public IActionResult GetAccessToken(string code, string state) { if (!string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(state)) { OAuthManager oauthManager = new OAuthManager(_logger); AccessTokenResponse response = oauthManager.GetAccessTokenAsync( new AccessTokenRequest() { ClientId = _configuration.GetValue(ConfigurationKey.CLIENT_ID), ClientSecret = _configuration.GetValue(ConfigurationKey.CLIENT_SECRET), RedirectUri = state, Code = code }) .Result; if (response != null && response.access_token != null) { UsersGetResponse userInfo = oauthManager.GetUserInfoAsync(response.access_token).Result; if (userInfo != null && userInfo.response != null) { _logger.LogWarning(JsonConvert.SerializeObject( new { info = userInfo } )); HttpContext.Response.Cookies.Append("access_token", _jwtManager.GenerateJwtToken(userInfo)); return(Redirect("/")); } _logger.LogError(JsonConvert.SerializeObject( new { error = "Invalid user info" } )); } _logger.LogError(JsonConvert.SerializeObject( new { error = "Can't get access token" } )); } return(Unauthorized()); }