Compare commits

...

4 Commits
master ... v1.2

Author SHA1 Message Date
AJ ONeal 3b12c7854c add client_id 2017-12-17 08:35:14 +00:00
AJ ONeal f410f2b171 set Accept header and reply with headers 2017-12-08 21:32:17 +00:00
AJ ONeal a952ee6197 better debug handling 2017-12-08 06:53:01 +00:00
AJ ONeal bb7fa017ef allow claims 2017-12-07 20:55:09 +00:00
2 changed files with 27 additions and 5 deletions

View File

@ -7,7 +7,7 @@ function create(myOpts) {
// TODO pre-generate URL
// deliver existing session if it exists
var scope = opts && opts.scope || [];
var scope = opts && (opts.scope || opts.claims || myOpts.scope || myOpts.claims || []);
if (myOpts.session) {
if (!scope.length || scope.every(function (scp) {
return -1 !== opts.myOpts.session.scope.indexOf(scp);
@ -23,6 +23,7 @@ function create(myOpts) {
// maybe use inline instead?
, windowType: 'popup'
, scope: scope
, debug: opts.debug || myOpts.debug
}).then(function (session) {
return session;
});
@ -57,6 +58,7 @@ window.navigator.auth = {
var conf = {};
var directives;
var session;
var scope = opts && (opts.scope || opts.claims || []);
opts = opts || {};
conf.client_uri = opts.client_uri || OAUTH3.clientUri(opts.location || window.location);
@ -73,12 +75,15 @@ window.navigator.auth = {
var myOpts = {
directives: directives
, conf: conf
, debug: opts.debug
, scope: scope
};
return OAUTH3.implicitGrant(directives, {
client_id: conf.client_uri
, client_uri: conf.client_uri
, windowType: 'background'
, scope: scope
}).then(function (_session) {
session = _session;
myOpts.session = session;

View File

@ -12,7 +12,8 @@
}
, error: {
parse: function (providerUri, params) {
var err = new Error(params.error_description || params.error.message || "Unknown error with provider '" + providerUri + "'");
var msg = decodeURIComponent(params.error_description || params.error.message || "Unknown error with provider '" + providerUri + "'");
var err = new Error(msg);
err.uri = params.error_uri || params.error.uri;
err.code = params.error.code || params.error;
return err;
@ -306,6 +307,8 @@
var params = {
state: opts.state || OAUTH3.utils.randomState()
, client_uri: clientId
, client_id: clientId
, redirect_uri: clientId + (opts.client_callback_path || '/.well-known/oauth3/callback.html#/')
, response_type: 'rpc'
, _method: 'GET'
@ -835,6 +838,9 @@
);
if (opts.debug) {
console.log('[DEBUG] [implicit_grant] url object:');
console.log(directives.issuer);
console.log(authReq);
window.alert("DEBUG MODE: Pausing so you can look at logs and whatnot :) Fire at will!");
}
@ -1012,6 +1018,10 @@
var headers = preq.headers || {};
var multipart;
if (!headers.Accept && !headers.accept) {
headers.Accept = 'application/json';
}
try {
xhr = new XMLHttpRequest(_sys);
} catch(e) {
@ -1023,7 +1033,7 @@
return;
}
var data, err;
var data, err, resp;
if (xhr.status !== 200) {
err = new Error('bad status code: ' + xhr.status);
}
@ -1046,12 +1056,19 @@
return;
}
resolve({
resp = {
_request: xhr
, headers: null // TODO
, headers: {}
, data: data
, status: xhr.status
};
(xhr.getAllResponseHeaders()||'').trim().split(/[\n\r]+/).forEach(function (line) {
var parts = line.split(': ');
var header = parts.shift();
var value = parts.join(': ');
resp.headers[header] = value;
});
resolve(resp);
};
xhr.ontimeout = function () {
var err = new Error('ETIMEDOUT');