From 0ad5017ac902dbdd1789939e3b8de74f9b9ebfcc Mon Sep 17 00:00:00 2001 From: aj Date: Mon, 14 Aug 2017 18:58:01 +0000 Subject: [PATCH] add oauth3 --- .well-known/oauth3 | 1 + index.html | 6 ++ install.sh | 7 ++ js/app.js | 2 +- js/controllers/signInController.js | 121 ++++++++++++++++++++++++++--- templates/splash-page.html | 37 ++++++--- 6 files changed, 152 insertions(+), 22 deletions(-) create mode 120000 .well-known/oauth3 create mode 100644 install.sh diff --git a/.well-known/oauth3 b/.well-known/oauth3 new file mode 120000 index 0000000..51f73eb --- /dev/null +++ b/.well-known/oauth3 @@ -0,0 +1 @@ +../assets/oauth3.org/.well-known/oauth3 \ No newline at end of file diff --git a/index.html b/index.html index 9a3961b..248f276 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,11 @@ + + + + + @@ -31,6 +36,7 @@ + diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..772ee10 --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +mkdir -p assets +git clone git@git.daplie.com:OAuth3/oauth3.js.git assets/oauth3.org +pushd assets/oauth3.org +git checkout v1.1 +popd diff --git a/js/app.js b/js/app.js index a9a1773..f0706c4 100644 --- a/js/app.js +++ b/js/app.js @@ -1,4 +1,4 @@ -var app = angular.module('launchpad', ['ui.router', 'LocalStorageModule']); +var app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule']); var redirectedURL; app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){ diff --git a/js/controllers/signInController.js b/js/controllers/signInController.js index 762521f..241a3e7 100644 --- a/js/controllers/signInController.js +++ b/js/controllers/signInController.js @@ -1,15 +1,118 @@ -app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorageService', '$rootScope', function ($scope, Auth, $location, localStorageService, $rootScope) { +app.controller('SignInController', [ + '$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org' +, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3) { + var vm = this; + vm.independentIssuer = false; + vm.oauth3 = Oauth3.oauth3 = Oauth3.oauth3 || Oauth3.create(location); + vm.timers = {}; + vm.defaultIssuer = 'provider.' + location.host.replace(/^cloud\./, ''); + + vm.toggleAdvanced = function () { + vm.independentIssuer = !vm.independentIssuer; + } + + vm._setSubject = function (subject) { + vm.currentSubject = vm.newSubject; + subject = subject || vm.newSubject; + var issuer = subject.replace(/.*@/, ''); + if (vm.independentIssuer) { + return $timeout(function () { return; }, 0); + } + return Oauth3.discover(issuer, { client_uri: Oauth3.clientUri(location) }).then(function (deets) { + return vm._setIssuer(issuer); + }, function () { + // ignore error + }); + }; + vm.setSubject = function (subject) { + $timeout.cancel(vm.timers.subject); + vm.timers.subject = $timeout(function () { + vm._setSubject(subject); + }, 300); + }; + vm._setIssuer = function (url) { + vm.spinner = true; + url = (url || vm.newIssuer).replace(/.*@/, ''); + if (!url) { + url = vm.defaultIssuer; + } + + return Oauth3.discover(url, { client_uri: Oauth3.clientUri(location) }).then(function (deets) { + console.log('discover', url); + console.log(deets); + vm.currentIssuer = url; + vm.issuerName = url; + + return vm.oauth3.setIdentityProvider(url).then(function (deets) { + vm.oauth3.setResourceProvider(url); + vm.spinner = false; + // TODO add icon and name to directives + console.log(deets); + }); + }, function () { + console.log('oauth3 timeout: No dice, no change'); + vm.spinner = false; + }); + }; + vm.setIssuer = function (url) { + $timeout.cancel(vm.timers.issuer); + vm.timers.issuer = $timeout(function () { + vm._setIssuer(url); + }, 300); + }; + vm.setAudience = function (url) { + url = url || vm.audienceUrl; + vm.audienceName = url; + vm.oauth3.setResourceProvider(url); + }; + + vm.selectSession = function (session) { + vm.oauth3.init({ + location: location + , issuer: vm.currentIssuer + , audience: vm.currentIssuer + }); + }; + + vm.oauth3.sessions = vm.oauth3.sessions || []; + vm.instaauth = function () { + return vm._setSubject().then(function () { + return vm._setIssuer().then(function () { + return vm.auth(); + }); + }); + }; + vm.auth = function () { + var subject = vm.currentSubject; + var issuer = vm.issuerName; + vm.oauth3.authenticate({ + subject: subject + , scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ] + }).then(function (session) { + console.log('session', session); + vm.hasSession = session; + session.subject = subject; + session.issuer = issuer; + vm.oauth3.sessions.push(session); + }, function (err) { + console.log('auth error'); + console.log(err); + }); + }; + + vm.newIssuer = vm.defaultIssuer; + vm.setIssuer(vm.defaultIssuer); + vm.signIn = function () { - var userInfo = { - email: vm.userAuthEmail, - name: 'Johnny Cash' - }; - Auth.setUser(userInfo); - var userAuthenticated = function() { - return localStorageService.set('userAuth', JSON.stringify(userInfo)); - }(); + vm.auth().then(function () { + var userInfo = { + email: vm.currentSubject, + name: 'Johnny Cash' + }; + Auth.setUser(userInfo); + }); }; }]); diff --git a/templates/splash-page.html b/templates/splash-page.html index 3ffb573..d12019c 100644 --- a/templates/splash-page.html +++ b/templates/splash-page.html @@ -1,14 +1,27 @@
-
-

Sign in

-
- - -
-
- - -
- -
+
+

Sign in

+
+ + + + +
+
+
+ + +
+
+ + +
+
+
+
+ Demo: + +
+ +