The Identity 2 system includes OAuth connections for Facebook, Twitter and Google. These are easy enough to configure (well to do a simple register/login) from an MVC website project BUT doing this with Web Api needs a little more knowledge!
Firstly I’ll make reference to this excellent resource on configuring various OAuth providers.
So if you’ve followed this correctly you should have your API key/secret in your Startup.Auth file.
Now to use this with WebApi you need to make a call to
This will return an object of all your registered OAuth providers along with a URL.
Make a GET request to this URL and you will be redirected to the providers login page which will eventually request the permissions you are needing for your app. (Typically this will be your client website or native app making this call)
Once authenticated, you will go back to your callback URL, which will look something like this or back to your native app.
Notice the access_token and token_type values. So all we need to do now to parse this response and send an Authorized request to our protected Api controller using this token.
curl -H "Authorization: OAuth <ACCESS_TOKEN>" http://www.example.com