From 354d2abde62bf456c84761d3408e2a0bb4815439 Mon Sep 17 00:00:00 2001 From: flgubler-ergon <82028220+flgubler-ergon@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:11:19 +0100 Subject: [PATCH 1/2] Add initialization check for signing If the initialization is not complete when trying to sign in, the response from the identity-provider will be "lost" because no `Notifier` is registered with the @openid/appauth code. This will lead to an infinite wait for the result of the login. That is quite time-consuming to debug. Therefore, an error should make things a lot easier for the programmer. --- src/auth-service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/auth-service.ts b/src/auth-service.ts index aabce9a..097077b 100644 --- a/src/auth-service.ts +++ b/src/auth-service.ts @@ -342,6 +342,10 @@ export class AuthService implements IAuthService { } public async signIn(authExtras?: StringMap, state?: string) { + if (!this._initComplete.value) { + throw new Error('Trying to sign in before AuthService is initialized!'); + } + await this.performAuthorizationRequest(authExtras, state).catch((response) => { this.notifyActionListers(AuthActionBuilder.SignInFailed(response)); }); From f13a1ecb2065b5a371832a9db18903e465d56a51 Mon Sep 17 00:00:00 2001 From: Florian Gubler Date: Wed, 29 Jan 2025 08:32:44 +0100 Subject: [PATCH 2/2] Fixed tests: apparently _initComplete does not emit quickly enough --- src/auth-service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/auth-service.ts b/src/auth-service.ts index 097077b..0382865 100644 --- a/src/auth-service.ts +++ b/src/auth-service.ts @@ -54,6 +54,7 @@ export class AuthService implements IAuthService { private _authSubject: AuthSubject = new AuthSubject(); private _actionHistory: ActionHistoryObserver = new ActionHistoryObserver(); private _session: SessionObserver = new SessionObserver(); + private _notifier: AuthorizationNotifier | undefined = undefined; private _authSubjectV2 = new BehaviorSubject(AuthActionBuilder.Init()); private _tokenSubject = new BehaviorSubject(undefined); @@ -191,6 +192,7 @@ export class AuthService implements IAuthService { let notifier = new AuthorizationNotifier(); this.requestHandler.setAuthorizationNotifier(notifier); notifier.setAuthorizationListener((request, response, error) => this.onAuthorizationNotification(request, response, error)); + this._notifier = notifier; } protected onAuthorizationNotification( @@ -342,7 +344,7 @@ export class AuthService implements IAuthService { } public async signIn(authExtras?: StringMap, state?: string) { - if (!this._initComplete.value) { + if (!this._notifier) { throw new Error('Trying to sign in before AuthService is initialized!'); }