Friday, April 29, 2016
Friday, April 22, 2016
OAuth2 proof of concept
Ok. It took me 7 hours and 15 minutes, but I have completed a proof of concept of OAuth2 for BLB.
Our overall guide through this disaster is a google article:
https://developer.chrome.com/apps/app_identity
I used that guide because I call chrome.identity.launchWebAuthFlow in my chrome extension.
This will be our guide for properly contacting our WordPress OAuth2 plugin.
https://wp-oauth.com/kb/access-the-resource-server/
Install the OAuth2 plugin:
https://wordpress.org/plugins/oauth2-provider/
Configure the plugin:
On the Advanced Configuration tab, I ticked all the grant types while debugging.
On the Clients tab, add a new client.
- Name the client whatever you want
- The client must have a very specific redirect URL
- Describe the client it however you want
https://<appid>.chromiumapp.org/<scope>
where <appid> is the application id of your application
and <scope> is the scope you invent as needed
<appid> must match the ID of your chrome app or extension. It's shown either in the app store (apparently) or on the Chrome > Settings > Extensions > Your Extension > ID field.
The WordPress OAuth2 plugin will create a Oauth2 client ID in response (let's call this <OCID>).
Configure your Chrome extension to use OAuth by updating the manifest:
https://developer.chrome.com/apps/app_identity#update_manifest
Call Chrome's handy method
https://developer.chrome.com/apps/identity#method-launchWebAuthFlow
You have to get the parameters to this method just right.
Here's some javascript:
var client_id = '<OCID>';
var redirectUri = chrome.identity.getRedirectURL("<scope>");
console.log("redirectUri: "+redirectUri);
var auth_url = "https://yoursite.com/oauth/authorize?response_type=token&client_id=" + client_id + "&redirect_uri=" + redirectUri;
Notice the endpoint is per the WordPress OAuth documentation: /oath/authorize?
Notice the variables are per the google documentation:
- response_type=token
- client_id
- redirect_uri
This should cause the callback provided to launchWebAuthFlow to be called....back.
When the callback is called, it will include the token.
The token will be provided by the client to the server. The server will use the token to authenticate the client's requests.
You can use I.E. to hit up any client calls to your server.
Other helpful explanations:
https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2
https://developer.vimeo.com/api/authentication
https://dev.twitter.com/oauth/overview/authorizing-requests
https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps#Obtaining_Access_Tokens
Subscribe to:
Posts (Atom)