Ejemplo n.º 1
0
        private OkObjectResult TokenResult(UserModel user)
        {
            var tokenId        = Guid.NewGuid().ToString();
            var refreshTokenId = GetRefreshTokenId(tokenId, user);
            var claims         = new List <Claim>
            {
                new Claim(JwtClaimNames.TokenId, tokenId),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.Name, user.UserName)
            };

            claims.AddRange(user.Claims);
            var accessToken  = _jwtProvider.CreateAccessToken(claims);
            var refreshToken = _refreshTokenProvider.CreateToken(refreshTokenId);

            return(new OkObjectResult(new
            {
                user.Id,
                user.UserName,
                accessToken,
                refreshToken
            }));
        }