Skip to content

Commit

Permalink
Handle OAuth server metadata not found error generically
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Nov 14, 2019
1 parent 87cbef8 commit f8cb4db
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
18 changes: 2 additions & 16 deletions docs/kubebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ const crypto = require('crypto'),
GoogleCloudPlatform = require('./auth/gcp'),
URI = require('urijs');

const { error } = require('./error');

class ChainRequest {

constructor(...requests) {
Expand Down Expand Up @@ -449,12 +447,6 @@ class Client {
oauth_authorize({ username, password }) {
return new ChainRequest(
() => this.oauth_server_metadata(),
{
onRejected: err => {
return Promise.reject(err.response && [401, 403, 404].includes(err.response.statusCode)
? error(`Authentication failed for ${this.url}, OAuth method unavailable!`)
: err)
}},
response => {
const metadata = JSON.parse(response.body.toString('utf8'));
const { protocol, hostname, port, path } = URI.parse(metadata.authorization_endpoint);
Expand All @@ -479,12 +471,6 @@ class Client {
oauth_authorize_web({ username, password }) {
return new ChainRequest(
() => this.oauth_server_metadata(),
{
onRejected: err => {
return Promise.reject(err.response && [401, 403, 404].includes(err.response.statusCode)
? error(`Authentication failed for ${this.url}, OAuth method unavailable!`)
: err)
}},
response => {
const metadata = JSON.parse(response.body.toString('utf8'));
const { protocol, hostname, port, path } = URI.parse(metadata.authorization_endpoint);
Expand Down Expand Up @@ -581,7 +567,7 @@ function mergeSingle(target, source) {

module.exports = Client;

},{"./auth/exec":1,"./auth/gcp":2,"./auth/oidc":3,"./error":10,"./http-then":"http-then","crypto":162,"urijs":"urijs"}],5:[function(require,module,exports){
},{"./auth/exec":1,"./auth/gcp":2,"./auth/oidc":3,"./http-then":"http-then","crypto":162,"urijs":"urijs"}],5:[function(require,module,exports){
'use strict';

const URI = require('urijs');
Expand Down Expand Up @@ -77587,7 +77573,7 @@ class Kubebox extends EventEmitter {
.fail(s => status.setContent(`${s} Authenticating to {bold}${client.url}{/bold}`))
.then(user => log(`{green-fg}Authenticated as {bold}${user.metadata.name}{/bold}{/green-fg}`)
.then(() => connect(null, Object.assign({}, options, { user: user }))))
.catch(error => error.response && error.response.statusCode === 401
.catch(error => error.response && [401, 403, 404].includes(error.response.statusCode)
? log(`{red-fg}Authentication failed for ${client.url}{/red-fg}`)
// throttle reauthentication
.then(wait(100))
Expand Down
14 changes: 0 additions & 14 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const crypto = require('crypto'),
GoogleCloudPlatform = require('./auth/gcp'),
URI = require('urijs');

const { error } = require('./error');

class ChainRequest {

constructor(...requests) {
Expand Down Expand Up @@ -209,12 +207,6 @@ class Client {
oauth_authorize({ username, password }) {
return new ChainRequest(
() => this.oauth_server_metadata(),
{
onRejected: err => {
return Promise.reject(err.response && [401, 403, 404].includes(err.response.statusCode)
? error(`Authentication failed for ${this.url}, OAuth method unavailable!`)
: err)
}},
response => {
const metadata = JSON.parse(response.body.toString('utf8'));
const { protocol, hostname, port, path } = URI.parse(metadata.authorization_endpoint);
Expand All @@ -239,12 +231,6 @@ class Client {
oauth_authorize_web({ username, password }) {
return new ChainRequest(
() => this.oauth_server_metadata(),
{
onRejected: err => {
return Promise.reject(err.response && [401, 403, 404].includes(err.response.statusCode)
? error(`Authentication failed for ${this.url}, OAuth method unavailable!`)
: err)
}},
response => {
const metadata = JSON.parse(response.body.toString('utf8'));
const { protocol, hostname, port, path } = URI.parse(metadata.authorization_endpoint);
Expand Down
2 changes: 1 addition & 1 deletion lib/kubebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Kubebox extends EventEmitter {
.fail(s => status.setContent(`${s} Authenticating to {bold}${client.url}{/bold}`))
.then(user => log(`{green-fg}Authenticated as {bold}${user.metadata.name}{/bold}{/green-fg}`)
.then(() => connect(null, Object.assign({}, options, { user: user }))))
.catch(error => error.response && error.response.statusCode === 401
.catch(error => error.response && [401, 403, 404].includes(error.response.statusCode)
? log(`{red-fg}Authentication failed for ${client.url}{/red-fg}`)
// throttle reauthentication
.then(wait(100))
Expand Down

0 comments on commit f8cb4db

Please sign in to comment.