Skip to content

Commit

Permalink
Merge pull request #775 from dbrandenstein/oidc-dynamic-redirect
Browse files Browse the repository at this point in the history
OIDC dynamic redirect
  • Loading branch information
ChristianBeilschmidt authored Feb 11, 2025
2 parents da1f5fa + bfe8b47 commit 1c00387
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@angular/platform-browser-dynamic": "^19.1.3",
"@angular/router": "^19.1.3",
"@egjs/hammerjs": "^2.0.17",
"@geoengine/openapi-client": "0.0.19",
"@geoengine/openapi-client": "0.0.20",
"codemirror": "~5.65.18",
"d3": "~7.9.0",
"dagre": "~0.8.5",
Expand Down
6 changes: 4 additions & 2 deletions projects/common/src/lib/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export class LoginComponent implements OnInit, AfterViewInit, OnDestroy {
}

ngOnInit(): void {
const redirectUri = window.location.href.replace(/\/signin$/, this.loginRedirect());

// check if OIDC login is enabled
this.userService.oidcInit().subscribe(
this.userService.oidcInit(redirectUri).subscribe(
(idr) => {
this.oidcUrl = idr.url;
this.formStatus$.next(FormStatus.Oidc);
Expand Down Expand Up @@ -98,7 +100,7 @@ export class LoginComponent implements OnInit, AfterViewInit, OnDestroy {

oidcLogin(): void {
this.formStatus$.next(FormStatus.Loading);
window.location.href = this.oidcUrl + '&redirect_url=' + window.location.href.replace(/\/signin$/, this.loginRedirect());
window.location.href = this.oidcUrl;
}

login(): void {
Expand Down
14 changes: 11 additions & 3 deletions projects/common/src/lib/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class UserService {

this.sessionInitialized = true;

if (oidcParams) {
if (oidcParams && sessionStorage.getItem('redirectUri')) {
this.oidcLogin(oidcParams)
.pipe(first())
.subscribe(() => {
Expand Down Expand Up @@ -343,8 +343,14 @@ export class UserService {
this.logoutCallback = callback;
}

oidcInit(): Observable<AuthCodeRequestURL> {
return from(new SessionApi().oidcInit());
oidcInit(redirectUri: string): Observable<AuthCodeRequestURL> {
sessionStorage.setItem('redirectUri', redirectUri);

return from(
new SessionApi().oidcInit({
redirectUri: redirectUri,
}),
);
}

oidcLogin(request: {sessionState: string; code: string; state: string}): Observable<Session> {
Expand All @@ -353,12 +359,14 @@ export class UserService {
new SessionApi()
.oidcLogin({
authCodeResponse: request,
redirectUri: sessionStorage.getItem('redirectUri')!,
})
.then((response) => {
const session = this.sessionFromDict(response);
this.session$.next(session);
result.next(session);
result.complete();
sessionStorage.removeItem('redirectUri');
})
.catch((error) => result.error(error));

Expand Down
2 changes: 1 addition & 1 deletion projects/core/src/lib/users/oidc/oidc.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class OidcComponent implements OnInit, OnDestroy {
this.pendingLoginRequest = true;
this.loginDisabled.next(true);
this.loginSubscription = this.userService
.oidcInit()
.oidcInit(window.location.href)
.pipe(
first(),
finalize(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export class LoginComponent implements OnInit, AfterViewInit, OnDestroy {
}

ngOnInit(): void {
const redirectUri = window.location.href.replace(/\/signin$/, '/dashboard');

// check if OIDC login is enabled
this.userService.oidcInit().subscribe(
this.userService.oidcInit(redirectUri).subscribe(
(idr) => {
this.oidcUrl = idr.url;
this.formStatus$.next(FormStatus.Oidc);
Expand Down
2 changes: 1 addition & 1 deletion projects/dashboards/gfbio/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class AppComponent implements OnInit, AfterViewInit {
const state = params.get('state');

let login;
if (sessionState && code && state) {
if (sessionState && code && state && sessionStorage.getItem('redirectUri')) {
login = this.userService.oidcLogin({sessionState, code, state}).pipe(first());
}

Expand Down

0 comments on commit 1c00387

Please sign in to comment.