bruno-garcia / Bazinga.AspNetCore.Authentication.Basic

Basic Authentication for Microsoft ASP.NET Core Authentication
MIT License
48 stars 13 forks source link

How to inject HttpRequest object into IBasicCredentialVerifier #9

Closed brobichaud closed 6 years ago

brobichaud commented 6 years ago

I'm implementing my own IBasicCredentialVerifier and need access to some of the request details. How would I go about injecting the HttpRequest object into my IBasicCredentialVerifier:Authenticate method?

bruno-garcia commented 6 years ago

You can register your class with the container. And in its constructor, take a IHttpContextAccessor.

Keep in mind the framework doesn't register it by default so you'd need to call: services.AddHttpContextAccessor() which is a helper method for:

AddSingleton<IHttpContextAccessor,HttpContextAccessor>()

brobichaud commented 6 years ago

Thanks @bruno-garcia. I was actually able to make it work simply by adding IHttpContextAccessor accessor to my class ctor, no other changes were needed.

bruno-garcia commented 6 years ago

Cool. That means another library you use already had it registered.