diff --git a/oauth3.core.js b/oauth3.core.js
index 15b2432..cf82eb5 100644
--- a/oauth3.core.js
+++ b/oauth3.core.js
@@ -20,6 +20,11 @@
// http://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome
return (exports.atob || require('atob'))(base64);
}
+ , btoa: function (b64) {
+ // for directive passing in .well-known/oauth3
+ // http://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome
+ return (exports.btoa || require('btoa'))(b64);
+ }
, decodeUrlSafe: function (b64) {
// URL-safe Base64 to Base64
// https://en.wikipedia.org/wiki/Base64
@@ -30,6 +35,13 @@
b64 = b64.replace(/-/g, '+').replace(/_/g, '/');
return OAUTH3._base64.atob(b64);
}
+ , encodeUrlSafe: function (b64) {
+ // for directive passing in .well-known/oauth3
+ // Base64 to URL-safe Base64
+ b64 = b64.replace(/\+/g, '-').replace(/\//g, '_');
+ b64 = b64.replace(/=+/g, '');
+ return OAUTH3._base64.btoa(b64);
+ }
}
, uri: {
normalize: function (uri) {
@@ -73,7 +85,38 @@
}
}
, query: {
- stringify: function (params) {
+ parse: function (search) {
+ // needed for .well-known/oauth3
+ // parse a query or a hash
+ if (-1 !== ['#', '?'].indexOf(search[0])) {
+ search = search.substring(1);
+ }
+ // Solve for case of search within hash
+ // example: #/authorization_dialog/?state=...&redirect_uri=...
+ var queryIndex = search.indexOf('?');
+ if (-1 !== queryIndex) {
+ search = search.substr(queryIndex + 1);
+ }
+
+ var args = search.split('&');
+ var argsParsed = {};
+ var i, arg, kvp, key, value;
+
+ for (i = 0; i < args.length; i += 1) {
+ arg = args[i];
+ if (-1 === arg.indexOf('=')) {
+ argsParsed[decodeURIComponent(arg).trim()] = true;
+ }
+ else {
+ kvp = arg.split('=');
+ key = decodeURIComponent(kvp[0]).trim();
+ value = decodeURIComponent(kvp[1]).trim();
+ argsParsed[key] = value;
+ }
+ }
+ return argsParsed;
+ }
+ , stringify: function (params) {
var qs = [];
Object.keys(params).forEach(function (key) {
@@ -522,8 +565,6 @@
return OAUTH3._requestHelper(preq, opts);
}
- OAUTH3.url.resolve(preq.providerUri || preq.provider_uri || preq.directives && preq.directives.issuer, preq.url);
-
if (!preq.session) {
return fetch();
}
@@ -757,7 +798,7 @@
, status: xhr.status
});
};
- xhr.open(preq.method, preq.url, true);
+ xhr.open(preq.method || 'GET', preq.url, true);
var headers = preq.headers || {};
Object.keys(headers).forEach(function (key) {
xhr.setRequestHeader(key, headers[key]);
@@ -989,9 +1030,12 @@
, request: function (preq) {
preq.client_uri = this._clientUri;
preq.client_id = this._clientUri;
+ preq.method = preq.method || 'GET';
if (this._session) {
preq.session = preq.session || OAUTH3.hooks.session._getCached(this._providerUri);
}
+ // TODO maybe use a baseUrl from the directives file?
+ preq.url = OAUTH3.url.resolve(this._providerUri, preq.url);
return OAUTH3.request(preq);
}
, logout: function (opts) {
diff --git a/well-known/oauth3/callback.html b/well-known/oauth3/callback.html
index 6cea1d3..b44f95f 100644
--- a/well-known/oauth3/callback.html
+++ b/well-known/oauth3/callback.html
@@ -16,6 +16,73 @@
-
+