Skip to content

Commit

Permalink
Fix OIDC redirection httpparams catch
Browse files Browse the repository at this point in the history
  • Loading branch information
fredx30 committed Mar 3, 2022
1 parent 3d9f40f commit c4c574a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
18 changes: 16 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';

@Component({
selector: 'wh-app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
export class AppComponent implements OnInit{
title = 'wharf';

constructor(
private oidcSecurityService: OidcSecurityService,
) {
}

ngOnInit() {
// The method checkAuth() is needed to process the redirect from your Security Token Service and set the
// correct states. This method must be used to ensure the correct functioning of the library.
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, accessToken, idToken }) => {
console.warn('Authenticated: ', isAuthenticated);
});
}
}
2 changes: 1 addition & 1 deletion src/app/auth/auth-config.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import {
AuthModule,
AuthModule, OidcSecurityService,
StsConfigHttpLoader,
StsConfigLoader,
} from 'angular-auth-oidc-client';
Expand Down
6 changes: 4 additions & 2 deletions src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RouterModule } from '@angular/router';
import { filter } from 'rxjs/operators';
import { DialogModule } from 'primeng/dialog';
import { ButtonModule } from 'primeng/button';
import { EventTypes, PublicEventsService } from 'angular-auth-oidc-client';
import { EventTypes, OidcSecurityService, PublicEventsService } from 'angular-auth-oidc-client';
import { AuthConfigModule } from './auth-config.module';
import { ForbiddenComponent } from './forbidden/forbidden.component';
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
Expand All @@ -27,7 +27,9 @@ import { CardModule } from 'primeng/card';
],
})
export class AuthModule {
constructor(private readonly eventService: PublicEventsService) {
constructor(
private readonly eventService: PublicEventsService,
) {
this.eventService
.registerForEvents()
.pipe(filter((notification) => notification.type === EventTypes.ConfigLoaded))
Expand Down
4 changes: 2 additions & 2 deletions src/app/auth/login/login.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!-- From https://github.com/damienbod/angular-auth-oidc-client/tree/main/projects/sample-code-flow-refresh-tokens/src/app -->
<div *ngIf="isAuthenticated; else noAuth">
<div *ngIf="isAuthenticated$|async; else noAuth">
<p-button (click)="logout()">Logout</p-button>
<p-button (click)="logoffAndRevokeTokens()">Logout and revoke tokens</p-button>
<p-button (click)="revokeAccessToken()">Revoke access token</p-button>
<p-button (click)="revokeRefreshToken()">Revoke refresh token</p-button>
<p-button (click)="refreshSession()">Refresh session</p-button>
<hr />
<br />
Is Authenticated: {{ isAuthenticated }}
Is Authenticated: {{ isAuthenticated$|async }}
<br />
userData
<pre>{{ userData$ | async | json }}</pre>
Expand Down
11 changes: 4 additions & 7 deletions src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, OnInit } from '@angular/core';
import {
AuthenticatedResult,
OidcSecurityService,
OpenIdConfiguration,
UserDataResult,
} from 'angular-auth-oidc-client';
import { Observable } from 'rxjs';
import { Observable, pluck } from 'rxjs';

/*
* Largely from damienbod/angular-auth-oidc-client samples. See-
Expand All @@ -19,7 +20,7 @@ export class LoginComponent implements OnInit {

configuration: OpenIdConfiguration;
userData$: Observable<UserDataResult>;
isAuthenticated = false;
isAuthenticated$: Observable<boolean>;

constructor(
public oidcSecurityService: OidcSecurityService,
Expand All @@ -28,11 +29,7 @@ export class LoginComponent implements OnInit {
ngOnInit() {
this.configuration = this.oidcSecurityService.getConfiguration();
this.userData$ = this.oidcSecurityService.userData$;

this.oidcSecurityService.isAuthenticated$.subscribe(({ isAuthenticated }) => {
this.isAuthenticated = isAuthenticated;
console.warn('authenticated: ', isAuthenticated);
});
this.isAuthenticated$ = this.oidcSecurityService.isAuthenticated$.pipe(pluck('isAuthenticated'));
}

login() {
Expand Down
3 changes: 0 additions & 3 deletions src/app/shared/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ export class ConfigService {
public getOidcConfig$(): Observable<OpenIdConfiguration> {
return this.getConfig$().pipe(
map<Config,OpenIdConfiguration>((configuration: Config) => configuration.oidcConfig),
tap(configuration => {
debugger;
}),
);
}

Expand Down

0 comments on commit c4c574a

Please sign in to comment.