@heroku-cli/command
Advanced tools
Comparing version 8.1.7 to 8.1.8
@@ -0,1 +1,9 @@ | ||
<a name="8.1.8"></a> | ||
## [8.1.8](https://github.com/heroku/heroku-cli-command/compare/v8.1.7...v8.1.8) (2018-05-08) | ||
### Bug Fixes | ||
* sso login ([747ce09](https://github.com/heroku/heroku-cli-command/commit/747ce09)) | ||
<a name="8.1.7"></a> | ||
@@ -2,0 +10,0 @@ ## [8.1.7](https://github.com/heroku/heroku-cli-command/compare/v8.1.6...v8.1.7) (2018-05-08) |
@@ -12,2 +12,3 @@ "use strict"; | ||
const debug = require('debug')('heroku-cli-command'); | ||
const headers = (token) => ({ headers: { accept: 'application/vnd.heroku+json; version=3', authorization: `Bearer ${token}` } }); | ||
class Login { | ||
@@ -85,9 +86,10 @@ constructor(config, heroku) { | ||
// authorizations because they are created a trusted client | ||
requests.push(this.heroku.delete('/oauth/sessions/~') | ||
requests.push(http_call_1.default.delete(`${vars_1.vars.apiUrl}/oauth/sessions/~`, headers(this.heroku.auth)) | ||
.catch(err => { | ||
err = err.http; | ||
if (err.statusCode === 404 && err.body && err.body.id === 'not_found' && err.body.resource === 'session') { | ||
if (!err.http) | ||
throw err; | ||
if (err.http.statusCode === 404 && err.http.body && err.http.body.id === 'not_found' && err.http.body.resource === 'session') { | ||
return; | ||
} | ||
if (err.statusCode === 401 && err.body && err.body.id === 'unauthorized') { | ||
if (err.http.statusCode === 401 && err.http.body && err.http.body.id === 'unauthorized') { | ||
return; | ||
@@ -100,3 +102,3 @@ } | ||
// the ~ is the API Key, not the authorization that is currently requesting | ||
requests.push(this.heroku.get('/oauth/authorizations') | ||
requests.push(http_call_1.default.get(`${vars_1.vars.apiUrl}/oauth/authorizations`, headers(this.heroku.auth)) | ||
.then(async ({ body: authorizations }) => { | ||
@@ -111,6 +113,8 @@ // grab the default authorization because that is the token shown in the | ||
.filter(a => a.access_token && a.access_token.token !== this.heroku.auth) | ||
.map(a => this.heroku.delete(`/oauth/authorizations/${a.id}`))); | ||
.map(a => http_call_1.default.delete(`${vars_1.vars.apiUrl}/oauth/authorizations/${a.id}`, headers(this.heroku.auth)))); | ||
}) | ||
.catch(err => { | ||
if (err.statusCode === 401 && err.body && err.body.id === 'unauthorized') { | ||
if (!err.http) | ||
throw err; | ||
if (err.http.statusCode === 401 && err.http.body && err.http.body.id === 'unauthorized') { | ||
return []; | ||
@@ -136,3 +140,3 @@ } | ||
cli_ux_1.default.action.start('Logging in'); | ||
const { body: account } = await http_call_1.default.get(`${vars_1.vars.apiUrl}/account`, { headers: { accept: 'application/vnd.heroku+json; version=3', authorization: `Bearer ${auth.access_token}` } }); | ||
const { body: account } = await http_call_1.default.get(`${vars_1.vars.apiUrl}/account`, headers(auth.access_token)); | ||
cli_ux_1.default.action.stop(); | ||
@@ -208,3 +212,3 @@ return { | ||
try { | ||
const { body: authorization } = await this.heroku.get('/oauth/authorizations/~'); | ||
const { body: authorization } = await http_call_1.default.get(`${vars_1.vars.apiUrl}/oauth/authorizations/~`, headers(this.heroku.auth)); | ||
return authorization.access_token && authorization.access_token.token; | ||
@@ -247,3 +251,3 @@ } | ||
this.heroku.auth = password; | ||
const { body: account } = await http_call_1.default.get(`${vars_1.vars.apiUrl}/account`, { headers: { accept: 'application/vnd.heroku+json; version=3', authorization: `Bearer ${password}` } }); | ||
const { body: account } = await http_call_1.default.get(`${vars_1.vars.apiUrl}/account`, headers(password)); | ||
return { password, login: account.email, method: 'sso', org }; | ||
@@ -250,0 +254,0 @@ } |
{ | ||
"name": "@heroku-cli/command", | ||
"description": "base class for Heroku CLI commands", | ||
"version": "8.1.7", | ||
"version": "8.1.8", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/heroku-cli-command/issues", |
49213
1151