Allow integration managers to validate user identity after opening (#8782)
* Add getOpenIdToken function * tidy up * tidy up * log an error Co-authored-by: Travis Ralston <travisr@matrix.org>
This commit is contained in:
parent
43f2ee4283
commit
4faacdaec0
1 changed files with 21 additions and 0 deletions
|
@ -234,6 +234,13 @@ Example:
|
||||||
avatar_url: null
|
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';
|
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||||
|
@ -262,6 +269,7 @@ enum Action {
|
||||||
BotOptions = "bot_options",
|
BotOptions = "bot_options",
|
||||||
SetBotOptions = "set_bot_options",
|
SetBotOptions = "set_bot_options",
|
||||||
SetBotPower = "set_bot_power",
|
SetBotPower = "set_bot_power",
|
||||||
|
GetOpenIdToken = "get_open_id_token"
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendResponse(event: MessageEvent<any>, res: any): void {
|
function sendResponse(event: MessageEvent<any>, res: any): void {
|
||||||
|
@ -587,6 +595,16 @@ function returnStateEvent(event: MessageEvent<any>, roomId: string, eventType: s
|
||||||
sendResponse(event, stateEvent.getContent());
|
sendResponse(event, stateEvent.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getOpenIdToken(event: MessageEvent<any>) {
|
||||||
|
try {
|
||||||
|
const tokenObject = MatrixClientPeg.get().getOpenIdToken();
|
||||||
|
sendResponse(event, tokenObject);
|
||||||
|
} catch (ex) {
|
||||||
|
logger.warn("Unable to fetch openId token.", ex);
|
||||||
|
sendError(event, 'Unable to fetch openId token.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onMessage = function(event: MessageEvent<any>): void {
|
const onMessage = function(event: MessageEvent<any>): void {
|
||||||
if (!event.origin) { // stupid chrome
|
if (!event.origin) { // stupid chrome
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -701,6 +719,9 @@ const onMessage = function(event: MessageEvent<any>): void {
|
||||||
case Action.SetBotPower:
|
case Action.SetBotPower:
|
||||||
setBotPower(event, roomId, userId, event.data.level, event.data.ignoreIfGreater);
|
setBotPower(event, roomId, userId, event.data.level, event.data.ignoreIfGreater);
|
||||||
break;
|
break;
|
||||||
|
case Action.GetOpenIdToken:
|
||||||
|
getOpenIdToken(event);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logger.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
logger.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue