Skip to content

Commit

Permalink
example: update fapi2-message-signing.ts to be using OpenID Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 15, 2024
1 parent d34609b commit bec0d40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
29 changes: 26 additions & 3 deletions examples/fapi2-message-signing.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/examples/fapi2.ts b/examples/fapi2-message-signing.ts
index 80ec0f4..c4b4e4f 100644
index 80ec0f4..5afce7e 100644
--- a/examples/fapi2.ts
+++ b/examples/fapi2-message-signing.ts
@@ -24,6 +24,11 @@ let DPoP!: CryptoKeyPair
Expand All @@ -25,10 +25,12 @@ index 80ec0f4..c4b4e4f 100644
{
const params = new URLSearchParams()
params.set('client_id', client.client_id)
@@ -55,6 +60,17 @@ let request_uri: string
@@ -54,7 +59,18 @@ let request_uri: string
params.set('code_challenge_method', code_challenge_method)
params.set('redirect_uri', redirect_uri)
params.set('response_type', 'code')
params.set('scope', 'api:read')
- params.set('scope', 'api:read')
+ params.set('scope', 'openid api:read')
+ params.set('response_mode', 'jwt')
+
+ request = await oauth.issueRequestObject(as, client, params, jarPrivateKey)
Expand All @@ -52,6 +54,27 @@ index 80ec0f4..c4b4e4f 100644
if (oauth.isOAuth2Error(params)) {
console.error('Error Response', params)
throw new Error() // Handle OAuth 2.0 redirect error
@@ -124,16 +140,16 @@ let access_token: string
throw new Error() // Handle WWW-Authenticate Challenges as needed
}

- const processAuthorizationCodeOAuth2Response = () =>
- oauth.processAuthorizationCodeOAuth2Response(as, client, response)
+ const processAuthorizationCodeOpenIDResponse = () =>
+ oauth.processAuthorizationCodeOpenIDResponse(as, client, response)

- let result = await processAuthorizationCodeOAuth2Response()
+ let result = await processAuthorizationCodeOpenIDResponse()
if (oauth.isOAuth2Error(result)) {
console.error('Error Response', result)
if (result.error === 'use_dpop_nonce') {
// the AS-signalled nonce is now cached, retrying
response = await authorizationCodeGrantRequest()
- result = await processAuthorizationCodeOAuth2Response()
+ result = await processAuthorizationCodeOpenIDResponse()
if (oauth.isOAuth2Error(result)) {
throw new Error() // Handle OAuth 2.0 response body error
}
@@ -142,6 +158,9 @@ let access_token: string
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/fapi2-message-signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let request: string
params.set('code_challenge_method', code_challenge_method)
params.set('redirect_uri', redirect_uri)
params.set('response_type', 'code')
params.set('scope', 'api:read')
params.set('scope', 'openid api:read')
params.set('response_mode', 'jwt')

request = await oauth.issueRequestObject(as, client, params, jarPrivateKey)
Expand Down Expand Up @@ -140,16 +140,16 @@ let access_token: string
throw new Error() // Handle WWW-Authenticate Challenges as needed
}

const processAuthorizationCodeOAuth2Response = () =>
oauth.processAuthorizationCodeOAuth2Response(as, client, response)
const processAuthorizationCodeOpenIDResponse = () =>
oauth.processAuthorizationCodeOpenIDResponse(as, client, response)

let result = await processAuthorizationCodeOAuth2Response()
let result = await processAuthorizationCodeOpenIDResponse()
if (oauth.isOAuth2Error(result)) {
console.error('Error Response', result)
if (result.error === 'use_dpop_nonce') {
// the AS-signalled nonce is now cached, retrying
response = await authorizationCodeGrantRequest()
result = await processAuthorizationCodeOAuth2Response()
result = await processAuthorizationCodeOpenIDResponse()
if (oauth.isOAuth2Error(result)) {
throw new Error() // Handle OAuth 2.0 response body error
}
Expand Down

0 comments on commit bec0d40

Please sign in to comment.