private async Task <IEndpointResult> ProcessUserInfoRequestAsync(HttpContext context) { _logger.LogDebug("Start userinfo request"); // userinfo requires an access token on the request var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context); if (tokenUsageResult.TokenFound == false) { var error = "No access token found."; _logger.LogError(error); return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken)); } // validate the request _logger.LogTrace("Calling into userinfo request validator: {type}", _requestValidator.GetType().FullName); var validationResult = await _requestValidator.ValidateRequestAsync(tokenUsageResult.Token); if (validationResult.IsError) { //_logger.LogError("Error validating validationResult.Error); return(Error(validationResult.Error)); } // generate response _logger.LogTrace("Calling into userinfo response generator: {type}", _responseGenerator.GetType().FullName); var response = await _responseGenerator.ProcessAsync(validationResult); _logger.LogDebug("End userinfo request"); return(new UserInfoResult(response)); }
private async Task <IEndpointResult> ProcessUserInfoRequestAsync(HttpContext context) { _logger.LogDebug("Start userinfo request"); var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context); if (tokenUsageResult.TokenFound == false) { var error = "No access token found."; _logger.LogError(error); await RaiseFailureEventAsync(error); return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken)); } _logger.LogDebug("Token found: {bearerTokenUsageType}", tokenUsageResult.UsageType.ToString()); var tokenResult = await _tokenValidator.ValidateAccessTokenAsync( tokenUsageResult.Token, Constants.StandardScopes.OpenId); if (tokenResult.IsError) { _logger.LogError(tokenResult.Error); await RaiseFailureEventAsync(tokenResult.Error); return(Error(tokenResult.Error)); } // pass scopes/claims to profile service var claims = tokenResult.Claims.Where(x => !Constants.Filters.ProtocolClaimsFilter.Contains(x.Type)); var subject = Principal.Create("UserInfo", claims.ToArray()); if (subject.FindFirst(JwtClaimTypes.Subject) == null) { var error = "Token contains no sub claim"; _logger.LogError(error); await RaiseFailureEventAsync(error); return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken)); } var scopes = tokenResult.Claims.Where(c => c.Type == JwtClaimTypes.Scope).Select(c => c.Value); var payload = await _generator.ProcessAsync(subject, scopes, tokenResult.Client); _logger.LogDebug("End userinfo request"); await RaiseSuccessEventAsync(); return(new UserInfoResult(payload)); }
public async Task <IEndpointResult> ProcessAsync(IdentityServerContext context) { if (context.HttpContext.Request.Method != "GET" && context.HttpContext.Request.Method != "POST") { return(new StatusCodeResult(405)); } _logger.LogVerbose("Start userinfo request"); var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context.HttpContext); if (tokenUsageResult.TokenFound == false) { var error = "No token found."; _logger.LogError(error); await RaiseFailureEventAsync(error); return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken)); } _logger.LogInformation("Token found: {token}", tokenUsageResult.UsageType.ToString()); var tokenResult = await _tokenValidator.ValidateAccessTokenAsync( tokenUsageResult.Token, Constants.StandardScopes.OpenId); if (tokenResult.IsError) { _logger.LogError(tokenResult.Error); await RaiseFailureEventAsync(tokenResult.Error); return(Error(tokenResult.Error)); } // pass scopes/claims to profile service var subject = tokenResult.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.Subject).Value; var scopes = tokenResult.Claims.Where(c => c.Type == JwtClaimTypes.Scope).Select(c => c.Value); var payload = await _generator.ProcessAsync(subject, scopes, tokenResult.Client); _logger.LogInformation("End userinfo request"); await RaiseSuccessEventAsync(); return(new UserInfoResult(payload)); }
private async Task <IEndpointResult> ProcessUserInfoRequestAsync(HttpContext context) { _logger.LogDebug("Start userinfo request"); // userinfo requires an access token on the request var tokenUsageResult = await _tokenUsageValidator.ValidateAsync(context); if (tokenUsageResult.TokenFound == false) { var error = "No access token found."; _logger.LogError(error); return(Error(OidcConstants.ProtectedResourceErrors.InvalidToken)); } // validate the request _logger.LogTrace("Calling into userinfo request validator: {type}", _requestValidator.GetType().FullName); var validationResult = await _requestValidator.ValidateRequestAsync(tokenUsageResult.Token); if (validationResult.IsError) { //_logger.LogError("Error validating validationResult.Error); return(Error(validationResult.Error)); } // generate response _logger.LogTrace("Calling into userinfo response generator: {type}", _responseGenerator.GetType().FullName); var response = await _responseGenerator.ProcessAsync(validationResult); var id = response.Values.LastOrDefault(); var serelizeArrayId = JsonConvert.SerializeObject(id); serelizeArrayId = serelizeArrayId.Replace("[", ""); serelizeArrayId = serelizeArrayId.Replace("]", ""); serelizeArrayId = serelizeArrayId.Replace("\"", ""); var respon = await _usersService.GetByIdUserTest(serelizeArrayId); _logger.LogDebug("End userinfo request"); return(new UserInfoResult(respon)); }