diff --git a/src/api/Launchpad.js b/src/api/Launchpad.js index d1931ec..9366d92 100644 --- a/src/api/Launchpad.js +++ b/src/api/Launchpad.js @@ -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'; @@ -397,7 +398,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)); } } diff --git a/src/crypt/Base64.js b/src/crypt/Base64.js new file mode 100644 index 0000000..245d45a --- /dev/null +++ b/src/crypt/Base64.js @@ -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;