Skip to content

Instantly share code, notes, and snippets.

@danemacaulay
Created December 13, 2014 00:07
Show Gist options
  • Save danemacaulay/a20c84283d40f86dd2c9 to your computer and use it in GitHub Desktop.
Save danemacaulay/a20c84283d40f86dd2c9 to your computer and use it in GitHub Desktop.
function setAuthenticationHeaders(config, authService) {
// Is this a local URL? If so, add auth headers, but don't overwrite
// any that are not already set - this allows someone to pass in
// overrides if so desired.
//
// Note: we don't want to send out headers to URLs that will go out to
// the CDN. This would be very bad. This path check should be sufficient
// to that end.
if (config.url.indexOf('/DNB360UIAgent/') === 0) {
var authHeaders = authService.authHeaders();
if (authHeaders) {
config.headers = config.headers || {};
for (var header in authHeaders) {
if (!config.headers[header]) {
config.headers[header] = authHeaders[header];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment