add oauth3

This commit is contained in:
aj 2017-08-14 18:58:01 +00:00
parent 5455b16ec7
commit 0ad5017ac9
6 changed files with 152 additions and 22 deletions

1
.well-known/oauth3 Symbolic link
View File

@ -0,0 +1 @@
../assets/oauth3.org/.well-known/oauth3

View File

@ -24,6 +24,11 @@
<!-- Lodash -->
<script src="/js/lib/lodash/lodash.min.js" charset="utf-8"></script>
<script src="/js/lib/lodash/lodash.underscore.min.js" charset="utf-8"></script>
<!-- Daplie Modules -->
<script src="/assets/oauth3.org/oauth3.core.js" charset="utf-8"></script>
<script src="/assets/oauth3.org/oauth3.dns.js" charset="utf-8"></script>
<script src="/assets/oauth3.org/oauth3.domains.js" charset="utf-8"></script>
<script src="/js/www@daplie.com.js" charset="utf-8"></script>
<!-- Angular Modules -->
<script src="/js/lib/angular/angular.min.js" charset="utf-8"></script>
<script src="/js/lib/angular/angular-local-storage.js" charset="utf-8"></script>
@ -31,6 +36,7 @@
<!-- Core Files -->
<script src="/js/app.js" charset="utf-8"></script>
<!-- Services -->
<script src="/assets/oauth3.org/oauth3.ng.js" charset="utf-8"></script>
<script src="/js/services/contacts.js" charset="utf-8"></script>
<script src="/js/services/auth.js" charset="utf-8"></script>
<!-- Controllers -->

7
install.sh Normal file
View File

@ -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

View File

@ -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){

View File

@ -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);
});
};
}]);

View File

@ -1,14 +1,27 @@
<section class="col-md-offset-4 col-md-4 login-container">
<form>
<h4 class="text-center">Sign in</h4>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="Email" ng-model="vm.userAuthEmail">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" placeholder="Password" ng-model="vm.userAuthPassword">
</div>
<button type="submit" class="btn btn-default" ng-click="vm.signIn()">Submit</button>
</form>
<form>
<h4 class="text-center">Sign in</h4>
<div class="form-group">
<label for="dap-address">Address</label>
<button class="btn btn-link" ng-click="vm.toggleAdvanced()" ng-if="vm.independentIssuer">hide advanced</button>
<button class="btn btn-link" ng-click="vm.toggleAdvanced()" ng-if="!vm.independentIssuer">show advanced</button>
<input type="text" class="form-control" placeholder="Email" ng-model="vm.newSubject" ng-change="vm.setSubject()">
</div>
<div ng-if="vm.independentIssuer">
<div class="form-group">
<label for="dap-issuer">Issuer</label>
<input type="text" class="form-control" placeholder="Issuer" ng-model="vm.newIssuer" ng-change="vm.setIssuer()">
</div>
</div>
<button type="submit" class="btn btn-default" ng-click="vm.signIn()">Login with <span ng-bind="vm.issuerName"></span></button>
<br>
<br>
<br>
<div>
Demo: <button class="btn btn-link" ng-click="vm.independentIssuer = true; vm.newSubject = 'coolaj86@gmail.com'; vm.newIssuer = 'provider.aj.daplie.me'; vm.instaauth();">coolaj86@aj.daplie.me</button>
<button class="btn btn-link" ng-click="vm.independentIssuer = true; vm.newSubject = 'coolaj86@gmail.com'; vm.newIssuer = 'oauth3.org'; vm.instaauth();">coolaj86@oauth3.org</button>
</div>
</form>
</section>