Skip to content

Commit

Permalink
use SubtleCrypto digest over @oslojs/crypto for sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
runjak committed Aug 6, 2024
1 parent 7438a39 commit 2be6889
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"./package.json": "./package.json"
},
"dependencies": {
"@oslojs/crypto": "^0.6.2",
"@oslojs/encoding": "^0.4.1",
"@oslojs/oauth2": "^0.5.0",
"debug": "^4.3.4"
Expand Down
10 changes: 7 additions & 3 deletions src/lib/authorization-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* direction of the library to focus on response parsing, I decided to copy the
* old code and adapt it to the new structure of the library.
*/
import { sha256 } from "@oslojs/crypto/sha2";
import { encodeBase64urlNoPadding } from "@oslojs/encoding";

export namespace AuthorizationCode {
Expand Down Expand Up @@ -33,8 +32,13 @@ export namespace AuthorizationCode {
this.searchParams.set("state", state);
}

public setS256CodeChallenge(codeVerifier: string): void {
const codeChallengeBytes = sha256(new TextEncoder().encode(codeVerifier));
public async setS256CodeChallenge(codeVerifier: string): Promise<void> {
const codeChallengeBytes = new Uint8Array(
await crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(codeVerifier),
),
);
const codeChallenge = encodeBase64urlNoPadding(codeChallengeBytes);
this.searchParams.set("code_challenge", codeChallenge);
this.searchParams.set("code_challenge_method", "S256");
Expand Down

0 comments on commit 2be6889

Please sign in to comment.