IdentityModel.AspNetCore.OAuth2Introspection icon indicating copy to clipboard operation
IdentityModel.AspNetCore.OAuth2Introspection copied to clipboard

HTTP 400 Bad Request can cause InvalidOperationException

Open webley opened this issue 4 years ago • 1 comments

If we hit our introspect endpoint with a missing or invalid client_id, it responds with:

400 BadRequest
{"errorCode": "invalid_client", "errorSummary": "Invalid value for 'client_id' parameter."}

Unfortunately because it returns 400 and doesn't have a property named "error", ProtocolResponse.IsError returns false (see IdentityModel 265), OAuth2IntrospectionHandler tries to continue, and we get an exception thrown like the following:

"ClassName": "System.InvalidOperationException",
"Message": "Nullable object must have a value.",
"Source": "System.Private.CoreLib",
"StackTraceString": "   
	at System.Nullable`1.get_Value()
	at IdentityModel.Client.TokenIntrospectionResponse.get_IsActive()
	at IdentityModel.AspNetCore.OAuth2Introspection.OAuth2IntrospectionHandler.HandleAuthenticateAsync()
	at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
	at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
	at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
	at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
	at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
	at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
	at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
	at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)"

We are admittedly not using IdentityServer (instead using OKTA auth servers) so perhaps this scenario is not intended to be supported, but I thought I would mention it as the strange stack trace caused a bit of a headache.

Thanks!

webley avatar Jun 18 '20 09:06 webley

Could you test this again with the latest version?

leastprivilege avatar Jan 30 '21 08:01 leastprivilege