insomnia/packages/insomnia-app/app/network/basic-auth/get-header.js
2018-10-17 12:42:33 -04:00

12 lines
384 B
JavaScript

// @flow
import type { RequestHeader } from '../../models/request';
export function getBasicAuthHeader(username: ?string, password: ?string): RequestHeader {
const name = 'Authorization';
const header = `${username || ''}:${password || ''}`;
const authString = Buffer.from(header, 'utf8').toString('base64');
const value = `Basic ${authString}`;
return { name, value };
}