Skip to content

Commit

Permalink
chore: use web crypto instead of cryptojs
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Nov 9, 2023
1 parent b7266eb commit b5902c1
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 185 deletions.
69 changes: 50 additions & 19 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,12 @@ export type SigninRedirectArgs = RedirectParams & ExtraSigninRequestArgs;

// @public (undocumented)
export class SigninRequest {
constructor({ url, authority, client_id, redirect_uri, response_type, scope, state_data, response_mode, request_type, client_secret, nonce, url_state, resource, skipUserInfo, extraQueryParams, extraTokenParams, disablePKCE, ...optionalParams }: SigninRequestArgs);
constructor(args: {
url: string;
state: SigninState;
});
// (undocumented)
static create({ url, authority, client_id, redirect_uri, response_type, scope, state_data, response_mode, request_type, client_secret, nonce, url_state, resource, skipUserInfo, extraQueryParams, extraTokenParams, disablePKCE, ...optionalParams }: SigninRequestArgs): Promise<SigninRequest>;
// (undocumented)
readonly state: SigninState;
// (undocumented)
Expand Down Expand Up @@ -731,22 +736,7 @@ export type SigninSilentArgs = IFrameWindowParams & ExtraSigninRequestArgs;

// @public (undocumented)
export class SigninState extends State {
constructor(args: {
id?: string;
data?: unknown;
created?: number;
request_type?: string;
url_state?: string;
code_verifier?: string | boolean;
authority: string;
client_id: string;
redirect_uri: string;
scope: string;
client_secret?: string;
extraTokenParams?: Record<string, unknown>;
response_mode?: "query" | "fragment";
skipUserInfo?: boolean;
});
constructor(args: SigninStateArgs);
// (undocumented)
readonly authority: string;
// (undocumented)
Expand All @@ -756,9 +746,11 @@ export class SigninState extends State {
readonly code_challenge: string | undefined;
readonly code_verifier: string | undefined;
// (undocumented)
static create(args: SigninStateCreateArgs): Promise<SigninState>;
// (undocumented)
readonly extraTokenParams: Record<string, unknown> | undefined;
// (undocumented)
static fromStorageString(storageString: string): SigninState;
static fromStorageString(storageString: string): Promise<SigninState>;
// (undocumented)
readonly redirect_uri: string;
// (undocumented)
Expand All @@ -771,6 +763,45 @@ export class SigninState extends State {
toStorageString(): string;
}

// @public (undocumented)
export interface SigninStateArgs {
// (undocumented)
authority: string;
// (undocumented)
client_id: string;
// (undocumented)
client_secret?: string;
// (undocumented)
code_challenge?: string;
// (undocumented)
code_verifier?: string;
// (undocumented)
created?: number;
// (undocumented)
data?: unknown;
// (undocumented)
extraTokenParams?: Record<string, unknown>;
// (undocumented)
id?: string;
// (undocumented)
redirect_uri: string;
// (undocumented)
request_type?: string;
// (undocumented)
response_mode?: "query" | "fragment";
// (undocumented)
scope: string;
// (undocumented)
skipUserInfo?: boolean;
// (undocumented)
url_state?: string;
}

// @public (undocumented)
export type SigninStateCreateArgs = Omit<SigninStateArgs, "code_verifier"> & {
code_verifier?: string | boolean;
};

// @public (undocumented)
export type SignoutPopupArgs = PopupWindowParams & ExtraSignoutRequestArgs;

Expand Down Expand Up @@ -838,7 +869,7 @@ export class State {
readonly created: number;
readonly data?: unknown;
// (undocumented)
static fromStorageString(storageString: string): State;
static fromStorageString(storageString: string): Promise<State>;
// (undocumented)
readonly id: string;
// (undocumented)
Expand Down
33 changes: 17 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
"prepare": "husky install"
},
"dependencies": {
"crypto-js": "^4.2.0",
"jwt-decode": "^4.0.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.0",
"@testing-library/jest-dom": "^6.0.0",
"@types/crypto-js": "^4.1.3",
"@types/jest": "^29.2.3",
"@types/node": "^20.8.2",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"esbuild": "^0.19.5",
Expand Down
8 changes: 4 additions & 4 deletions src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class OidcClient {
protected readonly _tokenClient: TokenClient;

public constructor(settings: OidcClientSettings);
public constructor(settings: OidcClientSettingsStore, metadataService: MetadataService);
public constructor(settings: OidcClientSettingsStore, metadataService: MetadataService);
public constructor(settings: OidcClientSettings | OidcClientSettingsStore, metadataService?: MetadataService) {
this.settings = settings instanceof OidcClientSettingsStore ? settings : new OidcClientSettingsStore(settings);

Expand Down Expand Up @@ -115,7 +115,7 @@ export class OidcClient {
const url = await this.metadataService.getAuthorizationEndpoint();
logger.debug("Received authorization endpoint", url);

const signinRequest = new SigninRequest({
const signinRequest = await SigninRequest.create({
url,
authority: this.settings.authority,
client_id: this.settings.client_id,
Expand Down Expand Up @@ -156,7 +156,7 @@ export class OidcClient {
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

const state = SigninState.fromStorageString(storedStateString);
const state = await SigninState.fromStorageString(storedStateString);
return { state, response };
}

Expand Down Expand Up @@ -286,7 +286,7 @@ export class OidcClient {
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

const state = State.fromStorageString(storedStateString);
const state = await State.fromStorageString(storedStateString);
return { state, response };
}

Expand Down
Loading

0 comments on commit b5902c1

Please sign in to comment.