IdentityModel / IdentityModel.AspNetCore.OAuth2Introspection

ASP.NET Core authentication handler for OAuth 2.0 token introspection
Apache License 2.0
147 stars 66 forks source link

Accessing HttpContext in OAuth2IntrospectionEvents #59

Closed raghumirajkar closed 5 years ago

raghumirajkar commented 5 years ago

Hi, Currently we're using IdentityModel's OAuth introspection middleware v3.5.0 and want to access the IP Address from HttpContext for some logging purposes. In the event properties (failure or success), we don't see access to HttpContext neither is it possible to access it in the Custom Http Handler. Is it possible to access HttpContext in any other way during the introspection flow?

leastprivilege commented 5 years ago

Yes - this looks like an omission.

You should be able to create a class that derives from OAuth2IntrospectionEvents and set that type as the EventsType on the OAuth2IntrospectionOptions.

Then put this class into DI (transient). In the ctor of your class you can add a dependency on the IHttpContextAccessor - which in turn gives you access to the HttpContext.

Let me know if that works for you.

raghumirajkar commented 5 years ago

Hi,

Thank you for the response. We were able to do it the other way; we're using IAuthorizationHandler for some other purpose, which has AuthorizationHandlerContext as a parameter in HandleRequirementAsync. Since this is executed after IdentityModel's event execution, this gives me the HttpContext

Thank you

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.