- Prihlásenie
+ Prihlásiť sa
diff --git a/Web/src/app/services/authentication.service.ts b/Web/src/app/services/authentication.service.ts
index a9be0c6..8bf4c06 100644
--- a/Web/src/app/services/authentication.service.ts
+++ b/Web/src/app/services/authentication.service.ts
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
+import { Router } from '@angular/router';
import { AuthConfig, OAuthService } from 'angular-oauth2-oidc';
const CONFIG_KEY = 'oauth_config_v1';
@@ -17,7 +18,7 @@ export class AuthenticationService {
public profile: any = null;
- constructor(private oauthService: OAuthService) { }
+ constructor(private oauthService: OAuthService, private router: Router) { }
saveConfig(cfg: Partial
) {
try {
@@ -52,7 +53,7 @@ export class AuthenticationService {
// Restore configuration from storage and apply to OAuthService
restoreConfiguration(): boolean {
const cfg = this.loadConfig() ?? this.config;
- if (!cfg) return false;
+ if (!cfg.issuer) return false;
this.oauthService.configure(cfg);
return true;
}
@@ -70,16 +71,18 @@ export class AuthenticationService {
// Call this on the callback route to process the redirect and obtain tokens + profile
handleCallback(): Promise {
- this.restoreConfiguration();
- // Ensure discovery document loaded, then process code flow, then load profile
- return this.oauthService
- .loadDiscoveryDocumentAndTryLogin()
- .then((isLoggedIn: boolean) => {
- if (!isLoggedIn && !this.oauthService.hasValidAccessToken()) {
- return Promise.reject('No valid token after callback');
- }
- return this.loadUserProfile();
- });
+ if (this.restoreConfiguration())
+ // Ensure discovery document loaded, then process code flow, then load profile
+ return this.oauthService
+ .loadDiscoveryDocumentAndTryLogin()
+ .then((isLoggedIn: boolean) => {
+ if (!isLoggedIn && !this.oauthService.hasValidAccessToken()) {
+ return Promise.reject('No valid token after callback');
+ }
+ return this.loadUserProfile();
+ });
+ else
+ return this.router.navigate(['/authentication/login']);
}
loadUserProfile(): Promise {