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:
68
src/config/auth-well-known/auth-well-known-data.service.ts
Normal file
68
src/config/auth-well-known/auth-well-known-data.service.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { inject, Injectable } from 'injection-js';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { map, retry } from 'rxjs/operators';
|
||||
import { DataService } from '../../api/data.service';
|
||||
import { LoggerService } from '../../logging/logger.service';
|
||||
import { OpenIdConfiguration } from '../openid-configuration';
|
||||
import { AuthWellKnownEndpoints } from './auth-well-known-endpoints';
|
||||
|
||||
const WELL_KNOWN_SUFFIX = `/.well-known/openid-configuration`;
|
||||
|
||||
@Injectable()
|
||||
export class AuthWellKnownDataService {
|
||||
private readonly loggerService = inject(LoggerService);
|
||||
|
||||
private readonly http = inject(DataService);
|
||||
|
||||
getWellKnownEndPointsForConfig(
|
||||
config: OpenIdConfiguration
|
||||
): Observable<AuthWellKnownEndpoints> {
|
||||
const { authWellknownEndpointUrl, authWellknownEndpoints = {} } = config;
|
||||
|
||||
if (!authWellknownEndpointUrl) {
|
||||
const errorMessage = 'no authWellknownEndpoint given!';
|
||||
|
||||
this.loggerService.logError(config, errorMessage);
|
||||
|
||||
return throwError(() => new Error(errorMessage));
|
||||
}
|
||||
|
||||
return this.getWellKnownDocument(authWellknownEndpointUrl, config).pipe(
|
||||
map(
|
||||
(wellKnownEndpoints) =>
|
||||
({
|
||||
issuer: wellKnownEndpoints.issuer,
|
||||
jwksUri: wellKnownEndpoints.jwks_uri,
|
||||
authorizationEndpoint: wellKnownEndpoints.authorization_endpoint,
|
||||
tokenEndpoint: wellKnownEndpoints.token_endpoint,
|
||||
userInfoEndpoint: wellKnownEndpoints.userinfo_endpoint,
|
||||
endSessionEndpoint: wellKnownEndpoints.end_session_endpoint,
|
||||
checkSessionIframe: wellKnownEndpoints.check_session_iframe,
|
||||
revocationEndpoint: wellKnownEndpoints.revocation_endpoint,
|
||||
introspectionEndpoint: wellKnownEndpoints.introspection_endpoint,
|
||||
parEndpoint:
|
||||
wellKnownEndpoints.pushed_authorization_request_endpoint,
|
||||
} as AuthWellKnownEndpoints)
|
||||
),
|
||||
map((mappedWellKnownEndpoints) => ({
|
||||
...mappedWellKnownEndpoints,
|
||||
...authWellknownEndpoints,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
private getWellKnownDocument(
|
||||
wellKnownEndpoint: string,
|
||||
config: OpenIdConfiguration
|
||||
): Observable<any> {
|
||||
let url = wellKnownEndpoint;
|
||||
|
||||
const wellKnownSuffix = config.authWellknownUrlSuffix || WELL_KNOWN_SUFFIX;
|
||||
|
||||
if (!wellKnownEndpoint.includes(wellKnownSuffix)) {
|
||||
url = `${wellKnownEndpoint}${wellKnownSuffix}`;
|
||||
}
|
||||
|
||||
return this.http.get(url, config).pipe(retry(2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user