Skip to content

Commit 617b190

Browse files
fix(eng-10262): added correct encoding of next query parameter
1 parent ae6fc32 commit 617b190

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/app/core/services/auth.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { inject, Injectable, PLATFORM_ID } from '@angular/core';
88
import { SignUpModel } from '@core/models/sign-up.model';
99
import { ENVIRONMENT } from '@core/provider/environment.provider';
1010
import { ClearCurrentUser } from '@osf/core/store/user';
11-
import { urlParam } from '@osf/shared/helpers/url-param.helper';
11+
import { localUrlParam, urlParam } from '@osf/shared/helpers/url-param.helper';
1212
import { JsonApiService } from '@osf/shared/services/json-api.service';
1313
import { LoaderService } from '@osf/shared/services/loader.service';
1414

@@ -41,7 +41,14 @@ export class AuthService {
4141
}
4242

4343
this.loaderService.show();
44-
const loginUrl = `${this.casUrl}/login?${urlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`;
44+
let loginUrl = null;
45+
if (this.environment.webUrl.includes('localhost')) {
46+
// CAS should handle auth instead of angular, so we need to pass the next param
47+
// in the service param to ensure the user is redirected back to the correct page after login
48+
loginUrl = `${this.casUrl}/login?${localUrlParam({ service: `${this.webUrl.replace('4200', '5000')}/login`, next: window.location.href })}`;
49+
} else {
50+
loginUrl = `${this.casUrl}/login?${urlParam({ service: `${this.webUrl}/login`, next: window.location.href })}`;
51+
}
4552
window.location.href = loginUrl;
4653
}
4754

src/app/shared/helpers/url-param.helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@ export const urlParam = (params: Record<string, string>) => {
33
.map((entry) => entry.map((comp) => encodeURIComponent(comp)).join('='))
44
.join('&');
55
};
6+
7+
export const localUrlParam = (params: { service: string; next?: string }) => {
8+
const { service, next } = params;
9+
10+
// encode "next" separately because it must be encoded twice
11+
const encodedNext = next ? encodeURIComponent(next) : undefined;
12+
13+
const valueAfterService = encodedNext ? `${service}?next=${encodedNext}` : service;
14+
15+
return `service=${encodeURIComponent(valueAfterService)}`;
16+
};

0 commit comments

Comments
 (0)