2017-08-15 15:37:37 +00:00
|
|
|
app.controller('loginCtrl', [
|
2017-08-14 18:58:01 +00:00
|
|
|
'$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org'
|
|
|
|
, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3) {
|
|
|
|
|
2017-08-08 20:54:25 +00:00
|
|
|
var vm = this;
|
2017-08-09 17:28:36 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.independentIssuer = false;
|
|
|
|
vm.oauth3 = Oauth3.oauth3 = Oauth3.oauth3 || Oauth3.create(location);
|
|
|
|
vm.timers = {};
|
|
|
|
vm.defaultIssuer = 'provider.' + location.host.replace(/^cloud\./, '');
|
|
|
|
|
2017-08-14 23:00:01 +00:00
|
|
|
vm.session = Auth.session;
|
|
|
|
vm.sessions = Auth.sessions;
|
|
|
|
|
|
|
|
vm.showAdvanced = true;
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.toggleAdvanced = function () {
|
2017-08-14 23:00:01 +00:00
|
|
|
vm.showAdvanced = !vm.showAdvanced;
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.independentIssuer = !vm.independentIssuer;
|
2017-08-15 15:37:37 +00:00
|
|
|
};
|
2017-08-14 18:58:01 +00:00
|
|
|
|
2017-08-14 23:00:01 +00:00
|
|
|
vm.notification = true;
|
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
};
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.setSubject = function (subject) {
|
|
|
|
$timeout.cancel(vm.timers.subject);
|
|
|
|
vm.timers.subject = $timeout(function () {
|
|
|
|
vm._setSubject(subject);
|
|
|
|
}, 300);
|
|
|
|
};
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
};
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.setIssuer = function (url) {
|
|
|
|
$timeout.cancel(vm.timers.issuer);
|
|
|
|
vm.timers.issuer = $timeout(function () {
|
|
|
|
vm._setIssuer(url);
|
|
|
|
}, 300);
|
|
|
|
};
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.setAudience = function (url) {
|
|
|
|
url = url || vm.audienceUrl;
|
|
|
|
vm.audienceName = url;
|
|
|
|
vm.oauth3.setResourceProvider(url);
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.selectSession = function (session) {
|
2017-08-16 22:35:04 +00:00
|
|
|
vm.xauth = true;
|
2017-08-14 23:00:01 +00:00
|
|
|
vm.session = session;
|
2017-08-16 22:35:04 +00:00
|
|
|
return Auth.select(session).then(function (oauth3) {
|
|
|
|
vm.xauth = false;
|
|
|
|
vm.oauth3 = oauth3;
|
2017-08-14 18:58:01 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.instaauth = function () {
|
|
|
|
return vm._setSubject().then(function () {
|
|
|
|
return vm._setIssuer().then(function () {
|
|
|
|
return vm.auth();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-08-15 15:37:37 +00:00
|
|
|
|
2017-08-14 18:58:01 +00:00
|
|
|
vm.auth = function () {
|
|
|
|
var subject = vm.currentSubject;
|
|
|
|
var issuer = vm.issuerName;
|
2017-08-14 18:59:45 +00:00
|
|
|
return vm.oauth3.authenticate({
|
2017-08-14 18:58:01 +00:00
|
|
|
subject: subject
|
|
|
|
, scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ]
|
|
|
|
}).then(function (session) {
|
2017-08-18 19:41:38 +00:00
|
|
|
console.log('vm.auth session.issuer', session.issuer);
|
2017-08-14 18:58:01 +00:00
|
|
|
session.subject = subject;
|
|
|
|
session.issuer = issuer;
|
2017-08-14 23:00:01 +00:00
|
|
|
Auth.add(session);
|
2017-08-15 15:37:37 +00:00
|
|
|
if ($rootScope.redirectedURL === '/splash-page') {
|
|
|
|
$location.path('/home');
|
|
|
|
} else {
|
|
|
|
$location.path('/' + $rootScope.redirectedURL);
|
|
|
|
}
|
2017-08-14 18:58:01 +00:00
|
|
|
}, function (err) {
|
|
|
|
console.log('auth error');
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.newIssuer = vm.defaultIssuer;
|
|
|
|
vm.setIssuer(vm.defaultIssuer);
|
|
|
|
|
2017-08-21 17:55:11 +00:00
|
|
|
vm.getSession = function() {
|
2017-08-21 17:21:00 +00:00
|
|
|
return Auth.select(Auth.session);
|
2017-08-21 17:55:11 +00:00
|
|
|
};
|
2017-08-21 17:21:00 +00:00
|
|
|
|
2017-08-18 21:13:43 +00:00
|
|
|
vm.initListLoggedInProfiles = function () {
|
|
|
|
vm.activeProfiles = Auth.getActiveSessions();
|
|
|
|
};
|
|
|
|
|
2017-08-10 17:36:59 +00:00
|
|
|
vm.signIn = function () {
|
2017-08-14 23:00:01 +00:00
|
|
|
vm.auth();
|
2017-08-08 20:54:25 +00:00
|
|
|
};
|
2017-08-10 22:33:54 +00:00
|
|
|
|
2017-08-18 21:13:43 +00:00
|
|
|
vm.masterLogOut = function () {
|
|
|
|
localStorage.clear();
|
|
|
|
$location.path('/splash-page');
|
|
|
|
};
|
|
|
|
|
2017-08-15 15:37:37 +00:00
|
|
|
vm.signOut = function () {
|
2017-08-21 17:55:11 +00:00
|
|
|
vm.getSession().then(function(){
|
|
|
|
// TODO the sign-out url for each account should be fixed.
|
|
|
|
return Auth.signOut().then(function () {
|
|
|
|
if (Auth.sessions.length === 0) {
|
|
|
|
$location.path('/splash-page');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.alert("You are still logged in with other accounts.");
|
|
|
|
});
|
2017-08-15 17:40:10 +00:00
|
|
|
});
|
2017-08-15 15:37:37 +00:00
|
|
|
};
|
|
|
|
|
2017-08-08 20:54:25 +00:00
|
|
|
}]);
|