Skip to content

Commit

Permalink
fix: move all crypto imports to import directly crypto not node:crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Jul 5, 2024
1 parent eca5df6 commit c7052ab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Before initializing [Part One](#part-one) of the authorization code flow, the cl
We can do this in Node using the native crypto package and a `base64urlencode` function:

```typescript
import crypto from "node:crypto";
import crypto from "crypto";

const code_verifier = crypto.randomBytes(43).toString("hex");
```
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/grants/authorization_code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ Before initializing [Part One](#part-one) of the authorization code flow, the cl
We can do this in Node using the native crypto package and a `base64urlencode` function:

```ts
import crypto from "node:crypto";
import { randomBytes } from "crypto";

const code_verifier = crypto.randomBytes(43).toString("hex");
const code_verifier = randomBytes(43).toString("hex");
```

@see [https://www.oauth.com/oauth2-servers/pkce/authorization-request/](https://www.oauth.com/oauth2-servers/pkce/authorization-request/)
Expand Down
4 changes: 2 additions & 2 deletions src/code_verifiers/S256.verifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import crypto from "node:crypto";
import { createHash } from "crypto";

import { base64urlencode } from "../utils/base64.js";
import { ICodeChallenge } from "./verifier.js";
Expand All @@ -7,7 +7,7 @@ export class S256Verifier implements ICodeChallenge {
public readonly method = "S256";

verifyCodeChallenge(codeVerifier: string, codeChallenge: string): boolean {
const codeHash = crypto.createHash("sha256").update(codeVerifier).digest();
const codeHash = createHash("sha256").update(codeVerifier).digest();
return codeChallenge === base64urlencode(codeHash);
}
}
4 changes: 2 additions & 2 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from "node:crypto";
import { randomBytes } from "crypto";

export function generateRandomToken(len = 80): string {
return crypto.randomBytes(len / 2).toString("hex");
return randomBytes(len / 2).toString("hex");
}

0 comments on commit c7052ab

Please sign in to comment.