Exemplo n.º 1
0
        public JsonWebTokenModel GetTokenAsync(List <Claim> claims)
        {
            var accessJwt        = CreateToken(claims, 2);
            var refreshJwt       = CreateToken(claims, 24 * 30);
            var accessJwtString  = new JwtSecurityTokenHandler().WriteToken(accessJwt);
            var refreshJwtString = new JwtSecurityTokenHandler().WriteToken(refreshJwt);
            var response         = new JsonWebTokenModel
            {
                AccessToken  = accessJwtString,
                RefreshToken = refreshJwtString
            };

            return(response);
        }
Exemplo n.º 2
0
        public async Task <JsonWebTokenModel> RefreshTokenAsync(string refreshTokenId, UserModel person, JsonWebTokenModel newToken)
        {
            var refreshTokenModel = new RefreshTokenModel
            {
                Id       = refreshTokenId,
                Username = person.Login,
                Token    = newToken.RefreshToken,
                Revoked  = false
            };
            var refreshTokenReplaceResult = await _refreshTokenRepository.ReplaceAsync(refreshTokenModel, x => x.Id == refreshTokenId);

            if (!refreshTokenReplaceResult)
            {
                return(null);
            }
            await _userRepository.UpdateLastLogin(person.UserId);

            return(newToken);
        }