browse multiple sessions

This commit is contained in:
aj 2017-08-16 22:35:04 +00:00
parent 1ccf0dd71c
commit a55aac6fc1
5 changed files with 84 additions and 8 deletions

@ -1 +1 @@
Subproject commit 9a7aa3261f2ad97ebd436c8b1e86d168cf93023d Subproject commit 8961a4e51962a21690b5e68af3abaad24be8207c

View File

@ -81,11 +81,11 @@ app.controller('loginCtrl', [
}; };
vm.selectSession = function (session) { vm.selectSession = function (session) {
vm.xauth = true;
vm.session = session; vm.session = session;
vm.oauth3.init({ return Auth.select(session).then(function (oauth3) {
location: location vm.xauth = false;
, issuer: session.issuer vm.oauth3 = oauth3;
, audience: session.audience || session.issuer
}); });
}; };

View File

@ -4,6 +4,30 @@ app.controller('websiteCtrl', [
var vm = this; var vm = this;
vm.oauth3 = Auth.oauth3; vm.oauth3 = Auth.oauth3;
vm.domains = [];
Auth.sessions.forEach(function (session) {
return Auth.select(session).then(function (oauth3) {
return oauth3.api('domains.list', {}).then(function (domains) {
if (domains.error) {
// not all tokens support all apis
return;
}
if (!Array.isArray(domains)) {
console.error('domains are not domains');
console.error(domains);
return;
}
console.log('domains');
console.log(domains);
domains.forEach(function (domain) {
domain.session = session.token.sub + '@' + session.token.iss;
vm.domains.push(domain);
});
});
});
});
vm.getDomains = function () { vm.getDomains = function () {
vm.oauth3.api('domains.list', {}).then(function (result) { vm.oauth3.api('domains.list', {}).then(function (result) {
@ -11,8 +35,28 @@ app.controller('websiteCtrl', [
}); });
}; };
vm.setDomain = function () {
if (!vm.domains || !vm.domains.length) {
vm.domain = { domain: vm.newDomain };
return;
}
vm.domains.some(function (domain) {
if (domain.domain === vm.newDomain) {
vm.domain = domain;
return true;
}
});
if (!vm.domain) {
vm.domain = { domain: vm.newDomain };
}
};
vm.selectDomain = function (domain) { vm.selectDomain = function (domain) {
vm.domain = domain; vm.domain = domain;
vm.newDomain = domain.domain;
/*
return vm.oauth3.api('dns.list', { }).then(function (records) { return vm.oauth3.api('dns.list', { }).then(function (records) {
records = records.filter(function (r) { records = records.filter(function (r) {
return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === domain || r.zone === domain.domain); return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === domain || r.zone === domain.domain);
@ -21,6 +65,7 @@ app.controller('websiteCtrl', [
console.log('records'); console.log('records');
console.log(records); console.log(records);
}); });
*/
}; };
vm.selectRecord = function (record) { vm.selectRecord = function (record) {

View File

@ -23,8 +23,16 @@ app.factory('Auth', [
var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {}; var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {};
var dapName = 'dap-' + session.subject + '|' + session.issuer; var dapName = 'dap-' + session.subject + '|' + session.issuer;
console.log('session', session); console.log('add session', session);
/*
Object.keys(Auth.session).forEach(function (key) {
delete Auth.session[key];
});
Object.keys(session).forEach(function (key) {
Auth.session[key] = session[key];
});
*/
Auth.session = session; Auth.session = session;
Auth.sessions.push(session); Auth.sessions.push(session);
@ -53,6 +61,28 @@ app.factory('Auth', [
return Auth.session; return Auth.session;
} }
, select: function (session) {
var name = session.token.sub + '@' + session.token.iss;
var promise;
if (!Auth._oauth3s[name]) {
Auth._oauth3s[name] = Oauth3.create(window.location);
promise = Auth._oauth3s[name].init({
location: location
, issuer: session.issuer
, audience: session.audience || session.issuer
, session: session
}).then(function () {
console.log('a Auth._oauth3s[name]', Auth._oauth3s[name]);
return Auth._oauth3s[name];
});
} else {
console.log('b Auth._oauth3s[name]', Auth._oauth3s[name]);
promise = Oauth3.PromiseA.resolve(Auth._oauth3s[name]);
}
return promise;
}
, signOut: function () { , signOut: function () {
var session = Auth.session; var session = Auth.session;
var dapName = 'dap-' + session.subject + '|' + session.issuer; var dapName = 'dap-' + session.subject + '|' + session.issuer;
@ -75,6 +105,7 @@ app.factory('Auth', [
}); });
// localStorage.clear(); // localStorage.clear();
} }
, _oauth3s: {}
, sessions: [] , sessions: []
, session: null , session: null
, oauth3: null , oauth3: null

View File

@ -14,14 +14,14 @@
<input type="text" class="form-control" placeholder="www" /> <input type="text" class="form-control" placeholder="www" />
<span class="input-group-addon">.</span> <span class="input-group-addon">.</span>
<input type="text" class="form-control" placeholder="Select a domain" aria-label="Domain Name"> <input type="text" class="form-control" placeholder="Select a domain" aria-label="Domain Name" ng-model="vm.newDomain" ng-change="vm.setDomain()">
<div class="input-group-btn"> <div class="input-group-btn">
<!-- Single button --> <!-- Single button -->
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span>
</button> </button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#">blog.jane.smith.net</a></li> <li ng-repeat="domain in vm.domains"><button class="btn btn-link" ng-bind="domain.domain" ng-click="vm.selectDomain(domain)">example.com</button></li>
</ul> </ul>
</div> </div>