コード例 #1
0
        public void Test2()
        {
            var tokenGen = new JwtTokenGenerator(
                new TokenOptions(
                    "Me",
                    "Me2",
                    new SymmetricSecurityKey(
                        Encoding.ASCII.GetBytes(
                            "abcdefghijklmnopqr12345"))));

            var tcp = tokenGen.GenerateAccessTokenWithClaimsPrincipal("*****@*****.**",
                                                                      new[]
            {
                new Claim(ClaimTypes.GivenName, "FName"),
                new Claim(ClaimTypes.Surname, "LName")
            });

            Assert.True(tcp.ClaimsPrincipal != null);
            Assert.True(!string.IsNullOrWhiteSpace(tcp.AccessToken));
            Assert.True(tcp.ClaimsPrincipal.FindFirst(ClaimTypes.GivenName).Value == "FName");
            Assert.True(tcp.ClaimsPrincipal.FindFirst(ClaimTypes.Surname).Value == "LName");
            Assert.True(tcp.AuthProperties != null &&
                        tcp.AuthProperties.Items.Any() &&
                        !string.IsNullOrWhiteSpace(tcp.AuthProperties.GetTokenValue(TokenConstants.TokenName)));
        }
コード例 #2
0
        private static TokenWithClaimsPrincipal Jwt(TokenOptions options = null)
        {
            var tokenGenerator =
                new JwtTokenGenerator(
                    options ?? new TokenOptions(
                        "Token.WebApp",
                        "Token.WebApp.Clients",
                        SecurityKey()));

            var token = tokenGenerator.GenerateAccessTokenWithClaimsPrincipal("Aman",
                                                                              new[]
            {
                new Claim("FName", "Aman")
            });

            return(token);
        }