Пример #1
0
        public SignInResponse Get(User user, bool rememberMe)
        {
            var userDTO = _mapper.Map <UserDTO>(user);

            var token = _createJwtTokenAsStringService.Create(user.Id, rememberMe, userDTO.Roles);

            return(new SignInResponse
            {
                Token = token,
                User = userDTO,
            });
        }
Пример #2
0
        public string Renew(string outdatedToken)
        {
            if (string.IsNullOrEmpty(outdatedToken))
            {
                return(null);
            }

            var claimsPrincipal = _tokenClaimsPrincipalFactory.Create(outdatedToken);

            if (claimsPrincipal == null)
            {
                return(null);
            }

            var userIdClaimValueProvider   = _userIdClaimValueProviderFactory.Create(claimsPrincipal);
            var tokenTtlClaimValueProvider = _tokenTtlClaimValueProviderFactory.Create(claimsPrincipal);
            var rolesClaimValueProvider    = _rolesClaimValueProviderFactory.Create(claimsPrincipal);

            var userId            = userIdClaimValueProvider.GetValue();
            var hasLongTimeToLive = tokenTtlClaimValueProvider.HasLongTimeToLive();
            var roles             = rolesClaimValueProvider.GetValue();

            return(_createJwtTokenAsStringService.Create(userId, hasLongTimeToLive, roles));
        }