oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
52 lines (51 loc) • 2.84 kB
JavaScript
import { Injectable, inject } from "injection-js";
import { throwError } from "rxjs";
import { map, retry } from "rxjs/operators";
import { DataService } from "../../api/data.service.js";
import { LoggerService } from "../../logging/logger.service.js";
function _ts_decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
const WELL_KNOWN_SUFFIX = "/.well-known/openid-configuration";
class AuthWellKnownDataService {
getWellKnownEndPointsForConfig(config) {
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
})), map((mappedWellKnownEndpoints)=>({
...mappedWellKnownEndpoints,
...authWellknownEndpoints
})));
}
getWellKnownDocument(wellKnownEndpoint, config) {
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));
}
constructor(){
this.loggerService = inject(LoggerService);
this.http = inject(DataService);
}
}
AuthWellKnownDataService = _ts_decorate([
Injectable()
], AuthWellKnownDataService);
export { AuthWellKnownDataService };