From 8b7e2ad1c9f4fcb400b652013cc6ba30a5741006 Mon Sep 17 00:00:00 2001 From: Henrique Vicente Date: Mon, 30 Nov 2015 02:30:05 -0300 Subject: [PATCH] Fixing BasicAuth due to missing btoa(). https://github.com/nodejs/node/issues/3462 --- src/api/Launchpad.js | 5 +++-- src/btoa/Btoa.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/btoa/Btoa.js diff --git a/src/api/Launchpad.js b/src/api/Launchpad.js index 04f7a9d..15a4d12 100644 --- a/src/api/Launchpad.js +++ b/src/api/Launchpad.js @@ -1,7 +1,7 @@ 'use strict'; import core from 'bower:metal/src/core'; -import Auth from '../api/Auth'; +import Auth from './Auth'; import Embodied from '../api-query/Embodied'; import Filter from '../api-query/Filter'; import Query from '../api-query/Query'; @@ -9,6 +9,7 @@ import TransportFactory from './TransportFactory'; import ClientRequest from './ClientRequest'; import Util from './Util'; import MultiMap from './MultiMap'; +import Btoa from '../btoa/Btoa'; var io; @@ -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 ' + Btoa.btoa(credentials)); } } diff --git a/src/btoa/Btoa.js b/src/btoa/Btoa.js new file mode 100644 index 0000000..c95373e --- /dev/null +++ b/src/btoa/Btoa.js @@ -0,0 +1,13 @@ +'use strict'; + +class Btoa { + btoa(stringToEncode) { + if (typeof btoa === 'function') { + return btoa(stringToEncode); + } + + return new Buffer(stringToEncode.toString(), 'binary'); + } +} + +export default Btoa;