Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions x-pack/plugins/cloud/server/routes/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';

security.authc.getCurrentUser.mockReturnValueOnce({
username,
email,
metadata: {
saml_name: [email],
},
});

const router = httpServiceMock.createRouter();
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/cloud/server/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
*/

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];
};

export const registerChatRoute = ({
router,
chatIdentitySecret,
Expand All @@ -33,7 +37,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_name || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, based on what I'm seeing in Cloud... we need saml_email. The token is coming back, but the AWS frame is rejecting it. I'll update and redeploy to test.


// In local development, these values are not populated. This is a workaround
// to allow for local testing.
Expand Down