diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts index 89e4f0a1e0..42073f1f9e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth-flow.ts @@ -93,6 +93,7 @@ export class UmbAuthFlow { readonly #postLogoutRedirectUri: string; readonly #clientId: string; readonly #scope: string; + readonly #timeoutSignal; // tokens #tokenResponse?: TokenResponse; @@ -101,17 +102,19 @@ export class UmbAuthFlow { * This signal will emit when the authorization flow is complete. * @remark It will also emit if there is an error during the authorization flow. */ - authorizationSignal = new Subject(); + readonly authorizationSignal = new Subject(); constructor( openIdConnectUrl: string, redirectUri: string, postLogoutRedirectUri: string, + timeoutSignal: Subject, clientId = 'umbraco-back-office', scope = 'offline_access', ) { this.#redirectUri = redirectUri; this.#postLogoutRedirectUri = postLogoutRedirectUri; + this.#timeoutSignal = timeoutSignal; this.#clientId = clientId; this.#scope = scope; @@ -310,7 +313,8 @@ export class UmbAuthFlow { // if the refresh token is not set (maybe the provider doesn't support them) if (!this.#tokenResponse?.refreshToken) { - return Promise.resolve('Missing refreshToken.'); + this.#timeoutSignal.next(); + return Promise.reject('Missing refreshToken.'); } const request = new TokenRequest({ @@ -324,9 +328,12 @@ export class UmbAuthFlow { await this.#performTokenRequest(request); - return this.#tokenResponse - ? Promise.resolve(this.#tokenResponse.accessToken) - : Promise.reject('Missing accessToken.'); + if (!this.#tokenResponse) { + this.#timeoutSignal.next(); + return Promise.reject('Missing tokenResponse.'); + } + + return Promise.resolve(this.#tokenResponse.accessToken); } /** diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts index 3ce24cd508..f38c2d8853 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts @@ -51,7 +51,12 @@ export class UmbAuthContext extends UmbContextBase { this.#serverUrl = serverUrl; this.#backofficePath = backofficePath; - this.#authFlow = new UmbAuthFlow(serverUrl, this.getRedirectUrl(), this.getPostLogoutRedirectUrl()); + this.#authFlow = new UmbAuthFlow( + serverUrl, + this.getRedirectUrl(), + this.getPostLogoutRedirectUrl(), + this.#isTimeout, + ); // Observe the authorization signal and close the auth window this.observe(