accept providerUri and session on create

This commit is contained in:
AJ ONeal 2017-03-24 10:13:15 -06:00
parent f37d47b0d4
commit 4bdacf9770
1 changed files with 23 additions and 7 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,29 @@
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) {
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 () {
@ -1158,6 +1171,9 @@
result.authenticate = result.login;
result.authorize = result.login;
result.expire = result.logout;
result._init(location, opts);
return result;
};