angular-simple-oidc
Version:
Angular Library implementing Open Id Connect specification. Code Flow, Refresh Tokens, Session Management, Discovery Document.
69 lines (64 loc) • 2.29 kB
JavaScript
import { SimpleOidcError } from 'angular-simple-oidc/core';
import { Injectable } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { SimpleOidcInfoEvent, EventsService } from 'angular-simple-oidc/events';
class RequiredConfigurationMissingError extends SimpleOidcError {
constructor(context) {
super(`Required field was not present in provided configuration`, `config-required-field-missing`, context);
}
}
class NullConfigurationProvidedError extends SimpleOidcError {
constructor(context) {
super(`Null/empty configuration was provided`, `config-empty-error`, context);
}
}
class ConfigService {
constructor(events) {
this.events = events;
this.configSubject = new ReplaySubject(1);
}
get current$() {
return this.configSubject.asObservable();
}
configure(config, options = {}) {
try {
if (!config) {
throw new NullConfigurationProvidedError({ config });
}
const current = Object.assign({}, options.defaultConfig, config);
if (options.requiredFields) {
this.validateConfiguration(current, options.requiredFields);
}
this.configSubject.next(current);
this.events.dispatch(new SimpleOidcInfoEvent('Configuration obtained', current));
}
catch (e) {
// Make sure we error on the subject too
// so that subscribers can react accordingly
this.configSubject.error(e);
throw e;
}
}
validateConfiguration(config, requiredFields) {
// Fields that are not in the config aka == undefined
const invalidFields = requiredFields
.filter(field => !(field in config));
if (invalidFields.length) {
throw new RequiredConfigurationMissingError({
config,
requiredFields
});
}
}
}
ConfigService.decorators = [
{ type: Injectable }
];
ConfigService.ctorParameters = () => [
{ type: EventsService }
];
/**
* Generated bundle index. Do not edit.
*/
export { ConfigService, NullConfigurationProvidedError, RequiredConfigurationMissingError };
//# sourceMappingURL=angular-simple-oidc-config.js.map