feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
This commit is contained in:
55
src/callback/implicit-flow-callback.service.ts
Normal file
55
src/callback/implicit-flow-callback.service.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { inject, Injectable } from 'injection-js';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError, tap } from 'rxjs/operators';
|
||||
import { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
import { CallbackContext } from '../flows/callback-context';
|
||||
import { FlowsDataService } from '../flows/flows-data.service';
|
||||
import { FlowsService } from '../flows/flows.service';
|
||||
import { IntervalService } from './interval.service';
|
||||
|
||||
@Injectable()
|
||||
export class ImplicitFlowCallbackService {
|
||||
private readonly flowsService = inject(FlowsService);
|
||||
|
||||
private readonly router = inject(Router);
|
||||
|
||||
private readonly flowsDataService = inject(FlowsDataService);
|
||||
|
||||
private readonly intervalService = inject(IntervalService);
|
||||
|
||||
authenticatedImplicitFlowCallback(
|
||||
config: OpenIdConfiguration,
|
||||
allConfigs: OpenIdConfiguration[],
|
||||
hash?: string
|
||||
): Observable<CallbackContext> {
|
||||
const isRenewProcess = this.flowsDataService.isSilentRenewRunning(config);
|
||||
const triggerAuthorizationResultEvent = Boolean(
|
||||
config.triggerAuthorizationResultEvent
|
||||
);
|
||||
const postLoginRoute = config.postLoginRoute ?? '';
|
||||
const unauthorizedRoute = config.unauthorizedRoute ?? '';
|
||||
|
||||
return this.flowsService
|
||||
.processImplicitFlowCallback(config, allConfigs, hash)
|
||||
.pipe(
|
||||
tap((callbackContext) => {
|
||||
if (
|
||||
!triggerAuthorizationResultEvent &&
|
||||
!callbackContext.isRenewProcess
|
||||
) {
|
||||
this.router.navigateByUrl(postLoginRoute);
|
||||
}
|
||||
}),
|
||||
catchError((error) => {
|
||||
this.flowsDataService.resetSilentRenewRunning(config);
|
||||
this.intervalService.stopPeriodicTokenCheck();
|
||||
if (!triggerAuthorizationResultEvent && !isRenewProcess) {
|
||||
this.router.navigateByUrl(unauthorizedRoute);
|
||||
}
|
||||
|
||||
return throwError(() => new Error(error));
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user