2018-06-25 17:42:50 +00:00
|
|
|
import type { RequestHeader } from '../../models/request';
|
2017-11-26 20:45:40 +00:00
|
|
|
|
2020-09-24 20:58:28 +00:00
|
|
|
export function getBasicAuthHeader(
|
2021-05-12 06:35:00 +00:00
|
|
|
username?: string | null,
|
|
|
|
password?: string | null,
|
|
|
|
encoding = 'utf8',
|
|
|
|
) {
|
2017-11-26 20:45:40 +00:00
|
|
|
const name = 'Authorization';
|
|
|
|
const header = `${username || ''}:${password || ''}`;
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION appears to be a genuine error
|
2020-09-24 20:58:28 +00:00
|
|
|
const authString = Buffer.from(header, encoding).toString('base64');
|
2017-11-26 20:45:40 +00:00
|
|
|
const value = `Basic ${authString}`;
|
2021-05-12 06:35:00 +00:00
|
|
|
const requestHeader: RequestHeader = {
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
};
|
|
|
|
return requestHeader;
|
2017-11-26 20:45:40 +00:00
|
|
|
}
|