Eliminados flujos implicit y password

This commit is contained in:
Eneko Nieto
2021-01-20 12:00:44 +01:00
parent a70f652221
commit e57906f583
16 changed files with 15 additions and 335 deletions

View File

@@ -1,31 +1,24 @@
import { noDiscoveryAuthConfig } from './auth-no-discovery.config';
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 { JwksValidationHandler } from 'angular-oauth2-oidc-jwks';
import { useHash } from '../flags';
@Component({
// tslint:disable-next-line:component-selector
selector: 'flight-app',
templateUrl: './app.component.html'
templateUrl: './app.component.html',
})
export class AppComponent {
constructor(private router: Router, private oauthService: OAuthService) {
// Remember the selected configuration
if (sessionStorage.getItem('flow') === 'code') {
this.configureCodeFlow();
} else {
this.configureImplicitFlow();
}
this.configureCodeFlow();
// Automatically load user profile
this.oauthService.events
.pipe(filter(e => e.type === 'token_received'))
.subscribe(_ => {
.pipe(filter((e) => e.type === 'token_received'))
.subscribe((_) => {
console.debug('state', this.oauthService.state);
this.oauthService.loadUserProfile();
});
@@ -33,7 +26,7 @@ export class AppComponent {
private configureCodeFlow() {
this.oauthService.configure(authCodeFlowConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(_ => {
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => {
if (useHash) {
this.router.navigate(['/']);
}
@@ -43,34 +36,6 @@ export class AppComponent {
this.oauthService.setupAutomaticSilentRefresh();
}
private configureImplicitFlow() {
this.oauthService.configure(authConfig);
this.oauthService.setStorage(localStorage);
// this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(_ => {
if (useHash) {
this.router.navigate(['/']);
}
});
// Optional
this.oauthService.setupAutomaticSilentRefresh();
// Display all events
this.oauthService.events.subscribe(e => {
// tslint:disable-next-line:no-console
console.debug('oauth/oidc event', e);
});
this.oauthService.events
.pipe(filter(e => e.type === 'session_terminated'))
.subscribe(e => {
// tslint:disable-next-line:no-console
console.debug('Your session has been terminated!');
});
}
//
// Below you find further examples for configuration functions
//
@@ -106,19 +71,19 @@ export class AppComponent {
this.oauthService.tokenValidationHandler = new NullValidationHandler();
this.oauthService.events.subscribe(e => {
this.oauthService.events.subscribe((e) => {
// tslint:disable-next-line:no-console
console.debug('oauth/oidc event', e);
});
// Load Discovery Document and then try to login the user
this.oauthService.loadDiscoveryDocument().then(doc => {
this.oauthService.loadDiscoveryDocument().then((doc) => {
this.oauthService.tryLogin();
});
this.oauthService.events
.pipe(filter(e => e.type === 'token_expires'))
.subscribe(e => {
.pipe(filter((e) => e.type === 'token_expires'))
.subscribe((e) => {
// tslint:disable-next-line:no-console
console.debug('received token_expires event', e);
this.oauthService.silentRefresh();