-
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: add additional dpop retry mechanisms
- Loading branch information
1 parent
668c53f
commit a102854
Showing
9 changed files
with
148 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { dpopResourceAuthenticateError, 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'); | ||
} | ||
|
||
return { ok: true, dpopNonce: dPoPNonce } as const; | ||
} | ||
|
||
return { ok: false } as const; | ||
} | ||
|
||
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; | ||
} | ||
|
||
const dPoPNonce = response.errorBody.headers.get('DPoP-Nonce'); | ||
if (!dPoPNonce) { | ||
throw new Error('The DPoP nonce was not returned'); | ||
} | ||
|
||
return { ok: true, dpopNonce: dPoPNonce } as const; | ||
} | ||
|
||
return { ok: false } as const; | ||
} |
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