Merge branch 'v1'

This commit is contained in:
AJ ONeal 2017-03-29 17:23:24 -06:00
commit e8c631a416
1 changed files with 31 additions and 9 deletions

View File

@ -1065,7 +1065,7 @@
// this is not necessary, but it's relatively small
// and gives people the 3-line examples they love so much
OAUTH3.create = function (location/*, opts*/) {
OAUTH3.create = function (location, opts) {
if (!location) {
location = OAUTH3._browser.window.location;
}
@ -1073,16 +1073,32 @@
var result = {
_clientUri: OAUTH3.clientUri(location)
, _providerUri: null
, init: function (location) {
, _init: function (location, opts) {
var me = this;
if (location) {
me._clientUri = OAUTH3.clientUri(location);
}
if (opts) {
if (opts.providerUri) {
me._providerUri = opts.providerUri;
}
if (opts.session) {
if (!me._providerUri) {
throw new Error("'providerUri' was not supplied");
}
me.session(opts.session, opts.sessionId);
}
}
}
, init: function (location/*, opts*/) {
var me = this;
var p = OAUTH3.PromiseA.resolve();
if (location) {
this._clientUri = OAUTH3.clientUri(location);
}
if (this._providerUri) {
me._init(location, opts);
if (me._providerUri) {
// returns directives
p = OAUTH3.discover(this._providerUri, { client_id: this._clientUri });
p = OAUTH3.discover(me._providerUri, { client_id: this._clientUri });
}
return p.then(function () {
@ -1122,8 +1138,11 @@
return session;
});
}
, session: function () {
return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._providerUri) || null));
, session: function (session, id) {
if (!session) {
return JSON.parse(JSON.stringify(OAUTH3.hooks.session._getCached(this._providerUri) || null));
}
return OAUTH3.hooks.session.set(this._providerUri, session, id);
}
, request: function (preq, opts) {
opts = opts || {};
@ -1159,6 +1178,9 @@
result.authenticate = result.login;
result.authorize = result.login;
result.expire = result.logout;
result._init(location, opts);
return result;
};