insomnia/packages/insomnia-app/app/network/basic-auth/get-header.js

12 lines
384 B
JavaScript
Raw Normal View History

// @flow
2018-06-25 17:42:50 +00:00
import type { RequestHeader } from '../../models/request';
2018-10-17 16:42:33 +00:00
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}`;
2018-06-25 17:42:50 +00:00
return { name, value };
}