Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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