From 84a8090d4921daab5466d1ee5feddb5c2663d329 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 14 Nov 2017 00:59:43 +0000 Subject: [PATCH] show session --- index.html | 114 +++++++++++++++++++++++++++++++++++------------ js/playground.js | 59 +++++++++++++++++++----- 2 files changed, 133 insertions(+), 40 deletions(-) diff --git a/index.html b/index.html index 5b058ed..6f813ae 100644 --- a/index.html +++ b/index.html @@ -157,15 +157,16 @@
taking my sweet time to do something in the background...
-
is a valid login provider
+
will be used as the login issuer
- + - + + @@ -187,63 +188,120 @@
-
- Client URI: +
+
+
+ Client URI:
(this is the URL of the application as per window.location.href)
-
-
OAUTH3.clientUri({ host: "" });
+
-
+ +
OAUTH3.clientUri({ host: "", port: null, pathname: '/' });
-
+
+
+
+ Subject: +
+ (this is either the subject portion or whole address of subject@issuer) +
+
+ + + +
address: 
+
subject: 
+
issuer: 
+
+
+ +
+
+
+
+ Issuer URI: +
+ (this is the URL part of subject@issuer) +
+
+ + + +
OAUTH3.urls.discover("", opts);
+
+ +
OAUTH3.discover("", opts);
+
+ + +
+
+
+ +
+
+
+
+ Authorization Dialog URL: +
+ (this is the URL part of subject@issuer) +
+
+ + +
OAUTH3.urls.implicitGrant(directives, opts);
+
+ +
OAUTH3.implicitGrant(directives, opts);
+ + +
+
+
+ +
+
+
+
Login Status:
-
+
...
+
-
+
Current Sessions:
-
+
...
+
-
+
Approved Devices:
-
+
...
+
-
+
Approved Applications:
-
+
...
-
-
- -
OAUTH3.discover("", opts);
-
OAUTH3.urls.discover("", opts);
- - -
-
-
-
-
diff --git a/js/playground.js b/js/playground.js index 805ebd9..b1e7c2d 100644 --- a/js/playground.js +++ b/js/playground.js @@ -31,10 +31,11 @@ vm.providerUri = vm.conf.client_uri; // map of things being debounced presently vm.debouncing = {}; + vm.defaults = { provider: vm.conf.provider_uri, directives: null }; vm.form = {}; vm.form.id = ''; - vm.form.user = ''; + vm.form.subject = ''; vm.form.userProvider = ''; vm.form.provider = ''; @@ -74,24 +75,35 @@ // The username may have a single @, the provider may not // user@thing.com@whatever.com -> user@thing.com, whatever.com provider = parts.pop(); - vm.form.user = parts.join(''); + user = parts.join(''); } else { //vm.form.hasUser = false; - vm.form.user = ''; + user = ''; provider = parts.join(''); } - if (!vm.form.providerIndependent) { - vm.form.provider = provider; - } - vm.form.userProvider = provider; + vm.form.subject = vm.form.id; - parts = vm.form.provider.split('.'); return vm.fn.debounce('provider', 250).then(function () { + var parts = vm.form.provider.split('.'); + if (!vm.form.providerIndependent) { + vm.form.provider = provider; + } + vm.form.userProvider = provider; // Careful: don't use state within a debounce function // uses vm.form.provider for lookup if (parts.length >= 2 && parts[parts.length - 1].length >= 2 && parts.every(function (p) {return p.length})) { - return vm.api.discover(); + return vm.api.discover().then(function () { + console.log('[changeUser] vm.directives:'); + console.log(vm.directives); + console.log(provider); + console.log(OAUTH3.uri.normalize(vm.directives.issuer)); + if (vm.directives && provider === OAUTH3.uri.normalize(vm.directives.issuer)) { + vm.form.subject = user; + } else { + vm.form.subject = vm.form.id; + } + }); } }); }; @@ -156,6 +168,7 @@ }; vm.api._discoverCount = 0; vm.api.discover = function () { + vm.directives = null; vm.validated.provider = ''; vm.api._discoverCount += 1; var latest = vm.api._discoverCount; @@ -178,8 +191,19 @@ console.log(dir); vm.validated.provider = provider; vm.directives = dir; + + var opts = { + client_uri: vm.conf.client_uri + , subject: vm.form.subject || undefined + , debug: vm.debug || undefined + }; + vm.implicitGrantObj = OAUTH3.urls.implicitGrant(vm.directives, opts); + vm.implicitGrantUrl = (OAUTH3.url.normalize(provider) + '/' + vm.implicitGrantObj.url).replace(vm.implicitGrantObj.state, '{{random}}'); //JSON.stringify(dir, null, 2); }, function (err) { + vm.form.provider = vm.defaults.provider; + vm.validated.provider = vm.defaults.provider; + vm.directives = vm.defaults.directives; if (latest !== vm.api._discoverCount) { console.warn('[DEBUG] ignoring stale discover error for', provider); console.warn(err); @@ -195,15 +219,26 @@ var provider = vm.validated.provider; var opts = { client_uri: vm.conf.client_uri - , subject: vm.form.user + , subject: vm.form.subject || undefined + , debug: vm.debug || undefined }; + console.log('[DEBUG] vm.directives'); + console.log(vm.directives); vm.implicitGrantObj = OAUTH3.urls.implicitGrant(vm.directives, opts); console.log('[DEBUG] vm.implicitGrantObj'); console.log(vm.implicitGrantObj); - vm.implicitGrantUrl = OAUTH3.url.normalize(provider) + '/' + vm.implicitGrantObj.query._pathname; - return OAUTH3.implicitGrant(provider, opts); + vm.implicitGrantUrl = (OAUTH3.url.normalize(provider) + '/' + vm.implicitGrantObj.url); + return OAUTH3.implicitGrant(vm.directives, opts).then(function (session) { + vm.session = session; + }); }; + vm.form.provider = vm.defaults.provider; + vm.validated.provider = vm.defaults.provider; + vm.api.discover().then(function () { + vm.defaults.directives = vm.directives; + }); + } ] ); }());