Customize header for JwtBearer in core 2.2.

So we were upgrading to core, the old system where using a custom jwt validation. Since core Authentication comes with a built in AothenticationBuilder for Jwt we decided to use that one instead (seems reasonable right?)

One thing was that the old system where not using the Authorization header and where accepting with or without Bearer first.

So we needed a way to look at the custom header for a token and forward it to Authentication. Of course there is a simple solution to this. Here it is:

We simply add a new callback to OnMessageReceived in the Events.

We look for a header with the name SpecialApiKey then we see if it starts with Bearer and if so we strip that part out.

That’s all. Pretty smooth right?

Until next time, have a good one.

Sharing is caring!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.