Merge pull request #277 from resin-io/jviotti/feat/token-login

Support for login in with token
This commit is contained in:
Juan Cruz Viotti 2015-12-04 10:55:39 -04:00
commit 7d0da7adc0
3 changed files with 50 additions and 5 deletions

View File

@ -20,11 +20,24 @@
exports.login = { exports.login = {
signature: 'login', signature: 'login',
description: 'login to resin.io', description: 'login to resin.io',
help: 'Use this command to login to your resin.io account.\n\nExamples:\n\n $ resin login', help: 'Use this command to login to your resin.io account.\n\nThis command will open your web browser and prompt you to authorize the CLI\nfrom the dashboard.\n\nIf you don\'t have access to a web browser (e.g: running in a headless server),\nyou can fetch your authentication token from the preferences page and pass\nthe token option.\n\nExamples:\n\n $ resin login\n $ resin login --token "..."',
options: [
{
signature: 'token',
description: 'auth token',
parameter: 'token',
alias: 't'
}
],
primary: true, primary: true,
action: function(params, options, done) { action: function(params, options, done) {
console.info('Connecting to the web dashboard'); return Promise["try"](function() {
return auth.login().then(resin.auth.whoami).tap(function(username) { if (options.token != null) {
return resin.auth.loginWithToken(options.token);
}
console.info('Connecting to the web dashboard');
return auth.login();
}).then(resin.auth.whoami).tap(function(username) {
console.info("Successfully logged in as: " + username); console.info("Successfully logged in as: " + username);
return events.send('user.login'); return events.send('user.login');
}).nodeify(done); }).nodeify(done);

View File

@ -165,9 +165,23 @@ confirm non interactively
Use this command to login to your resin.io account. Use this command to login to your resin.io account.
This command will open your web browser and prompt you to authorize the CLI
from the dashboard.
If you don't have access to a web browser (e.g: running in a headless server),
you can fetch your authentication token from the preferences page and pass
the token option.
Examples: Examples:
$ resin login $ resin login
$ resin login --token "..."
### Options
#### --token, -t <token>
auth token
## logout ## logout

View File

@ -13,14 +13,32 @@ exports.login =
help: ''' help: '''
Use this command to login to your resin.io account. Use this command to login to your resin.io account.
This command will open your web browser and prompt you to authorize the CLI
from the dashboard.
If you don't have access to a web browser (e.g: running in a headless server),
you can fetch your authentication token from the preferences page and pass
the token option.
Examples: Examples:
$ resin login $ resin login
$ resin login --token "..."
''' '''
options: [
signature: 'token'
description: 'auth token'
parameter: 'token'
alias: 't'
]
primary: true primary: true
action: (params, options, done) -> action: (params, options, done) ->
console.info('Connecting to the web dashboard') Promise.try ->
auth.login() if options.token?
return resin.auth.loginWithToken(options.token)
console.info('Connecting to the web dashboard')
return auth.login()
.then(resin.auth.whoami) .then(resin.auth.whoami)
.tap (username) -> .tap (username) ->
console.info("Successfully logged in as: #{username}") console.info("Successfully logged in as: #{username}")