Added OAuth sample code: https://github.com/manfredsteyer/angular-oauth2-oidc/tree/master/projects/sample
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user