🎉
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
export function constructHeaders(username, password) {
|
||||
const Authorization = constructAuthHeader(username, password);
|
||||
return {
|
||||
Authorization,
|
||||
Accept: "application/json"
|
||||
};
|
||||
}
|
||||
function constructAuthHeader(username, password) {
|
||||
const credentials = `${username}:${password}`;
|
||||
return `Basic ${toBase64(credentials)}`;
|
||||
}
|
||||
function toBase64(data) {
|
||||
const existsTextEncoder= typeof TextEncoder !== 'undefined';
|
||||
if (!existsTextEncoder)
|
||||
return btoa(data);
|
||||
const existsUint8ArrayToBase64= typeof Uint8Array.prototype.toBase64 === 'function';
|
||||
if (existsUint8ArrayToBase64)
|
||||
return new TextEncoder().encode(data).toBase64();
|
||||
|
||||
const binString= Array.from(new TextEncoder().encode(data))
|
||||
.map(x=> String.fromCharCode(x)).join("");
|
||||
return btoa(binString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user