Allow (experimental!) login with API keys

Change-Type: minor
This commit is contained in:
Tim Perry 2018-03-23 16:35:39 +01:00
parent b4526e9895
commit 12a1916007
4 changed files with 15 additions and 12 deletions

View File

@ -262,7 +262,7 @@ from the dashboard.
- Credentials: using email/password and 2FA.
- Token: using the authentication token from the preferences page.
- Token: using a session token or API key (experimental) from the preferences page.
Examples:
@ -276,7 +276,7 @@ Examples:
#### --token, -t <token>
auth token
session token or API key (experimental)
#### --web, -w

View File

@ -27,7 +27,7 @@ exports.login =
- Credentials: using email/password and 2FA.
- Token: using the authentication token from the preferences page.
- Token: using a session token or API key (experimental) from the preferences page.
Examples:
@ -40,7 +40,7 @@ exports.login =
options: [
{
signature: 'token'
description: 'auth token'
description: 'session token or API key (experimental)'
parameter: 'token'
alias: 't'
}
@ -73,7 +73,7 @@ exports.login =
action: (params, options, done) ->
_ = require('lodash')
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
resin = require('resin-sdk').fromSharedOptions()
auth = require('../auth')
form = require('resin-cli-form')
patterns = require('../utils/patterns')
@ -84,7 +84,7 @@ exports.login =
return Promise.try ->
return options.token if _.isString(options.token)
return form.ask
message: 'Token (from the preferences page)'
message: 'Session token or API key (experimental) from the preferences page'
name: 'token'
type: 'input'
.then(resin.auth.loginWithToken)
@ -188,7 +188,7 @@ exports.whoami =
permission: 'user'
action: (params, options, done) ->
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
resin = require('resin-sdk').fromSharedOptions()
visuals = require('resin-cli-visuals')
Promise.props

View File

@ -62,14 +62,15 @@ capitanoExecuteAsync = Promise.promisify(capitano.execute)
# We don't yet use resin-sdk directly everywhere, but we set up shared
# options correctly so we can do safely in submodules
require('resin-sdk').setSharedOptions(
ResinSdk = require('resin-sdk')
ResinSdk.setSharedOptions(
apiUrl: settings.get('apiUrl')
imageMakerUrl: settings.get('imageMakerUrl')
dataDirectory: settings.get('dataDirectory')
retries: 2
)
# Keep using sdk-preconfigured for now, but only temporarily
resin = require('resin-sdk-preconfigured')
resin = ResinSdk.fromSharedOptions()
actions = require('./actions')
errors = require('./errors')

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
###
resin = require('resin-sdk-preconfigured')
resin = require('resin-sdk').fromSharedOptions()
_ = require('lodash')
url = require('url')
Promise = require('bluebird')
@ -62,7 +62,9 @@ exports.isTokenValid = (sessionToken) ->
if not sessionToken? or _.isEmpty(sessionToken.trim())
return Promise.resolve(false)
return resin.token.get().then (currentToken) ->
return resin.auth.getToken()
.catchReturn(undefined)
.then (currentToken) ->
resin.auth.loginWithToken(sessionToken)
.return(sessionToken)
.then(resin.auth.isLoggedIn)