insomnia/packages/insomnia-app/app/network/basic-auth/get-header.ts
Dimitri Mitropoulos 5f4c19da35
[TypeScript] Phase 1 & 2 (#3370)
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-12 18:35:00 +12:00

19 lines
536 B
TypeScript

import type { RequestHeader } from '../../models/request';
export function getBasicAuthHeader(
username?: string | null,
password?: string | null,
encoding = 'utf8',
) {
const name = 'Authorization';
const header = `${username || ''}:${password || ''}`;
// @ts-expect-error -- TSCONVERSION appears to be a genuine error
const authString = Buffer.from(header, encoding).toString('base64');
const value = `Basic ${authString}`;
const requestHeader: RequestHeader = {
name,
value,
};
return requestHeader;
}