Exemplo n.º 1
0
        public async Task <UserModel> GetModelAsync(int userId)
        {
            var userEntity = await _UserRepository.FindByIdAsync(userId);

            if (userEntity is null)
            {
                return(null);
            }

            var userDomains = await _UserDomainManager.GetAllByUserId(userId);

            return(new UserModel(userEntity.Id)
            {
                Username = userEntity.Username,
                JoinDate = userEntity.JoinDate,
                Domains = userDomains
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult <AuthResponse> > RefreshAuthentication()
        {
            Request.Cookies.TryGetValue(_Config["Cookie:RefreshToken"], out var refreshTokenCookie);

            _Logger.LogInformation($"Refresh Token: {refreshTokenCookie}");

            if (refreshTokenCookie is null)
            {
                return(BadRequest());
            }

            var dbEntity = await _RefreshTokenManager.GetOneByTokenAsync(refreshTokenCookie);

            if (dbEntity is null)
            {
                await _TokenService.RevokeAuthenticationRefreshTokens(Response, refreshTokenCookie);

                return(Unauthorized());
            }

            if (!dbEntity.Token.Equals(refreshTokenCookie))
            {
                return(Unauthorized());
            }

            var authedUser = await _UserManager.GetModelAsync(dbEntity.UserId);

            await _TokenService.IssueAuthenticationTokens(Response, authedUser);

            _Logger.LogInformation($"(Token) Refreshed User Authentication: {dbEntity.UserId}");

            var userDomains = await _UserDomainManager.GetAllByUserId(authedUser.Id);

            var response = new AuthResponse(authedUser.Id)
            {
                Username  = authedUser.Username,
                LastLogin = _DateService.LastLogin(),
                Domains   = userDomains
            };

            return(Ok(response));
        }