Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/AuthorizationCodeGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const redirectForLogin = async (idp: string, redirect_uri: string, client_detail
sessionStorage.setItem("pkce_code_verifier", pkce_code_verifier);

// RFC 6749 OAuth 2.0 - CSRF token
const csrf_token = window.crypto.randomUUID();
const csrf_token = globalThis.crypto.randomUUID();
sessionStorage.setItem("csrf_token", csrf_token);

// redirect to idp
Expand All @@ -99,10 +99,10 @@ const redirectForLogin = async (idp: string, redirect_uri: string, client_detail
const getPKCEcode = async () => {
// create random string as PKCE code verifier
const pkce_code_verifier =
window.crypto.randomUUID() + "-" + window.crypto.randomUUID();
globalThis.crypto.randomUUID() + "-" + globalThis.crypto.randomUUID();
// hash the verifier and base64URL encode as PKCE code challenge
const digest = new Uint8Array(
await window.crypto.subtle.digest(
await globalThis.crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(pkce_code_verifier)
)
Expand Down Expand Up @@ -277,7 +277,7 @@ const requestAccessToken = async (
htm: "POST",
})
.setIssuedAt()
.setJti(window.crypto.randomUUID())
.setJti(globalThis.crypto.randomUUID())
.setProtectedHeader({
alg: "ES256",
typ: "dpop+jwt",
Expand Down
2 changes: 1 addition & 1 deletion src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class SessionCore extends EventTarget implements Session {
);
return new SignJWT(payload)
.setIssuedAt()
.setJti(window.crypto.randomUUID())
.setJti(globalThis.crypto.randomUUID())
.setProtectedHeader({
alg: "ES256",
typ: "dpop+jwt",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('SessionCore', () => {
(session as any).information = { ...mockSessionInfo };
(session as any).information.clientDetails.client_id = client_id;

// 2. Mock the internal _computeAth method, as it depends on `window.crypto`
// 2. Mock the internal _computeAth method, as it depends on `globalThis.crypto`
// which is not available in the JSDOM test environment.
const computeAthSpy = jest.spyOn(session as any, '_computeAth')
.mockResolvedValueOnce('mock-ath-value');
Expand Down