Skip to content

Commit

Permalink
fix(security, http): expose authentication headers in the authenticat…
Browse files Browse the repository at this point in the history
…ion result when HTTP authentication is used
  • Loading branch information
azasypkin committed Aug 21, 2024
1 parent e3d6cf6 commit 221aad8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ describe('HTTPAuthenticationProvider', () => {
});

await expect(provider.authenticate(request)).resolves.toEqual(
AuthenticationResult.succeeded({
...user,
authentication_provider: { type: 'http', name: 'http' },
})
AuthenticationResult.succeeded(
{ ...user, authentication_provider: { type: 'http', name: 'http' } },
{ authHeaders: { authorization: header } }
)
);

expectAuthenticateCall(mockOptions.client, { headers: { authorization: header } });
Expand All @@ -160,10 +160,10 @@ describe('HTTPAuthenticationProvider', () => {
});

await expect(provider.authenticate(request)).resolves.toEqual(
AuthenticationResult.succeeded({
...user,
authentication_provider: { type: 'http', name: 'http' },
})
AuthenticationResult.succeeded(
{ ...user, authentication_provider: { type: 'http', name: 'http' } },
{ authHeaders: { authorization: header } }
)
);

expectAuthenticateCall(mockOptions.client, { headers: { authorization: header } });
Expand All @@ -187,10 +187,10 @@ describe('HTTPAuthenticationProvider', () => {
});

await expect(provider.authenticate(request)).resolves.toEqual(
AuthenticationResult.succeeded({
...user,
authentication_provider: { type: 'http', name: 'http' },
})
AuthenticationResult.succeeded(
{ ...user, authentication_provider: { type: 'http', name: 'http' } },
{ authHeaders: { authorization: header } }
)
);

expectAuthenticateCall(mockOptions.client, { headers: { authorization: header } });
Expand All @@ -217,10 +217,10 @@ describe('HTTPAuthenticationProvider', () => {
});

await expect(provider.authenticate(request)).resolves.toEqual(
AuthenticationResult.succeeded({
...user,
authentication_provider: { type: 'http', name: 'http' },
})
AuthenticationResult.succeeded(
{ ...user, authentication_provider: { type: 'http', name: 'http' } },
{ authHeaders: { authorization: header } }
)
);

expectAuthenticateCall(mockOptions.client, { headers: { authorization: header } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export class HTTPAuthenticationProvider extends BaseAuthenticationProvider {
return AuthenticationResult.notHandled();
}

return AuthenticationResult.succeeded(user);
return AuthenticationResult.succeeded(user, {
// Even though the `Authorization` header is already present in the HTTP headers of the original request,
// we still need to expose it to the Core authentication service for consistency.
authHeaders: { authorization: authorizationHeader.toString() },
});
} catch (err) {
this.logger.debug(
() =>
Expand Down

0 comments on commit 221aad8

Please sign in to comment.