From 80217fd39bf9b02e1901b5e170476617c7e48ada Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 14 Apr 2017 16:50:09 -0600 Subject: [PATCH 1/8] add .jshintrc --- .jshintrc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..63801ce --- /dev/null +++ b/.jshintrc @@ -0,0 +1,16 @@ +{ "node": true +, "browser": true +, "jquery": true +, "strict": true +, "indent": 2 +, "onevar": true +, "laxcomma": true +, "laxbreak": true +, "eqeqeq": true +, "immed": true +, "undef": true +, "unused": true +, "latedef": true +, "curly": true +, "trailing": true +} From daa92fa829e965073463b6a4aa46168a5f2606b4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 14 Apr 2017 16:52:00 -0600 Subject: [PATCH 2/8] add missing semis --- oauth3.core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index 43acd4a..806b4b6 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -1086,8 +1086,8 @@ if (!me._providerUri) { throw new Error("'providerUri' was not supplied"); } - opts.session.provider_uri = me._providerUri - opts.session.client_uri = me._clientUri + opts.session.provider_uri = me._providerUri; + opts.session.client_uri = me._clientUri; me.session(opts.session, opts.sessionId); } } From c4cc61992805469f86ecd4d74afc18cf6506155b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 28 Apr 2017 18:40:37 -0600 Subject: [PATCH 3/8] begin cli parser --- bin/cli.js | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 bin/cli.js diff --git a/bin/cli.js b/bin/cli.js new file mode 100644 index 0000000..da3be23 --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,144 @@ +'use strict'; + +var oauth3 = require('./oauth3.js'); +var defaults = { + main: 'oauth3' +, provider: 'oauth3.org' +}; + +function parseArgs(argv, opts) { + var args = Array.prototype.slice.call(argv); + var sep = /[:\.\-]/; + + args.shift(); // node + args.shift(); // oauth3.js + + var command = args.shift() || 'help'; + var cmdpair = command.split(sep); + var cmd = cmdpair[0]; + var sub = cmdpair[1]; + var COMMAND = 'COMMAND'; + var maxCmdLen = COMMAND.length; + var maxPairLen = 0; + var cmds; + var arg1 = args[0]; + + // build commands list + var pairsMap = {}; + cmds = opts.commands.filter(function (desc) { + var pair = desc[0].split(/\s+/)[0]; + var psub = pair.split(sep)[0]; + pairsMap[pair] = true; + maxPairLen = Math.max(maxPairLen, pair.length); + if (pair === psub) { + maxCmdLen = Math.max(maxCmdLen, psub.length); + return true; + } + }); + + if (-1 === Object.keys(pairsMap).indexOf(cmd)) { + console.log('fail', cmd); + arg1 = cmd; + cmd = 'help'; + help(); + } + + function rpad(str, len) { + while (str.length < len) { + str += ' '; + } + return str; + } + + function help() { + var status = 0; + + function helpMain() { + console.log(''); + console.log('Here are all the top-level commands:'); + console.log(''); + + console.log('\t' + defaults.main + ' ' + rpad(COMMAND, maxCmdLen), ' # description'); + console.log('\t' + '------------------------------'); + cmds.forEach(function (desc) { + var pcmd = rpad(desc[0].split(/\s+/)[0], maxCmdLen); + var pdesc = desc[1]; + console.log('\t' + defaults.main + ' ' + pcmd, ' # ' + pdesc); + }); + console.log(''); + } + + if (arg1 && -1 === Object.keys(pairsMap).indexOf(arg1)) { + status = 1; + console.log(''); + console.log(defaults.main + ": Unknown command '" + arg1 + "'"); + arg1 = null; + } + if (!arg1 || '-' === arg1[0]) { + helpMain(); + process.exit(status); + } + if ('help' === arg1) { + helpMain(); + console.log("no more help available for 'help'"); + process.exit(status); + } + } + + if (-1 !== [ 'help', '-h', '--help' ].indexOf(command) || -1 !== args.indexOf('-h') || -1 !== args.indexOf('--help')) { + help(); + return; + } +} + +parseArgs(process.argv, { + // CLI goals: + // + // whoami / login: you are now logged in as + // * john@example.com [current] (just now) + // * john@work.net (2 minutes ago) + // * john@family.me (2 weeks ago) + commands: [ + [ 'login [email or cloud address]', 'alias of session:attach', [ + "--auto, create a new account without asking if none exists" + //, "--exclusive, logout all other ids, removing access to their accounts" + , "--provider, specify an authentication provider (default: :provider)".replace(/\b:provider\b/, defaults.provider) + //, "--email [addr], use the given id as an email address, even if it works as a cloud address" + //, "--cloud [addr], use the given id as a cloud address or fail (don't fallback to email)" + ] + ] + , [ 'logout', 'alias of session:detach' ] + , [ 'whoami', 'show current account(s) and login(s) and device(s)' ] + + // authn + , [ 'session', 'Manage your ids (credentials / logins)' ] + , [ 'session:new', 'alias of `login --exclusive`' ] + , [ 'session:attach', 'Create a session (and account if needed) for a given email address or cloud address' ] + , [ 'session:detach', 'remove login from session' ] + , [ 'session:list', 'show all of the ids in the current session' ] + + // authz + , [ 'accounts', 'Manage your accounts (authorization / profiles)' ] + , [ 'accounts:new', 'create a new account attached to the credentials of the current session' ] + , [ 'accounts:set', 'change account details' ] // todo changing the name should be restricted john@provider.net -> jonathan@provider.net would be bad + , [ 'accounts:list', 'show all of the accounts in the current session' ] + , [ 'accounts:attach', 'attach an account to an id' ] + , [ 'accounts:detach', 'detach an account from an id' ] + , [ 'accounts:select', 'select an account to use as the primary account for this session' ] + , [ 'accounts:update', '(deprecated) alias of set' ] + , [ 'accounts:login', '(deprecated) alias of login' ] + , [ 'accounts:whoami', '(deprecated) alias of whoami' ] + + // authn / authz + , [ 'devices', 'manages devices for your account(s)' ] + , [ 'devices:new', 'create a new device (default name is hostname, default ip is the result of :provider/api/org.oauth3.tunnel/checkip)'.replace(/\b:provider\b/, defaults.provider) ] + , [ 'devices:set', 'set the ip address of the device (defaults ip is the result of :provider/api/org.oauth3.tunnel/checkip)'.replace(/\b:provider\b/, defaults.provider) ] + , [ 'devices:attach', "attach a device to a domain's DNS record" ] + , [ 'devices:detach', "detach an account from a domain's DNS record" ] + , [ 'devices:select', '(re)claim the specified device as this device (i.e. you re-installed your OS or deleted your ~/.oauth3)' ] + , [ 'devices:list', 'show all devices for your account(s)' ] + + // help + , [ 'help', "show this menu; use '" + defaults.main + " help COMMAND' (even 'help') for options and sub-commands" ] + ] +}); From 87ba1e4298015d34695eea3d7ecebc078c839c8f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 May 2017 16:18:49 -0600 Subject: [PATCH 4/8] warn browser users loud and clear that only https is supported --- oauth3.core.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oauth3.core.js b/oauth3.core.js index 806b4b6..f71487d 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -2,6 +2,10 @@ ;(function (exports) { 'use strict'; + if ('undefined' !== typeof window && 'https:' !== window.location.protocol) { + window.alert("You must use https. We suggest using caddy as your webserver (or serve-https if testing locally)"); + } + var OAUTH3 = exports.OAUTH3 = { clientUri: function (location) { return OAUTH3.uri.normalize(location.host + (location.pathname || '')); From 0a0a5041b7e748737539e099ba55de3477d2e6c0 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 May 2017 16:19:42 -0600 Subject: [PATCH 5/8] v1.0.9 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 59aba45..a32a60d 100644 --- a/bower.json +++ b/bower.json @@ -39,5 +39,5 @@ "test", "tests" ], - "version": "1.0.8" + "version": "1.0.9" } diff --git a/package.json b/package.json index 6d1b4ec..e76fc7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oauth3.js", - "version": "1.0.8", + "version": "1.0.9", "description": "The world's smallest, fastest, and most secure OAuth3 (and OAuth2) JavaScript implementation.", "main": "oauth3.node.js", "scripts": { From ec33e667b3d9222f92406ab6d0011c4be256e81d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 May 2017 23:39:56 +0000 Subject: [PATCH 6/8] don't omit scope, duh --- oauth3.core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/oauth3.core.js b/oauth3.core.js index 43acd4a..ba39238 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -698,6 +698,7 @@ , { redirect_uri: opts.redirect_uri , client_id: opts.client_id || opts.client_uri , client_uri: opts.client_uri || opts.client_id + , scope: opts.scope , state: opts._state || undefined , debug: opts.debug } From 181027a07f161d1a4449bdca24c1842f45080d61 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 May 2017 17:43:22 -0600 Subject: [PATCH 7/8] v1.0.10 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index a32a60d..d6dece9 100644 --- a/bower.json +++ b/bower.json @@ -39,5 +39,5 @@ "test", "tests" ], - "version": "1.0.9" + "version": "1.0.10" } diff --git a/package.json b/package.json index e76fc7c..606658b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oauth3.js", - "version": "1.0.9", + "version": "1.0.10", "description": "The world's smallest, fastest, and most secure OAuth3 (and OAuth2) JavaScript implementation.", "main": "oauth3.node.js", "scripts": { From b4804b4c979921770f5203a50492ad9ece333d41 Mon Sep 17 00:00:00 2001 From: Drew Warren Date: Tue, 9 May 2017 10:08:29 -0600 Subject: [PATCH 8/8] update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c2658d7..afde3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules/ +DS_Store +.vscode \ No newline at end of file