How to get OAuth 2.0 right for consuming external APIs in my Custom API .net core

682 views Asked by At

I want to create a custom API that behind the scenes, call number of other APIs which use OAuth 2.0 for authentication. I want to manage this internally so that my custom endpoint somewhat abstract this.

Or to begin with I want to do what app like buffer (https://buffer.com) do - where you connect to different social services and than post your status.

How can I achieve this in .NetCore ?? I don't want to login with these (a lot of samples are catering this scenario), user login is different than this. I just want to establish these connections (like API Connections if you look at Azure API Management) and then perform some operations against those endpoints.

I hope i convey my point. please let me know if this isn't clear.

Thanks Sanjay

1

There are 1 answers

1
Andrei Dragotoniu On

OAuth2 systems are all based on the same workflow.

here's an authorization url, you pass some ids in an authorization header, if everything is correct you get a token, you then use the token to do whatever you are allowed to do. What changes are the credentials you use for authentication and the urls you hit for the various parts of this workflow.

You could write your own OAuth2 library which deals with all this, that's pretty much what I did and simply changed the details for every specific system I had to interact with.

This being said you can always use one of the existing implementations to connect to the various systems you care about, they all have an API you could use, all you have to do is make sure you follow the OAuth2 flow correctly.