This commit is contained in:
csimonis 2025-03-12 14:45:40 +01:00 committed by Constantin Simonis
parent 144f033beb
commit e848b548b5
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
7 changed files with 65 additions and 25 deletions

View file

@ -15,6 +15,6 @@ export default class LoginSuccessComponent implements OnInit {
private router: Router = inject(Router);
private authService: AuthService = inject(AuthService);
async ngOnInit() {
this.authService.getUserInfo()
console.log(this.authService.getAccessToken());
}
}

View file

@ -13,9 +13,6 @@ export class AuthService {
private readonly authConfig: AuthConfig = {
issuer: 'https://oauth.simonis.lol/application/o/casino-dev/',
loginUrl: 'https://oauth.simonis.lol/application/o/authorize/',
tokenEndpoint: 'https://oauth.simonis.lol/application/o/token/',
userinfoEndpoint: 'https://oauth.simonis.lol/application/o/userinfo/',
clientId: 'MDqjm1kcWKuZfqHJXjxwAV20i44aT7m4VhhTL3Nm',
dummyClientSecret: 'GY2F8te6iAVYt1TNAUVLzWZEXb6JoMNp6chbjqaXNq4gS5xTDL54HqBiAlV1jFKarN28LQ7FUsYX4SbwjfEhZhgeoKuBnZKjR9eiu7RawnGgxIK9ffvUfMkjRxnmiGI5',
scope: 'openid profile email',
@ -25,6 +22,8 @@ export class AuthService {
requestAccessToken: true,
strictDiscoveryDocumentValidation: false,
showDebugInformation: true,
skipIssuerCheck: true,
disableAtHashCheck: true,
};
private isAuthenticated = new Subject<boolean>();
@ -32,9 +31,11 @@ export class AuthService {
private oauthService: OAuthService = inject(OAuthService);
constructor() {
this.oauthService.setStorage(localStorage);
this.oauthService.configure(this.authConfig);
this.oauthService.events.subscribe((event) => {
if (event.type === 'token_received') {
localStorage.setItem('jwt', this.getAccessToken());
this.oauthService.loadUserProfile().then((profile) => {
this.fromUserProfile(profile).subscribe((user) => {
this.user = user;
@ -56,10 +57,6 @@ export class AuthService {
this.isAuthenticated.next(false);
}
getUserInfo() {
return this.user;
}
isLoggedIn() {
return this.oauthService.hasValidAccessToken();
}

View file

@ -1,9 +1,9 @@
import { HttpInterceptorFn } from '@angular/common/http';
import { inject } from '@angular/core';
import { AuthService } from '../../service/auth.service';
export const httpInterceptor: HttpInterceptorFn = (req, next) => {
return next(req.clone({
setHeaders: {'Authorization': 'Bearer '+inject(AuthService).getAccessToken()},
}));
if (localStorage.getItem('jwt')) {
return next(req.clone({ setHeaders: { 'Authorization': 'Bearer ' + localStorage.getItem('jwt') } }));
} else {
return next(req);
}
};