deno.land / x / oauth4webapi@v1.2.2 / examples / par.diff
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152diff --git a/examples/code.ts b/examples/par.tsindex 98576c1..1cbaba2 100644--- a/examples/code.ts+++ b/examples/par.ts@@ -24,16 +24,41 @@ const code_verifier = oauth.generateRandomCodeVerifier() const code_challenge = await oauth.calculatePKCECodeChallenge(code_verifier) const code_challenge_method = 'S256' +let request_uri: string+{+ const params = new URLSearchParams()+ params.set('client_id', client.client_id)+ params.set('code_challenge', code_challenge)+ params.set('code_challenge_method', code_challenge_method)+ params.set('redirect_uri', redirect_uri)+ params.set('response_type', 'code')+ params.set('scope', 'openid email')++ const response = await oauth.pushedAuthorizationRequest(as, client, params)+ let challenges: oauth.WWWAuthenticateChallenge[] | undefined+ if ((challenges = oauth.parseWwwAuthenticateChallenges(response))) {+ for (const challenge of challenges) {+ console.log('challenge', challenge)+ }+ throw new Error() // Handle www-authenticate challenges as needed+ }++ const result = await oauth.processPushedAuthorizationResponse(as, client, response)+ if (oauth.isOAuth2Error(result)) {+ console.log('error', result)+ throw new Error() // Handle OAuth 2.0 response body error+ }++ console.log('result', result)+ ;({ request_uri } = result)+}+ { // redirect user to as.authorization_endpoint const authorizationUrl = new URL(as.authorization_endpoint!) authorizationUrl.searchParams.set('client_id', client.client_id)- authorizationUrl.searchParams.set('code_challenge', code_challenge)- authorizationUrl.searchParams.set('code_challenge_method', code_challenge_method)- authorizationUrl.searchParams.set('redirect_uri', redirect_uri)- authorizationUrl.searchParams.set('response_type', 'code')- authorizationUrl.searchParams.set('scope', 'openid email')+ authorizationUrl.searchParams.set('request_uri', request_uri) } // one eternity later, the user lands back on the redirect_uri
Version Info