Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] TokenResponse response, [FromRoute] string provider)
        {
            m_logger.LogDebug($"Open id connect refresh with {provider}");

            var token = await m_oAuthService.RefreshToken(response.RefreshToken,
                                                          Enum.Parse <AuthenticationProvider>(provider, true));

            return(Ok(token));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RefreshToken(string sgId)
        {
            _logger.LogDebug($"Refresh token has been requested for SGId {sgId}");

            var refreshToken = _repository.FindBy <Token>(t => t.User.UserName == sgId)
                               .Include(t => t.User)
                               .ThenInclude(u => u.UserGroups)
                               .ThenInclude(ug => ug.ApplicationUserGroup)
                               .ThenInclude(aug => aug.UserGroupRoles)
                               .ThenInclude(augr => augr.Role)
                               .FirstOrDefault();

            if (refreshToken == null || string.IsNullOrEmpty(refreshToken.Value))
            {
                _logger.LogWarning($"Refresh token has not been found for SGId {sgId}");
                return(new NotFoundObjectResult($"Refresh token not found for SGID {sgId}"));
            }

            var accessTokenResponse = await _oAuthService.RefreshToken(refreshToken.Value);

            if (accessTokenResponse == null)
            {
                return(new BadRequestObjectResult("Cannot refresh token."));
            }

            if (string.IsNullOrWhiteSpace(accessTokenResponse.Refresh_Token))
            {
                _logger.LogWarning($"SGId {sgId} has no refresh token.");
            }
            else
            {
                refreshToken.Value = accessTokenResponse.Refresh_Token;
                _repository.Save();
            }

            var tokenInfo = new TokenInfoResponseDto
            {
                Access_Token = accessTokenResponse.Access_Token,
                Expires_In   = accessTokenResponse.Expires_In,
                StGoSGI      = sgId
            };

            return(returnTokenAndUserData(tokenInfo, refreshToken.User));
        }