wip
This commit is contained in:
parent
32aa753452
commit
33683f565f
11 changed files with 330 additions and 294 deletions
52
frontend/src/app/service/auth.service.ts
Normal file
52
frontend/src/app/service/auth.service.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { inject, Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { AuthConfig, OAuthService } from 'angular-oauth2-oidc';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthService {
|
||||
private readonly authConfig: AuthConfig = {
|
||||
issuer: 'https://oauth.simonis.lol/application/o/casino-dev/',
|
||||
clientId: 'MDqjm1kcWKuZfqHJXjxwAV20i44aT7m4VhhTL3Nm',
|
||||
redirectUri: window.location.origin + '/auth/callback',
|
||||
responseType: 'code',
|
||||
scope: 'openid profile email',
|
||||
showDebugInformation: true,
|
||||
oidc: true,
|
||||
requestAccessToken: true,
|
||||
};
|
||||
|
||||
private isAuthenticated = new Subject<boolean>();
|
||||
|
||||
private oauthService: OAuthService = inject(OAuthService);
|
||||
|
||||
constructor() {
|
||||
this.oauthService.configure(this.authConfig);
|
||||
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(() => {
|
||||
this.isAuthenticated.next(this.oauthService.hasValidAccessToken());
|
||||
});
|
||||
}
|
||||
|
||||
login() {
|
||||
this.oauthService.initLoginFlow();
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.oauthService.logOut();
|
||||
this.isAuthenticated.next(false);
|
||||
}
|
||||
|
||||
getAccessToken() {
|
||||
return this.oauthService.getAccessToken();
|
||||
}
|
||||
|
||||
getUserInfo() {
|
||||
return this.oauthService.loadUserProfile();
|
||||
}
|
||||
|
||||
isLoggedIn() {
|
||||
return this.oauthService.hasValidAccessToken();
|
||||
}
|
||||
}
|
Reference in a new issue