forked from nikku/camunda-worker-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-auth.js
More file actions
38 lines (28 loc) · 705 Bytes
/
basic-auth.js
File metadata and controls
38 lines (28 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
var auth = require('./auth');
/**
* Set username + password credentials on Engine API requests.
*
* @example
*
* Worker(engineEndpoint, {
* use: [
* BasicAuth('Walt', 'SECRET_PASSWORD')
* ]
* });
*/
function createBasicAuth(username, password) {
if (!username) {
throw new Error('<username> required');
}
if (typeof password === 'undefined') {
throw new Error('<password> required');
}
const token = base64encode(`${username}:${password}`);
return auth('Basic', token);
}
module.exports = createBasicAuth;
/* global btoa */
var base64encode = typeof btoa === 'function' ? btoa : function(str) {
return Buffer.from(str).toString('base64');
};