Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: use web crypto instead of cryptojs #1196

Closed
wants to merge 10 commits into from
28 changes: 15 additions & 13 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ 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, resource, skipUserInfo, extraQueryParams, extraTokenParams, disablePKCE, ...optionalParams }: SigninRequestArgs);
// (undocumented)
static create({ url, authority, client_id, redirect_uri, response_type, scope, state_data, response_mode, request_type, client_secret, nonce, resource, skipUserInfo, extraQueryParams, extraTokenParams, disablePKCE, ...optionalParams }: SigninRequestArgs): Promise<SigninRequest>;
// (undocumented)
readonly state: SigninState;
// (undocumented)
Expand Down Expand Up @@ -734,7 +735,16 @@ export type SigninSilentArgs = IFrameWindowParams & ExtraSigninRequestArgs;

// @public (undocumented)
export class SigninState extends State {
constructor(args: {
// (undocumented)
readonly authority: string;
// (undocumented)
readonly client_id: string;
// (undocumented)
readonly client_secret: string | undefined;
readonly code_challenge: string | undefined;
readonly code_verifier: string | undefined;
// (undocumented)
static create(args: {
id?: string;
data?: unknown;
created?: number;
Expand All @@ -748,19 +758,11 @@ export class SigninState extends State {
extraTokenParams?: Record<string, unknown>;
response_mode?: "query" | "fragment";
skipUserInfo?: boolean;
});
// (undocumented)
readonly authority: string;
// (undocumented)
readonly client_id: string;
// (undocumented)
readonly client_secret: string | undefined;
readonly code_challenge: string | undefined;
readonly code_verifier: string | undefined;
}): 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 Down Expand Up @@ -839,7 +841,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
35 changes: 7 additions & 28 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.1.1",
"jwt-decode": "^3.1.2"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.0",
"@testing-library/jest-dom": "^6.0.0",
"@types/crypto-js": "^4.0.2",
"@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.17.0",
Expand Down
6 changes: 3 additions & 3 deletions src/OidcClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ describe("OidcClient", () => {

it("should deserialize stored state and return state and response", async () => {
// arrange
const item = new SigninState({
const item = (await SigninState.create({
id: "1",
authority: "authority",
client_id: "client",
redirect_uri: "http://app/cb",
scope: "scope",
request_type: "type",
}).toStorageString();
})).toStorageString();
jest.spyOn(subject.settings.stateStore, "get").mockImplementation(() => Promise.resolve(item));

// act
Expand Down Expand Up @@ -314,7 +314,7 @@ describe("OidcClient", () => {

it("should deserialize stored state and call validator", async () => {
// arrange
const item = new SigninState({
const item = await SigninState.create({
id: "1",
authority: "authority",
client_id: "client",
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 @@ -114,7 +114,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 @@ -154,7 +154,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 @@ -284,7 +284,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