public static Token GenerateToken(User user, IAccessTokenSettings accessTokenSettings)
        {
            var claims = new List <System.Security.Claims.Claim>
            {
                new System.Security.Claims.Claim(JwtRegisteredClaimNames.GivenName, user.FirstName),
                new System.Security.Claims.Claim(JwtRegisteredClaimNames.FamilyName, user.LastName)
            };

            if (user.Claims != null && user.Claims.Count > 0)
            {
                user.Claims.ForEach((claim) =>
                {
                    claims.Add(new System.Security.Claims.Claim(claim.Type, claim.Value));
                });
            }

            var accessToken = AccessTokenGenerator.GenerateAccessToken(
                userId: user.Id.ToString(),
                privateKey: accessTokenSettings.PrivateKey,
                issuer: accessTokenSettings.Issuer,
                audience: accessTokenSettings.Audience,
                notBefore: accessTokenSettings.NotBefore,
                expires: accessTokenSettings.Expires,
                additionClaims: claims);

            return(new Token(
                       accessToken: accessToken,
                       expiresIn: accessTokenSettings.ExpiresIn));
        }
예제 #2
0
        public void TokenShouldBeCreatedAndValid(
            IAccessTokenSettings accessTokenSettings,
            User user,
            string expectedAccessToken
            )
        {
            var token = Token.GenerateToken(user, accessTokenSettings);

            Assert.Equal(accessTokenSettings.ExpiresIn, token.ExpiresIn);
            Assert.Equal(expectedAccessToken, token.AccessToken);
        }
예제 #3
0
 public AccessTokenProvider(IAccessTokenSettings accessTokenSettings)
 {
     _accessTokenSettings = accessTokenSettings;
 }
예제 #4
0
 public SignInUseCase(IUserRepository userRepository, IAccessTokenSettings tokenSettings, ILogger <SignInUseCase> logger)
 {
     _userRepository = userRepository;
     _logger         = logger;
     _tokenSettings  = tokenSettings;
 }
        public AccessTokenValueProvider(HttpRequest request, IAccessTokenSettings accessTokenSettings)
        {
            _request = request;

            _accessTokenSettings = accessTokenSettings;
        }
 public AccessTokenBinding(IAccessTokenSettings accessTokenSettings)
 {
     _accessTokenSettings = accessTokenSettings;
 }