Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@
"error_occurred_login": "An error occurred during login.",
"failed_to_retrieve_suggestions": "Couldn't get translation suggestions.",
"failed_to_update_avatar": "Your avatar image could not be updated.",
"login": "Log in",
"login_expired": "Your log in has expired. Please log in again.",
"suggestion_engine_requires_retrain": "Couldn't get translation suggestions. Please retrain the suggestions on the Overview page.",
"go_to_retrain": "Go to Overview",
"try_again": "Try Again"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
});
env.localSettings.clear();
expect(env.service.currentUserRoles.length).toBe(0);
env.localSettings.set(ROLE_SETTING, SystemRole.SystemAdmin);

Check warning on line 203 in src/SIL.XForge.Scripture/ClientApp/src/xforge-common/auth.service.spec.ts

View workflow job for this annotation

GitHub Actions / Lint and Prettier (22.13.0, 11.11.0)

`ROLE_SETTING` is deprecated. This value is deprecated, but maintained to ensure compatibility with older login sessions
expect(env.service.currentUserRoles.length).toBe(1);
env.discardTokenExpiryTimer();
}));
Expand Down Expand Up @@ -524,6 +524,17 @@
mockedConsole.verify();
}));

it('should display prompt to log in again when the token grant is invalid', fakeAsync(() => {
const callback = (env: TestEnvironment): void => {
env.setInvalidGrantResponse();
mockedConsole.expectAndHide(/Unknown or invalid refresh token/);
};
const env = new TestEnvironment({ isOnline: true, isNewlyLoggedIn: true, callback });
expect(env.isLoggedIn).toBe(false);
verify(mockedWebAuth.getTokenSilently(anything())).once();
verify(mockedDialogService.message(anything(), anything())).once();
}));

it('should redirect to url after successful login', fakeAsync(() => {
const env = new TestEnvironment({
isOnline: true,
Expand Down Expand Up @@ -943,20 +954,20 @@
when(mockedWebAuth.getTokenSilently(anything())).thenResolve(this.auth0Response!.token);
}

setInvalidGrantResponse(): void {
const grantError = new GenericError('invalid_grant', 'Unknown or invalid refresh token.');
when(mockedWebAuth.getTokenSilently()).thenThrow(grantError);
when(mockedWebAuth.getTokenSilently(anything())).thenThrow(grantError);
when(mockedWebAuth.getIdTokenClaims()).thenThrow(grantError);
}

setLoginRequiredResponse(): void {
const loginError = new GenericError('login_required', 'Not logged in');
when(mockedWebAuth.getTokenSilently()).thenThrow(loginError);
when(mockedWebAuth.getTokenSilently(anything())).thenThrow(loginError);
when(mockedWebAuth.getIdTokenClaims()).thenThrow(loginError);
}

setMissingTokenResponse(): void {
const tokenError = new GenericError('missing_refresh_token', 'Invalid token');
when(mockedWebAuth.getTokenSilently()).thenThrow(tokenError);
when(mockedWebAuth.getTokenSilently(anything())).thenThrow(tokenError);
when(mockedWebAuth.getIdTokenClaims()).thenThrow(tokenError);
}

setOnline(isOnline: boolean = true): void {
this.testOnlineStatusService.setIsOnline(isOnline);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@

get currentUserRoles(): SystemRole[] {
// Provide compatibility with login session predating role array support
const role = this.localSettings.get<SystemRole | undefined>(ROLE_SETTING);

Check warning on line 142 in src/SIL.XForge.Scripture/ClientApp/src/xforge-common/auth.service.ts

View workflow job for this annotation

GitHub Actions / Lint and Prettier (22.13.0, 11.11.0)

`ROLE_SETTING` is deprecated. This value is deprecated, but maintained to ensure compatibility with older login sessions
if (role != null) {
return [role];
} else {
Expand Down Expand Up @@ -535,6 +535,14 @@

private async handleLoginError(method: string, error: unknown): Promise<void> {
console.error(error);

// Handle invalid_grant from Auth0
if (typeof error === 'object' && error !== null && 'error' in error && error.error === 'invalid_grant') {
await this.dialogService.message('error_messages.login_expired', 'error_messages.login');
return;
}

// Unknown log in error
this.reportingService.silentError(`Error occurred in ${method}`, ErrorReportingService.normalizeError(error));
await this.dialogService.message('error_messages.error_occurred_login', 'error_messages.try_again');
}
Expand Down Expand Up @@ -620,7 +628,7 @@
this.localSettings.set(ID_TOKEN_SETTING, idToken);
this.localSettings.set(EXPIRES_AT_SETTING, expiresAt);
this.localSettings.set(USER_ID_SETTING, userId);
this.localSettings.remove(ROLE_SETTING);

Check warning on line 631 in src/SIL.XForge.Scripture/ClientApp/src/xforge-common/auth.service.ts

View workflow job for this annotation

GitHub Actions / Lint and Prettier (22.13.0, 11.11.0)

`ROLE_SETTING` is deprecated. This value is deprecated, but maintained to ensure compatibility with older login sessions
this.localSettings.set(ROLES_SETTING, typeof role === 'string' ? [role] : role || []);
this.scheduleRenewal();
this.bugsnagService.leaveBreadcrumb(
Expand Down
Loading