Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow integration managers to validate user identity after opening #8782

Merged
merged 5 commits into from
Jun 16, 2022
Merged
Changes from 3 commits
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
20 changes: 20 additions & 0 deletions src/ScalarMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ Example:
avatar_url: null
}
}

get_open_id_token
-----------------
Get an openID token for the current user session.
Request: No parameters
Response:
- The openId token object as described in https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridopenidrequest_token
*/

import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
Expand Down Expand Up @@ -262,6 +269,7 @@ enum Action {
BotOptions = "bot_options",
SetBotOptions = "set_bot_options",
SetBotPower = "set_bot_power",
GetOpenIdToken = "get_open_id_token"
}

function sendResponse(event: MessageEvent<any>, res: any): void {
Expand Down Expand Up @@ -587,6 +595,15 @@ function returnStateEvent(event: MessageEvent<any>, roomId: string, eventType: s
sendResponse(event, stateEvent.getContent());
}

async function getOpenIdToken(event: MessageEvent<any>) {
try {
const tokenObject = MatrixClientPeg.get().getOpenIdToken();
sendResponse(event, tokenObject);
} catch (ex) {
sendError(event, 'Unable to fetch openId token.');
turt2live marked this conversation as resolved.
Show resolved Hide resolved
}
}

const onMessage = function(event: MessageEvent<any>): void {
if (!event.origin) { // stupid chrome
// @ts-ignore
Expand Down Expand Up @@ -701,6 +718,9 @@ const onMessage = function(event: MessageEvent<any>): void {
case Action.SetBotPower:
setBotPower(event, roomId, userId, event.data.level, event.data.ignoreIfGreater);
break;
case Action.GetOpenIdToken:
getOpenIdToken(event);
break;
default:
logger.warn("Unhandled postMessage event with action '" + event.data.action +"'");
break;
Expand Down