diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index b51cb58b9..be9b1f27c 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -8,7 +8,7 @@ import { inject, Injectable, PLATFORM_ID } from '@angular/core'; import { SignUpModel } from '@core/models/sign-up.model'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { ClearCurrentUser } from '@osf/core/store/user'; -import { urlParam } from '@osf/shared/helpers/url-param.helper'; +import { doubleEncodedUrlParam, urlParam } from '@osf/shared/helpers/url-param.helper'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { LoaderService } from '@osf/shared/services/loader.service'; @@ -41,7 +41,7 @@ export class AuthService { } this.loaderService.show(); - const loginUrl = `${this.casUrl}/login?${urlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`; + const loginUrl = `${this.casUrl}/login?${doubleEncodedUrlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`; window.location.href = loginUrl; } diff --git a/src/app/shared/helpers/url-param.helper.ts b/src/app/shared/helpers/url-param.helper.ts index 02e7e98c8..7d214aee3 100644 --- a/src/app/shared/helpers/url-param.helper.ts +++ b/src/app/shared/helpers/url-param.helper.ts @@ -3,3 +3,15 @@ export const urlParam = (params: Record) => { .map((entry) => entry.map((comp) => encodeURIComponent(comp)).join('=')) .join('&'); }; + +export const doubleEncodedUrlParam = (params: { service: string; next?: string }): string => { + const { service, next } = params; + + if (!next) { + return `service=${encodeURIComponent(service)}`; + } + + const encodedNext = encodeURIComponent(next); + const valueAfterService = `${service}?next=${encodedNext}`; + return `service=${encodeURIComponent(valueAfterService)}`; +};