Files
Okupa_mi_coche_-_Angular/src/app/app.component.ts
2021-01-21 01:14:17 +01:00

40 lines
1.1 KiB
TypeScript

import { Component } from '@angular/core';
import { OAuthService, NullValidationHandler } from 'angular-oauth2-oidc';
import { Router } from '@angular/router';
import { filter } from 'rxjs/operators';
import { authConfig } from './auth.config';
import { useHash } from '../flags';
@Component({
// tslint:disable-next-line:component-selector
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
constructor(private router: Router, private oauthService: OAuthService) {
this.configureCodeFlow();
// Automatically load user profile
this.oauthService.events
.pipe(filter((e) => e.type === 'token_received'))
.subscribe((_) => {
console.log('state', this.oauthService.state);
this.oauthService.loadUserProfile();
});
}
private configureCodeFlow(): void {
this.oauthService.configure(authConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => {
if (useHash) {
this.router.navigate(['/']);
}
});
// Optional
if (authConfig.useSilentRefresh) {
this.oauthService.setupAutomaticSilentRefresh();
}
}
}