C
C#2y ago
joy

api to accept header

hi all, how do we add an api to accept a header value sent from postman? does it make sense to add like
[ServiceFilter(typeof(CustomAuthorization))]
[ServiceFilter(typeof(CustomAuthorization))]
above the api controller and add a CustomAuthorization and pass the request from postman to this class so we can reuse the CustomAuthorization
6 Replies
pox
pox2y ago
I'm having a hard time understanding what you exactly want to achieve Is the purpose of the header to auth the api user?
joy
joy2y ago
usually from postman we can add a header and send to an api, i was trying to create a simple api that accept this "header"
joy
joy2y ago
yes, so it's like the controller of an api will check what header is passed to the api, and i was wondering how we check that "header".
pox
pox2y ago
You can use the built in [Authorize] to do this with schemes and stuff etc. Or something "easier" would be a simple actionfilter (http://codingsonata.com/secure-asp-net-core-web-api-using-api-key-authentication/ not sure if this a good way didn't read it all)
Aram
Coding Sonata
Secure ASP.NET Core Web API using API Key Authentication - Coding S...
This tutorial explains how to use API Key Authentication to secure your ASP.NET Core Web API using Custom Attribute and Custom Middleware.
pox
pox2y ago
we use the Authorize method since it allows us to easy add claims and stuff
joy
joy2y ago
oh wait, i think this is what im looking for i'll try it out. thank you friend!