-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: incorporate feedback and fix tests
- Loading branch information
1 parent
b696dba
commit c7c6af4
Showing
10 changed files
with
55 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
import { dpopResourceAuthenticateError, dpopTokenRequestNonceError } from '@sphereon/oid4vc-common'; | ||
import { dpopTokenRequestNonceError } from '@sphereon/oid4vc-common'; | ||
import { OpenIDResponse } from 'oid4vci-common'; | ||
|
||
export function dPoPShouldRetryRequestWithNonce(response: OpenIDResponse<unknown, unknown>) { | ||
if (response.errorBody && response.errorBody.error === dpopTokenRequestNonceError) { | ||
const dPoPNonce = response.errorBody.headers.get('DPoP-Nonce'); | ||
if (!dPoPNonce) { | ||
throw new Error('The DPoP nonce was not returned'); | ||
} | ||
export type RetryRequestWithDPoPNonce = { ok: true; dpopNonce: string } | { ok: false }; | ||
|
||
return { ok: true, dpopNonce: dPoPNonce } as const; | ||
export function shouldRetryTokenRequestWithDPoPNonce(response: OpenIDResponse<unknown, unknown>): RetryRequestWithDPoPNonce { | ||
if (!response.errorBody || response.errorBody.error !== dpopTokenRequestNonceError) { | ||
return { ok: false }; | ||
} | ||
|
||
return { ok: false } as const; | ||
const dPoPNonce = response.errorBody.headers.get('DPoP-Nonce'); | ||
if (!dPoPNonce) { | ||
throw new Error('Missing required DPoP-Nonce header.'); | ||
} | ||
|
||
return { ok: true, dpopNonce: dPoPNonce }; | ||
} | ||
|
||
export function dPoPShouldRetryResourceRequestWithNonce(response: OpenIDResponse<unknown, unknown>) { | ||
if (response.errorBody && response.origResponse.status === 401) { | ||
const wwwAuthenticateHeader = response.errorBody.headers?.get('WWW-Authenticate'); | ||
if (!wwwAuthenticateHeader?.includes(dpopResourceAuthenticateError)) { | ||
return { ok: false } as const; | ||
} | ||
export function shouldRetryResourceRequestWithDPoPNonce(response: OpenIDResponse<unknown, unknown>): RetryRequestWithDPoPNonce { | ||
if (!response.errorBody || response.origResponse.status !== 401) { | ||
return { ok: false }; | ||
} | ||
|
||
const dPoPNonce = response.errorBody.headers.get('DPoP-Nonce'); | ||
if (!dPoPNonce) { | ||
throw new Error('The DPoP nonce was not returned'); | ||
} | ||
const wwwAuthenticateHeader = response.errorBody.headers?.get('WWW-Authenticate'); | ||
if (!wwwAuthenticateHeader?.includes(dpopTokenRequestNonceError)) { | ||
return { ok: false }; | ||
} | ||
|
||
return { ok: true, dpopNonce: dPoPNonce } as const; | ||
const dPoPNonce = response.errorBody.headers.get('DPoP-Nonce'); | ||
if (!dPoPNonce) { | ||
throw new Error('Missing required DPoP-Nonce header.'); | ||
} | ||
|
||
return { ok: false } as const; | ||
return { ok: true, dpopNonce: dPoPNonce }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters