Skip to content

Commit

Permalink
feat: authts#4 reduce any types
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Nov 3, 2021
1 parent b3c93c6 commit 2575030
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface CreateSigninRequestArgs {
// (undocumented)
extraQueryParams?: Record<string, string | number | boolean>;
// (undocumented)
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
// (undocumented)
id_token_hint?: string;
// (undocumented)
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface CreateSigninRequestArgs {
//
// @public (undocumented)
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url" | "state_data"> & {
state?: any;
state?: unknown;
};

// @public (undocumented)
Expand Down Expand Up @@ -218,7 +218,7 @@ export interface OidcClientSettings {
display?: string;
extraQueryParams?: Record<string, string | number | boolean>;
// (undocumented)
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
filterProtocolClaims?: boolean;
loadUserInfo?: boolean;
// (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export interface CreateSigninRequestArgs {
extraQueryParams?: Record<string, string | number | boolean>;
request_type?: string;
client_secret?: string;
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
skipUserInfo?: boolean;
}

/**
* @public
*/
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url" | "state_data"> & { state?: any };
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url" | "state_data"> & { state?: unknown };

/**
* @public
Expand Down
2 changes: 1 addition & 1 deletion src/OidcClientSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface OidcClientSettings {

/** An object containing additional query string parameters to be including in the authorization request */
extraQueryParams?: Record<string, string | number | boolean>;
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
}

export class OidcClientSettingsStore {
Expand Down
2 changes: 1 addition & 1 deletion src/SigninRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface SigninRequestArgs {
extraQueryParams?: Record<string, string | number | boolean>;
request_type?: string;
client_secret?: string;
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
skipUserInfo?: boolean;

// custom "state", which can be used by a caller to have "data" round tripped
Expand Down
6 changes: 3 additions & 3 deletions src/SigninState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export class SigninState extends State {
public readonly redirect_uri: string;
public readonly scope: string;
public readonly client_secret: string | undefined;
public readonly extraTokenParams: Record<string, any> | undefined;
public readonly extraTokenParams: Record<string, unknown> | undefined;

public readonly response_mode: string | undefined;
public readonly skipUserInfo: boolean | undefined;

public constructor(args: {
id?: string;
data?: any;
data?: unknown;
created?: number;
request_type?: string;

Expand All @@ -32,7 +32,7 @@ export class SigninState extends State {
redirect_uri: string;
scope: string;
client_secret?: string;
extraTokenParams?: Record<string, any>;
extraTokenParams?: Record<string, unknown>;
response_mode?: string;
skipUserInfo?: boolean;
}) {
Expand Down
2 changes: 1 addition & 1 deletion src/SignoutRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface SignoutRequestArgs {
url: string;

// optional
state_data?: any;
state_data?: unknown;
id_token_hint?: string;
post_logout_redirect_uri?: string;
extraQueryParams?: Record<string, string | number | boolean>;
Expand Down
23 changes: 12 additions & 11 deletions test/unit/ResponseValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { UserInfoService } from "../../src/UserInfoService";
import { SigninState } from "../../src/SigninState";
import type { SigninResponse } from "../../src/SigninResponse";
import type { ErrorResponse } from "../../src/ErrorResponse";
import type { UserProfile } from "../../src/User";

// access private methods
class ResponseValidatorWrapper extends ResponseValidator {
Expand All @@ -17,10 +18,10 @@ class ResponseValidatorWrapper extends ResponseValidator {
public async _processClaims(state: SigninState, response: SigninResponse) {
return super._processClaims(state, response);
}
public _mergeClaims(claims1: any, claims2: any) {
public _mergeClaims(claims1: UserProfile, claims2: any) {
return super._mergeClaims(claims1, claims2);
}
public _filterProtocolClaims(claims: any) {
public _filterProtocolClaims(claims: UserProfile) {
return super._filterProtocolClaims(claims);
}
public _validateTokens(state: SigninState, response: SigninResponse) {
Expand Down Expand Up @@ -491,7 +492,7 @@ describe("ResponseValidator", () => {

it("should merge claims", () => {
// arrange
const c1 = { a: "apple", b: "banana" };
const c1 = { a: "apple", b: "banana" } as UserProfile;
const c2 = { c: "carrot" };

// act
Expand All @@ -503,7 +504,7 @@ describe("ResponseValidator", () => {

it("should not merge claims when claim types are objects", () => {
// arrange
const c1 = { custom: { "apple": "foo", "pear": "bar" } };
const c1 = { custom: { "apple": "foo", "pear": "bar" } } as UserProfile;
const c2 = { custom: { "apple": "foo", "orange": "peel" }, b: "banana" };

// act
Expand All @@ -517,7 +518,7 @@ describe("ResponseValidator", () => {
// arrange
settings.mergeClaims = true;

const c1 = { custom: { "apple": "foo", "pear": "bar" } };
const c1 = { custom: { "apple": "foo", "pear": "bar" } } as UserProfile;
const c2 = { custom: { "apple": "foo", "orange": "peel" }, b: "banana" };

// act
Expand All @@ -529,7 +530,7 @@ describe("ResponseValidator", () => {

it("should merge same claim types into array", () => {
// arrange
const c1 = { a: "apple", b: "banana" };
const c1 = { a: "apple", b: "banana" } as UserProfile;
const c2 = { a: "carrot" };

// act
Expand All @@ -541,7 +542,7 @@ describe("ResponseValidator", () => {

it("should merge arrays of same claim types into array", () => {
// arrange
const c1 = { a: "apple", b: "banana" };
const c1 = { a: "apple", b: "banana" } as UserProfile;
const c2 = { a: ["carrot", "durian"] };

// act
Expand All @@ -551,7 +552,7 @@ describe("ResponseValidator", () => {
expect(result).toEqual({ a: ["apple", "carrot", "durian"], b: "banana" });

// arrange
const d1 = { a: ["apple", "carrot"], b: "banana" };
const d1 = { a: ["apple", "carrot"], b: "banana" } as UserProfile;
const d2 = { a: ["durian"] };

// act
Expand All @@ -561,7 +562,7 @@ describe("ResponseValidator", () => {
expect(result).toEqual({ a: ["apple", "carrot", "durian"], b: "banana" });

// arrange
const e1 = { a: ["apple", "carrot"], b: "banana" };
const e1 = { a: ["apple", "carrot"], b: "banana" } as UserProfile;
const e2 = { a: "durian" };

// act
Expand All @@ -573,7 +574,7 @@ describe("ResponseValidator", () => {

it("should remove duplicates when producing arrays", () => {
// arrange
const c1 = { a: "apple", b: "banana" };
const c1 = { a: "apple", b: "banana" } as UserProfile;
const c2 = { a: ["apple", "durian"] };

// act
Expand All @@ -585,7 +586,7 @@ describe("ResponseValidator", () => {

it("should not add if already present in array", () => {
// arrange
const c1 = { a: ["apple", "durian"], b: "banana" };
const c1 = { a: ["apple", "durian"], b: "banana" } as UserProfile;
const c2 = { a: "apple" };

// act
Expand Down

0 comments on commit 2575030

Please sign in to comment.