Skip to content

Commit

Permalink
feat(Login): When SCORE SSO is enabled, show SCORE login in a popup w…
Browse files Browse the repository at this point in the history
…indow

#565
  • Loading branch information
geoffreykwan committed Sep 6, 2023
1 parent 6a72b95 commit 1f42f74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions frontend/src/app/guards/sso.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class SsoGuard implements CanActivate {
_state: RouterStateSnapshot
) {
if (this.userService.loggedIn) {
if (window.opener != null) {
window.opener.postMessage('loadAttemptedUrl', '*');
}
return true;
} else {
if (await this.userService.isSsoEnabled()) {
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import User, { AuthUser, TokenResponse } from '../models/user';
})
export class UserService {
redirectUrl: string | null = null;
signInWindow: any;

constructor(private http: HttpClient) {}

Expand Down Expand Up @@ -59,15 +60,33 @@ export class UserService {
}

async trySsoLogin(attemptedUrl: string): Promise<any> {
this.addLoadAttemptedUrlListener(attemptedUrl);
return this.http
.get('auth/sso/handshake')
.toPromise()
.then((response: any) => {
window.location.href = `${response.scoreSsoEndpoint}?sig=${response.sig}&sso=${response.sso}&redirectUrl=${attemptedUrl}`;
this.openSignInWindow(response, attemptedUrl);
return false;
});
}

addLoadAttemptedUrlListener(attemptedUrl: string): void {
window.addEventListener('message', (event) => {
if (event.data === 'loadAttemptedUrl') {
window.location.href = attemptedUrl;
this.signInWindow.close();
}
});
}

openSignInWindow(response: any, attemptedUrl: string): void {
const ssoEndpoint =
response.scoreSsoEndpoint +
`?sig=${response.sig}&sso=${response.sso}&redirectUrl=${attemptedUrl}`;
const params = 'width=800,height=600';
this.signInWindow = window.open(ssoEndpoint, 'SCORE Login Window', params);
}

async ssoLogin(sso: string | null, sig: string | null): Promise<boolean> {
return this.http
.get(`auth/sso/login/${sso}/${sig}`)
Expand Down

0 comments on commit 1f42f74

Please sign in to comment.