Skip to content

Commit fcbd05a

Browse files
fix: oidc redirect path for subfolders (#846)
1 parent fd77b15 commit fcbd05a

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

projects/manager/src/app/providers/provider-editor/forms/wildlive/wildlive.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {ErrorStateMatcher} from '@angular/material/core';
2424
import {toSignal} from '@angular/core/rxjs-interop';
2525
import {map, pairwise, startWith} from 'rxjs';
2626
import {MatButton} from '@angular/material/button';
27-
import {OidcPopupMessage} from 'projects/manager/src/app/oidc-popup/oidc-popup.component';
27+
import {OidcPopupMessage} from '../../../../oidc-popup/oidc-popup.component';
28+
import {oidcRedirectPath} from '../../../../util/location';
2829

2930
const nop = (): null => null;
3031

@@ -195,7 +196,8 @@ export class WildLiveComponent implements ControlValueAccessor {
195196
const orientation = window.innerWidth > window.innerHeight ? 'landscape' : 'portrait';
196197
const [popupWidth, popupHeight] = orientation === 'landscape' ? [700, 500] : [360, 660];
197198

198-
const redirectUri = `${window.location.origin}/#/oidc-popup`;
199+
const redirectUri = oidcRedirectPath(window.location, '/oidc-popup');
200+
199201
const clientId = 'geoengine';
200202
const keycloakBaseUrl = 'https://auth.geoengine.io/realms/AI4WildLIVE/protocol/openid-connect/auth';
201203

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {oidcRedirectPath} from './location';
2+
3+
const urlToLocation = (url: URL): Location =>
4+
({
5+
origin: url.origin,
6+
pathname: url.pathname,
7+
}) as Location;
8+
9+
describe('oidcRedirectPath', () => {
10+
it('should generate correct redirect URI without path', async () => {
11+
const location = urlToLocation(new URL('https://example.com'));
12+
13+
const route = '/oidc-popup';
14+
const redirectUri = oidcRedirectPath(location, route);
15+
await expect(redirectUri).toBe('https://example.com/#/oidc-popup');
16+
});
17+
18+
it('should generate correct redirect URI with path', async () => {
19+
const location = urlToLocation(new URL('https://example.com/some/path'));
20+
21+
const route = '/oidc-popup';
22+
const redirectUri = oidcRedirectPath(location, route);
23+
await expect(redirectUri).toBe('https://example.com/some/path#/oidc-popup');
24+
});
25+
26+
it('should generate correct redirect URI with path, with trailing slash', async () => {
27+
const location = urlToLocation(new URL('https://example.com/some/path/'));
28+
29+
const route = '/oidc-popup';
30+
const redirectUri = oidcRedirectPath(location, route);
31+
await expect(redirectUri).toBe('https://example.com/some/path/#/oidc-popup');
32+
});
33+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Generates a redirect URI for OIDC authentication flows.
3+
* @param route The route to append to the redirect URI.
4+
* @returns The full redirect URI including the specified route.
5+
*/
6+
export function oidcRedirectPath(location: Location, route: string): string {
7+
const IS_HASHTAG_ROUTING = true;
8+
9+
let redirectUri = location.origin;
10+
if (location.pathname) {
11+
redirectUri += location.pathname;
12+
}
13+
if (IS_HASHTAG_ROUTING) {
14+
redirectUri += `#`;
15+
}
16+
17+
redirectUri += route;
18+
19+
return redirectUri;
20+
}

0 commit comments

Comments
 (0)