Skip to content

Commit 07b17ae

Browse files
committed
Fixing BasicAuth due to missing btoa().
nodejs/node#3462
1 parent a25ddbd commit 07b17ae

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/api/Launchpad.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
import core from 'bower:metal/src/core';
4-
import Auth from '../api/Auth';
4+
import Auth from './Auth';
5+
import Base64 from '../crypt/Base64';
56
import Embodied from '../api-query/Embodied';
67
import Filter from '../api-query/Filter';
78
import Query from '../api-query/Query';
@@ -403,7 +404,7 @@ class Launchpad {
403404
clientRequest.header('Authorization', 'Bearer ' + this.auth_.token());
404405
} else {
405406
var credentials = this.auth_.username() + ':' + this.auth_.password();
406-
clientRequest.header('Authorization', 'Basic ' + btoa(credentials));
407+
clientRequest.header('Authorization', 'Basic ' + Base64.encodeString(credentials));
407408
}
408409
}
409410

src/crypt/Base64.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
/**
4+
* Abstraction layer for string to base64 conversion
5+
* reference: https://github.com/nodejs/node/issues/3462
6+
*/
7+
class Base64 {
8+
/**
9+
* Creates a base-64 encoded ASCII string from a "string" of binary data.
10+
* @param {string} string to be encoded.
11+
* @return {string}
12+
* @static
13+
*/
14+
static encodeString(string) {
15+
if (typeof btoa === 'function') {
16+
return btoa(string);
17+
}
18+
19+
return new Buffer(string.toString(), 'binary');
20+
}
21+
}
22+
23+
export default Base64;

0 commit comments

Comments
 (0)