Skip to content

Commit

Permalink
refactor: #20 do not allow to create UserManager or OidcClient withou…
Browse files Browse the repository at this point in the history
…t settings
  • Loading branch information
pamapa committed Aug 18, 2021
1 parent 89101e7 commit e369d13
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 52 deletions.
5 changes: 0 additions & 5 deletions src/MetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ export class MetadataService {
private _metadata: Partial<OidcMetadata> | null;

constructor(settings: OidcClientSettingsStore) {
if (!settings) {
Log.error("MetadataService: No settings passed to MetadataService");
throw new Error("settings");
}

this._settings = settings;
this._jsonService = new JsonService(["application/jwk-set+json"]);

Expand Down
2 changes: 1 addition & 1 deletion src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class OidcClient {
public readonly metadataService: MetadataService;
private readonly _validator: ResponseValidator;

constructor(settings: OidcClientSettings = {}) {
constructor(settings: OidcClientSettings) {
this.settings = new OidcClientSettingsStore(settings);

this.metadataService = new MetadataService(this.settings);
Expand Down
10 changes: 5 additions & 5 deletions src/OidcClientSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DefaultClockSkewInSeconds = 60 * 5;

export interface OidcClientSettings {
/** The URL of the OIDC/OAuth2 provider */
authority?: string;
authority: string;
metadataUrl?: string;
/** Provide metadata when authority server does not allow CORS on the metadata endpoint */
metadata?: Partial<OidcMetadata>;
Expand All @@ -24,7 +24,7 @@ export interface OidcClientSettings {
signingKeys?: any[];

/** Your client application's identifier as registered with the OIDC/OAuth2 */
client_id?: string;
client_id: string;
client_secret?: string;
/** The type of response desired from the OIDC/OAuth2 provider (default: 'id_token') */
response_type?: string;
Expand Down Expand Up @@ -106,9 +106,9 @@ export class OidcClientSettingsStore {

constructor({
// metadata related
authority = "", metadataUrl, metadata, signingKeys, metadataSeed,
authority, metadataUrl, metadata, signingKeys, metadataSeed,
// client related
client_id = "", client_secret, response_type = DefaultResponseType, scope = DefaultScope,
client_id, client_secret, response_type = DefaultResponseType, scope = DefaultScope,
redirect_uri, post_logout_redirect_uri,
client_authentication = DefaultClientAuthentication,
// optional protocol
Expand All @@ -125,7 +125,7 @@ export class OidcClientSettingsStore {
// extra query params
extraQueryParams = {},
extraTokenParams = {}
}: OidcClientSettings = {}) {
}: OidcClientSettings) {

this.authority = authority;
this.metadataUrl = metadataUrl;
Expand Down
5 changes: 0 additions & 5 deletions src/ResponseValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export class ResponseValidator {
private readonly _tokenClient: TokenClient;

constructor(settings: OidcClientSettingsStore, metadataService: MetadataService) {
if (!settings) {
Log.error("ResponseValidator.ctor: No settings passed to ResponseValidator");
throw new Error("settings");
}

this._settings = settings;
this._metadataService = metadataService;
this._userInfoService = new UserInfoService(this._settings, metadataService);
Expand Down
5 changes: 0 additions & 5 deletions src/TokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export class TokenClient {
private readonly _metadataService: MetadataService;

constructor(settings: OidcClientSettingsStore, metadataService: MetadataService) {
if (!settings) {
Log.error("TokenClient.ctor: No settings passed");
throw new Error("settings");
}

this._settings = settings;
this._jsonService = new JsonService();
this._metadataService = metadataService;
Expand Down
5 changes: 0 additions & 5 deletions src/TokenRevocationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export class TokenRevocationClient {
private _metadataService: MetadataService;

constructor(settings: OidcClientSettingsStore, metadataService: MetadataService) {
if (!settings) {
Log.error("TokenRevocationClient.ctor: No settings provided");
throw new Error("No settings provided.");
}

this._settings = settings;
this._metadataService = metadataService;
}
Expand Down
5 changes: 0 additions & 5 deletions src/UserInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export class UserInfoService {
private _metadataService: MetadataService;

constructor(settings: OidcClientSettingsStore, metadataService: MetadataService) {
if (!settings) {
Log.error("UserInfoService.ctor: No settings passed");
throw new Error("settings");
}

this._settings = settings;
this._jsonService = new JsonService(undefined, this._getClaimsFromJwt.bind(this));
this._metadataService = metadataService;
Expand Down
2 changes: 1 addition & 1 deletion src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class UserManager extends OidcClient {
private readonly _tokenRevocationClient: TokenRevocationClient;
private readonly _tokenClient: TokenClient;

constructor(settings: UserManagerSettings = {}) {
constructor(settings: UserManagerSettings) {
super(settings);
this.settings = new UserManagerSettingsStore(settings);

Expand Down
2 changes: 1 addition & 1 deletion src/UserManagerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {

public readonly userStore: WebStorageStateStore;

constructor(args: UserManagerSettings = {}) {
constructor(args: UserManagerSettings) {
const {
popup_redirect_uri,
popup_post_logout_redirect_uri,
Expand Down
9 changes: 2 additions & 7 deletions test/unit/OidcClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ describe("OidcClient", () => {
});

describe("constructor", () => {

it("should allow no settings", () => {
// act
new OidcClient();
});

it("should expose settings", () => {
// assert
expect(subject.settings).not.toBeNull();
Expand All @@ -46,7 +40,8 @@ describe("OidcClient", () => {
it("should accept OidcClientSettings", () => {
// arrange
const settings = {
client_id: "client"
authority: "authority",
client_id: "client",
};

// act
Expand Down
Loading

0 comments on commit e369d13

Please sign in to comment.