mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[cloud] Get user email from saml metadata (#124301)
This commit is contained in:
parent
7b9901eac8
commit
c877725dfc
2 changed files with 15 additions and 4 deletions
|
@ -44,14 +44,16 @@ describe('chat route', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('returns user information and a token', async () => {
|
||||
test('returns user information taken from saml metadata and a token', async () => {
|
||||
const security = securityMock.createSetup();
|
||||
const username = 'user.name';
|
||||
const email = 'user@elastic.co';
|
||||
|
||||
security.authc.getCurrentUser.mockReturnValueOnce({
|
||||
username,
|
||||
email,
|
||||
metadata: {
|
||||
saml_email: [email],
|
||||
},
|
||||
});
|
||||
|
||||
const router = httpServiceMock.createRouter();
|
||||
|
|
|
@ -6,11 +6,18 @@
|
|||
*/
|
||||
|
||||
import { IRouter } from '../../../../../src/core/server';
|
||||
import type { SecurityPluginSetup } from '../../../security/server';
|
||||
import type { SecurityPluginSetup, AuthenticatedUser } from '../../../security/server';
|
||||
import { GET_CHAT_USER_DATA_ROUTE_PATH } from '../../common/constants';
|
||||
import type { GetChatUserDataResponseBody } from '../../common/types';
|
||||
import { generateSignedJwt } from '../util/generate_jwt';
|
||||
|
||||
type MetaWithSaml = AuthenticatedUser['metadata'] & {
|
||||
saml_name: [string];
|
||||
saml_email: [string];
|
||||
saml_roles: [string];
|
||||
saml_principal: [string];
|
||||
};
|
||||
|
||||
export const registerChatRoute = ({
|
||||
router,
|
||||
chatIdentitySecret,
|
||||
|
@ -33,7 +40,9 @@ export const registerChatRoute = ({
|
|||
},
|
||||
async (_context, request, response) => {
|
||||
const user = security.authc.getCurrentUser(request);
|
||||
let { email: userEmail, username: userId } = user || {};
|
||||
const { metadata, username } = user || {};
|
||||
let userId = username;
|
||||
let [userEmail] = (metadata as MetaWithSaml)?.saml_email || [];
|
||||
|
||||
// In local development, these values are not populated. This is a workaround
|
||||
// to allow for local testing.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue