0

I want to use an authorization header that looks like so -

Authorization: APIToken <API_KEY>

I'd like to use the FromHeader parameter in my C# controller so that I can inject this value when testing inside Swagger, but when I try to come the FromHeader parameter with the Authorization header, my API controller fails. How can I use FromHeader parameter with the Authorization Header in my API Controller?

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
MK998392
  • 15
  • 3
  • 1
    User authorization is a cross cutting concern, meaning that you will use this across all controller action methods. So, injecting at action method will not help scale and not the right way to do it. – Ramesh Jan 06 '21 at 04:16
  • 2
    Please read through https://learn.microsoft.com/en-us/aspnet/core/security/authentication/?view=aspnetcore-5.0 and most likely you might be using JwtAuthentication – Ramesh Jan 06 '21 at 04:18
  • This doesn't really explain how to accomplish this though, how are where does the Auth header get implemented/validation if not at the IActionResult endpoint? On the controllers? Globally? – MK998392 Jan 06 '21 at 18:56
  • Globally in a middleware. If you are using jwt you can follow https://www.c-sharpcorner.com/article/jwt-json-web-token-authentication-in-asp-net-core/ – Ramesh Jan 07 '21 at 02:41

0 Answers0