Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 5x 5x 5x 5x 5x | import 'isomorphic-base64'; import user from '../user'; /** * Returns the Authorization header as part of an Object. * * @export * @param {Object} [server={}] * @param {Object} [server.requestOptions] * @param {string|function} [server.requestOptions.auth] * @returns {Object} { Authorization } */ export default function getAuthorizationHeader({ requestOptions } = {}, user) { const headers = {}; // Check for OHIF.user since this can also be run on the server const accessToken = user && user.getAccessToken && user.getAccessToken(); // Auth for a specific server Iif (requestOptions && requestOptions.auth) { if (typeof requestOptions.auth === 'function') { // Custom Auth Header headers.Authorization = requestOptions.auth(requestOptions); } else { // HTTP Basic Auth (user:password) headers.Authorization = `Basic ${btoa(requestOptions.auth)}`; } } // Auth for the user's default else Iif (accessToken) { headers.Authorization = `Bearer ${accessToken}`; } return headers; } |