예제 #1
0
        public void return_claims()
        {
            IClaims claims = new Claims();

            var claims1 = claims.Create("1", "Test");
            var claims2 = claims.Create("1", "Test", new List <Claim>());

            claims1.Count.Should().BeGreaterThan(0);
            claims2.Count.Should().BeGreaterThan(0);
        }
예제 #2
0
        public void claim_is_null()
        {
            IClaims claims = new Claims();

            claims.Create("1", "Test");

            claims.GetClaim(JwtRegisteredClaimNames.Website).Should().BeNull();
        }
예제 #3
0
        public void return_claim()
        {
            IClaims claims = new Claims();

            claims.Create("1", "Test");

            claims.GetClaim(JwtRegisteredClaimNames.Sub).Value.Should().Be("Test");
        }
예제 #4
0
        public void create_claims()
        {
            IClaims claims = new Claims(new List <Claim>()
            {
                new Claim("OwnClaim", "Test")
            });

            claims.Create("1", "Test");

            claims.GetClaim(JwtRegisteredClaimNames.Sub).Value.Should().Be("Test");
            claims.GetClaim(JwtRegisteredClaimNames.Jti).Value.Length.Should().Be(36);
            claims.GetClaim(JwtRegisteredClaimNames.Iat).Value.Should().NotBeNullOrEmpty();
            claims.GetClaim(Constants.JwtClaimIdentifiers.Id).Value.Should().Be("1");
            claims.GetClaim(Constants.JwtClaimIdentifiers.Rol).Value.Should().Be(Constants.JwtClaims.ApiAccess);
            claims.GetClaim("OwnClaim").Value.Should().Be("Test");
        }
예제 #5
0
        public void read_data_from_token()
        {
            IToken  token  = new Token();
            IClaims claims = new Claims();

            claims.Create("1", "User");
            var jsonWebToken = token.CreateJsonWebToken(claims.ToArray(), new JwtSettings()
            {
                Timeout = 120
            }, new JsonSerializerSettings {
                Formatting = Formatting.Indented
            });

            var id = token.GetId(JsonConvert.DeserializeObject <TokenData>(jsonWebToken).AuthToken);

            id.Should().Be("1");
        }
예제 #6
0
        public void return_json_web_token()
        {
            IToken  token  = new Token();
            IClaims claims = new Claims();

            claims.Create("1", "User");

            var jsonWebToken = token.CreateJsonWebToken(claims.ToArray(), new JwtSettings()
            {
                Timeout = 120
            }, new JsonSerializerSettings {
                Formatting = Formatting.Indented
            });

            jsonWebToken.Should().Contain("\"id\": \"1\",");
            jsonWebToken.Should().Contain("\"auth_token\": \"");
            jsonWebToken.Should().Contain("\"expires_in\": \"02:00:00\"");
        }