diff --git a/x-pack/plugins/security/server/authentication/providers/http.test.ts b/x-pack/plugins/security/server/authentication/providers/http.test.ts index 90ff62294ff3fd..d599b6be2d9c38 100644 --- a/x-pack/plugins/security/server/authentication/providers/http.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/http.test.ts @@ -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 } }); @@ -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 } }); @@ -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 } }); @@ -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 } }); diff --git a/x-pack/plugins/security/server/authentication/providers/http.ts b/x-pack/plugins/security/server/authentication/providers/http.ts index 630ae7ea59de78..8619d942d3e1d6 100644 --- a/x-pack/plugins/security/server/authentication/providers/http.ts +++ b/x-pack/plugins/security/server/authentication/providers/http.ts @@ -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( `Failed to authenticate request to ${request.url.pathname} via authorization header with "${