Files
openid-client/examples/dpop.diff
T

63 lines
1.7 KiB
Diff

diff --git a/examples/oauth.ts b/examples/dpop.ts
index dde3bbc..666c632 100644
--- a/examples/oauth.ts
+++ b/examples/dpop.ts
@@ -12,10 +12,19 @@ let clientSecret!: string
*/
let redirect_uri!: string
+/**
+ * In order to take full advantage of DPoP you shall generate a random key pair
+ * for every session. In the browser environment you shall use IndexedDB to
+ * persist the generated CryptoKeyPair.
+ */
+let DPoPKeys!: client.CryptoKeyPair
+
// End of prerequisites
let config = await client.discovery(server, clientId, clientSecret)
+let DPoP = client.getDPoPHandle(config, DPoPKeys)
+
let code_challenge_method = 'S256'
/**
* The following (code_verifier and potentially state) MUST be generated for
@@ -56,15 +65,22 @@ let state!: string
// one eternity later, the user lands back on the redirect_uri
// Authorization Code Grant
let access_token: string
+let token_type: string
{
let currentUrl: URL = getCurrentUrl()
- let tokens = await client.authorizationCodeGrant(config, currentUrl, {
- pkceCodeVerifier: code_verifier,
- expectedState: state,
- })
+ let tokens = await client.authorizationCodeGrant(
+ config,
+ currentUrl,
+ {
+ pkceCodeVerifier: code_verifier,
+ expectedState: state,
+ },
+ undefined,
+ { DPoP },
+ )
console.log('Token Endpoint Response', tokens)
- ;({ access_token } = tokens)
+ ;({ access_token, token_type } = tokens)
}
// Protected Resource Request
@@ -74,6 +90,9 @@ let access_token: string
access_token,
new URL('https://rs.example.com/api'),
'GET',
+ undefined,
+ undefined,
+ token_type === 'dpop' ? { DPoP } : undefined,
)
console.log('Protected Resource Response', await protectedResource.json())