diff --git a/web/app/shared/services/scalar/scalar-widget.api.ts b/web/app/shared/services/scalar/scalar-widget.api.ts index 3267145..5897344 100644 --- a/web/app/shared/services/scalar/scalar-widget.api.ts +++ b/web/app/shared/services/scalar/scalar-widget.api.ts @@ -88,6 +88,10 @@ export class ScalarWidgetApi { ScalarWidgetApi.callAction("get_openid", {}); } + public static requestSupportedVersions(): void { + ScalarWidgetApi.callAction("supported_api_versions", {}); + } + private static callAction(action, payload) { if (!window.opener) { return; diff --git a/web/app/widget-wrappers/reauth-example/reauth-example.component.ts b/web/app/widget-wrappers/reauth-example/reauth-example.component.ts index dcdd98d..2a9851f 100644 --- a/web/app/widget-wrappers/reauth-example/reauth-example.component.ts +++ b/web/app/widget-wrappers/reauth-example/reauth-example.component.ts @@ -14,12 +14,12 @@ import { FE_ScalarOpenIdRequestBody } from "../../shared/models/scalar-server-re }) export class ReauthExampleWidgetWrapperComponent extends CapableWidget implements OnInit, OnDestroy { - public busy = false; + public busy = true; // busy until we load supported versions public hasOpenId = false; public userId: string; public blocked = false; public error = false; - public stateMessage = ""; + public stateMessage = "Checking client version..."; private widgetReplySubscription: Subscription; private widgetRequestSubscription: Subscription; @@ -38,14 +38,30 @@ export class ReauthExampleWidgetWrapperComponent extends CapableWidget implement } public ngOnInit(): void { - // TODO: Check that the client supports this (API version 0.0.2 at least) - super.ngOnInit(); this.widgetReplySubscription = ScalarWidgetApi.replyReceived.subscribe(async response => { - if (response.action !== "get_openid") return; - const data = response.response; + if (response.action === "supported_api_versions") { + if (!data || !data.supported_versions) { + this.stateMessage = "Invalid API version response"; + this.changeDetector.detectChanges(); + return; + } + + if (data.supported_versions.indexOf("0.0.2") === -1) { + this.stateMessage = "Your client is not supported by this widget."; + this.changeDetector.detectChanges(); + return; + } + + this.busy = false; + this.changeDetector.detectChanges(); + return; + } + + if (response.action !== "get_openid") return; + try { if (data.state === "request") { this.stateMessage = "Waiting for you to accept the prompt..."; @@ -96,6 +112,13 @@ export class ReauthExampleWidgetWrapperComponent extends CapableWidget implement if (this.widgetRequestSubscription) this.widgetRequestSubscription.unsubscribe(); } + protected onCapabilitiesSent(): void { + super.onCapabilitiesSent(); + + // Start a request for supported API versions + ScalarWidgetApi.requestSupportedVersions(); + } + public onReauthStart(): void { this.busy = true; this.error = false;