Eneko Nieto
2021-01-18 01:07:29 +01:00
parent 63dabe3357
commit 83be283757
43 changed files with 1469 additions and 551 deletions

View File

@@ -1,10 +1,38 @@
import { authConfig } from './auth.config';
import { Component } from '@angular/core';
import { OAuthService, NullValidationHandler } from 'angular-oauth2-oidc';
import { Router } from '@angular/router';
import { filter } from 'rxjs/operators';
import { authCodeFlowConfig } from './auth-code-flow.config';
import { useHash } from '../flags';
@Component({
// tslint:disable-next-line:component-selector
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'okupamicoche-angular';
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.debug('state', this.oauthService.state);
this.oauthService.loadUserProfile();
});
}
private configureCodeFlow() {
this.oauthService.configure(authCodeFlowConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => {
if (useHash) {
this.router.navigate(['/']);
}
});
// Optional
this.oauthService.setupAutomaticSilentRefresh();
}
}