Skip to content

Commit

Permalink
Add pbkdf_2 support to passwords.migrate (#231)
Browse files Browse the repository at this point in the history
* Add pbkdf_2 support to passwords.migrate

- Adds support for pbkdf_2 password hashes to the passwords.migrate
  command

* 7.2.0

---------

Co-authored-by: Logan Gore <[email protected]>
  • Loading branch information
oldmantaiter and logan-stytch authored Jun 29, 2023
1 parent 2f30ec3 commit 558fbc9
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/b2b/passwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export type B2BPasswordsMigrateRequest =
| (shared.Argon2IDMigrateRequest & MigrateRequestBase)
| (shared.SHA1MigrateRequest & MigrateRequestBase)
| (shared.ScryptMigrateRequest & MigrateRequestBase)
| (shared.PHPassMigrateRequest & MigrateRequestBase);
| (shared.PHPassMigrateRequest & MigrateRequestBase)
| (shared.PBKDF2MigrateRequest & MigrateRequestBase);

export interface B2BPasswordsMigrateResponse extends ResponseWithMember {
organization_id: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/b2c/passwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export type B2CPasswordsMigrateRequest =
| (shared.Argon2IDMigrateRequest & MigrateRequestBase)
| (shared.SHA1MigrateRequest & MigrateRequestBase)
| (shared.ScryptMigrateRequest & MigrateRequestBase)
| (shared.PHPassMigrateRequest & MigrateRequestBase);
| (shared.PHPassMigrateRequest & MigrateRequestBase)
| (shared.PBKDF2MigrateRequest & MigrateRequestBase);

export interface B2CPasswordsMigrateResponse extends BaseResponse {
user_id: string;
Expand Down
9 changes: 9 additions & 0 deletions lib/shared/passwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ export interface ScryptMigrateRequest {
key_length: number;
};
}

export interface PBKDF2MigrateRequest {
hash_type: "pbkdf_2";
pbkdf_2_config?: {
salt: string;
iteration_amount: number;
key_length: number;
};
}
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stytch",
"version": "7.1.3",
"version": "7.2.0",
"description": "A wrapper for the Stytch API",
"types": "./types/lib/index.d.ts",
"main": "./dist/index.js",
Expand Down
29 changes: 29 additions & 0 deletions test/b2b/passwords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,5 +487,34 @@ describe("passwords.migrate", () => {
},
params: undefined,
});
}),
test("pbkdf_2", () => {
return expect(
passwords.migrate({
organization_id: "organization-id-1234",
email_address: "[email protected]",
hash_type: "pbkdf_2",
hash: "not-a-real-password-hash",
pbkdf_2_config: {
salt: "not-a-real-salt",
iteration_amount: 10000,
key_length: 32,
},
})
).resolves.toMatchObject({
method: "POST",
path: "passwords/migrate",
data: {
organization_id: "organization-id-1234",
email_address: "[email protected]",
hash_type: "pbkdf_2",
hash: "not-a-real-password-hash",
pbkdf_2_config: {
salt: "not-a-real-salt",
iteration_amount: 10000,
key_length: 32,
},
},
});
});
});
27 changes: 27 additions & 0 deletions test/b2c/password.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,32 @@ describe("passwords.migrate", () => {
},
},
});
}),
test("pbkdf_2", () => {
return expect(
passwords.migrate({
email: "[email protected]",
hash_type: "pbkdf_2",
hash: "not-a-real-password-hash",
pbkdf_2_config: {
salt: "not-a-real-salt",
iteration_amount: 10000,
key_length: 32,
},
})
).resolves.toMatchObject({
method: "POST",
path: "passwords/migrate",
data: {
email: "[email protected]",
hash_type: "pbkdf_2",
hash: "not-a-real-password-hash",
pbkdf_2_config: {
salt: "not-a-real-salt",
iteration_amount: 10000,
key_length: 32,
},
},
});
});
});
2 changes: 1 addition & 1 deletion types/lib/b2b/passwords.d.ts

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

2 changes: 1 addition & 1 deletion types/lib/b2c/passwords.d.ts

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

8 changes: 8 additions & 0 deletions types/lib/shared/passwords.d.ts

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

0 comments on commit 558fbc9

Please sign in to comment.