This commit is contained in:
Constantin Simonis 2025-03-06 11:01:59 +01:00
commit 33683f565f
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
11 changed files with 330 additions and 294 deletions

View 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();
}
}