began internal initialization API
This commit is contained in:
parent
44bfc02fa1
commit
1cae332c9c
|
@ -5,9 +5,9 @@
|
|||
</head>
|
||||
<body class="fade" ng-class="[ 'in' ]">
|
||||
|
||||
Do admin stuff:
|
||||
|
||||
<div ng-controller="LoginController as vm" ng-init="vm.setSimple()">
|
||||
<h1 ng-if="!vm.authnUpdated">Initializing... {{vm.hello}}</h1>
|
||||
<div ng-if="!vm.authnUpdated">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-link"
|
||||
|
@ -32,8 +32,10 @@
|
|||
ng-click="vm.authenticate()"
|
||||
>Login</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<li>Show Device Name</li>
|
||||
<li>Login to Daplie</li>
|
||||
<li>Show domains (or ask purchase)</li>
|
||||
<li>Tunnel On</li>
|
||||
|
|
|
@ -4,8 +4,12 @@ angular.module('com.daplie.cloud', [ 'org.oauth3' ])
|
|||
auth.setProvider('oauth3.org');
|
||||
return auth;
|
||||
} ])
|
||||
.controller('LoginController', [ '$timeout', 'oauth3', function ($timeout, oauth3) {
|
||||
.controller('LoginController', [ '$scope', '$timeout', 'oauth3', function ($scope, $timeout, oauth3) {
|
||||
var vm = this;
|
||||
var OAUTH3 = window.OAUTH3;
|
||||
|
||||
vm.hello = 'Hello!';
|
||||
vm.clientUri = OAUTH3.clientUri(window.location);
|
||||
|
||||
vm.setSimple = function () {
|
||||
vm.advanced = false;
|
||||
|
@ -35,15 +39,69 @@ angular.module('com.daplie.cloud', [ 'org.oauth3' ])
|
|||
};
|
||||
|
||||
vm.authenticate = function () {
|
||||
// TODO authorization redirect /api/org.oauth3.consumer/authorization_redirect/:provider_uri
|
||||
|
||||
return oauth3.authenticate().then(function (session) {
|
||||
console.info("Authorized Session", session);
|
||||
|
||||
return oauth3.api('domains.list').then(function (domains) {
|
||||
console.info("domains owned", domains);
|
||||
vm.domains = domains;
|
||||
|
||||
return OAUTH3.request({
|
||||
method: 'POST'
|
||||
, url: 'https://' + vm.clientUri + '/api/com.daplie.caddy/init'
|
||||
, session: session
|
||||
, data: {
|
||||
access_token: session.access_token
|
||||
, refresh_token: session.refresh_token
|
||||
, expires_in: session.expires_in
|
||||
, scope: session.scope
|
||||
, provider_uri: OAUTH3.uri.normalize(session.provider_uri)
|
||||
, client_uri: vm.clientUri
|
||||
, domains: domains.map(function (d) {
|
||||
return {
|
||||
id: d.id
|
||||
, sub: d.sub
|
||||
, sld: d.sld
|
||||
, tld: d.tld
|
||||
};
|
||||
})
|
||||
}
|
||||
}).then(function (resp) {
|
||||
console.info('Initialized Goldilocks', resp);
|
||||
return resp;
|
||||
}, function (err) {
|
||||
console.error(err);
|
||||
window.alert("Initialization failed:" + err.message);
|
||||
});
|
||||
});
|
||||
}, function (err) {
|
||||
console.error(err);
|
||||
window.alert("Authentication failed:" + err.message);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
console.log('OAUTH3.PromiseA', OAUTH3.PromiseA);
|
||||
return oauth3.setProvider('oauth3.org').then(function () {
|
||||
return oauth3.authenticate({ windowType: 'background' }).then(function () {
|
||||
console.log('HELLO!!');
|
||||
//vm.authnUpdated = Date.now();
|
||||
vm.hasSession = true;
|
||||
}, function () {
|
||||
console.log('GOODBYE!!');
|
||||
//vm.authnUpdated = Date.now();
|
||||
vm.hasSession = false;
|
||||
$timeout(function () {
|
||||
console.log('GOODBYE!!');
|
||||
vm.hello = 'Nope!';
|
||||
}, 1);
|
||||
});
|
||||
});
|
||||
//*/
|
||||
|
||||
}]);
|
||||
/*
|
||||
$(function () {
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = function (opts) {
|
|||
var pathsMap = {};
|
||||
var content = opts.content;
|
||||
var server;
|
||||
var serveInit;
|
||||
|
||||
function addServer(hostname) {
|
||||
|
||||
|
@ -71,6 +72,14 @@ module.exports = function (opts) {
|
|||
addServer(opts.sites[0].name);
|
||||
|
||||
return function (req, res) {
|
||||
if ('/api/com.daplie.caddy/init' === req.url) {
|
||||
if (!serveInit) {
|
||||
serveInit = require('../packages/apis/com.daplie.caddy').create(opts);
|
||||
}
|
||||
serveInit(req, res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (content && '/' === req.url) {
|
||||
// res.setHeader('Content-Type', 'application/octet-stream');
|
||||
res.end(content);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
"homepage": "https://git.daplie.com/Daplie/goldilocks.js#readme",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.4.6",
|
||||
"body-parser": "git+https://github.com/expressjs/body-parser.git#1.16.1",
|
||||
"daplie-tunnel": "git+https://git.daplie.com/Daplie/daplie-cli-tunnel.git#master",
|
||||
"ddns-cli": "git+https://git.daplie.com/Daplie/node-ddns-client.git#master",
|
||||
"finalhandler": "^0.4.0",
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
module.exports.create = function (opts) {
|
||||
var bodyParser = require('body-parser');
|
||||
var jsonParser = bodyParser.json({
|
||||
inflate: true, limit: '100kb', reviver: null, strict: true /* type, verify */
|
||||
});
|
||||
|
||||
return function (req, res) {
|
||||
jsonParser(req, res, function () {
|
||||
|
||||
console.log('req.body', req.body);
|
||||
|
||||
res.setHeader('Content-Type', 'application/json;');
|
||||
res.end(JSON.stringify({ error: { message: "Not Implemented", code: "E_NO_IMPL" } }));
|
||||
});
|
||||
};
|
||||
};
|
|
@ -1 +1 @@
|
|||
Subproject commit 1e0d129b8a6748f635b6f6985d7dae2ece747e55
|
||||
Subproject commit eff1fd11272472e8f6d03ac8b897a9853810672e
|
Loading…
Reference in New Issue