ikey
ikey

Reputation: 331

How to consume a web api with oauth2 authorization using ASP.net MVC?

I've been looking for ways of how to consume a web api with an oauth2 authorization using ASP.Net MVC. Any suggestions?

I have already tried sending a request to the web api and recieve a response. But I'm having a hard time when it involves Oauth2 authorization because i don't know how to send headers like the clientsecret and clientid and also on how to send a raw json data to the web api. I've already tried testing my api on postman and it's working properly.I wanted to know now how can i make an ASP.Net MVC application that can POST and GET to that web api with Oauth2 authorization.

Upvotes: 0

Views: 3295

Answers (1)

wonhee
wonhee

Reputation: 1661

There is answer for client_credential oauth2 gran type

How to write OAuth2 Web API Client in Asp.net MVC

and I think that's commonly used between services. However, if it's not your case then you need to take a look OAuth2 grant type and understand how those are working and different from each other.

If you want to know what to set in http header regardless of what language/framework you use, you need to set "Authorization" http header with "Bearer " value. In order to get your access token from oauth2 provider, you need to send a request to oauth2 provider with grant type you'd like to use along with your clientId and secrets.

It will be look like below if you use client credential grant type. https://oauth.example.com/token?grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET

Upvotes: 1

Related Questions