Skip to content

Commit

Permalink
Fixing BasicAuth due to missing btoa().
Browse files Browse the repository at this point in the history
  • Loading branch information
henvic committed Dec 24, 2015
1 parent bbc6b5e commit 487d9d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/api/Launchpad.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

import core from 'bower:metal/src/core';
import Auth from '../api/Auth';
import Auth from './Auth';
import Base64 from '../crypt/Base64';
import Embodied from '../api-query/Embodied';
import Filter from '../api-query/Filter';
import Query from '../api-query/Query';
Expand Down Expand Up @@ -403,7 +404,7 @@ class Launchpad {
clientRequest.header('Authorization', 'Bearer ' + this.auth_.token());
} else {
var credentials = this.auth_.username() + ':' + this.auth_.password();
clientRequest.header('Authorization', 'Basic ' + btoa(credentials));
clientRequest.header('Authorization', 'Basic ' + Base64.encodeString(credentials));
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/crypt/Base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

/**
* Abstraction layer for string to base64 conversion
* reference: https://github.com/nodejs/node/issues/3462
*/
class Base64 {
/**
* Creates a base-64 encoded ASCII string from a "string" of binary data.
* @param {string} string to be encoded.
* @return {string}
* @static
*/
static encodeString(string) {
if (typeof btoa === 'function') {
return btoa(string);
}

return new Buffer(string.toString(), 'binary');
}
}

export default Base64;

0 comments on commit 487d9d1

Please sign in to comment.