-
Notifications
You must be signed in to change notification settings - Fork 53
freedom.js OAuth
'core.oauth' is a core permission first proposed in freedom v0.6. freedom.js modules with this permission have the ability to perform a full client-side OAuth2.0 flow.
- Should support any OAuth2.0 client-side authorization flow.
- By default, any freedom.js module using this interface does not have to worry about how to display the proper screens to the user, which will be different depending on the platform (e.g. freedom/freedom-for-chrome/freedom-for-node/freedom-for-firefox).
- For special cases, an application developer should be able to specify a core.oauth provider to customize the user experience of the oAuth flow.
freedom.js manifest:
{
...
permissions: [ "core.oauth" ]
}
Code:
var oauth = freedom["core.oauth"]();
oauth.chooseRedirectUri([
"http://localhost/",
"http://remotehost.com/"
]).then(function(result) {
var url = "https://accounts.google.com/o/oauth2/auth?" + params +
"redirect_uri=" + result.redirect +
"state=" + result.state;
return oauth.initiateAuthFlow(url);
}).then(function(responseUrl) {
//Parse the responseUrl for the access_token
...
}).catch(function(err) {
console.error(err);
});
There are two key methods in core.oauth
.
chooseRedirectUri
will take a list of registered redirectURIs for the application and choose one that is compatible with the current runtime platform. (e.g. Chrome apps must register a redirect URI of the form https://.chromiumapp.com/*). If no options work, it will reject with an error.
initiateAuthFlow
will take a url that initiates an oAuth flow and return the responseUrl containing the access token. Within the core.oauth provider, we will expose a browser window and allow a user to sign in. When the oAuth flow completes, the promise will fulfill with the returned responseUrl.
In order to support custom oAuth user experiences, we allow an application developer to specify a custom core.oauth provider.
Exists, still needs to be described