File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 224224 // Import the private JWK to a CryptoKey for signing
225225 const signingKey = await jose .importJWK (privateKey, ' ES256' );
226226 // Create a minimal DPoP proof JWT (RFC 9449)
227+ // Generate SHA256 hash of the code for c_hash
228+ // Convert to BASE64URL as per spec section 1.8
229+ const codeHash = await crypto .subtle .digest (' SHA-256' , new TextEncoder ().encode (code))
230+ .then (hash => btoa (String .fromCharCode (... new Uint8Array (hash)))
231+ .replace (/ \+ / g , ' -' )
232+ .replace (/ \/ / g , ' _' )
233+ .replace (/ =/ g , ' ' ));
234+
227235 const dpopPayload = {
228- code ,
236+ c_hash : codeHash ,
229237 jti: crypto .randomUUID (),
230238 iat: Math .floor (Date .now () / 1000 ),
231239 htu: url .href ,
272280 if (! token .id_token && ! token .access_token ) throw new Error (' Did not get token' );
273281 const { payload: profile } = parseToken (token .id_token || token .access_token );
274282 if (! profile) throw new Error (' Did not get profile from token' );
283+
284+ // // Log the profile to check for cnf claim when DPoP is enabled
285+ // if (isDpopEnabled) {
286+ // console.log('DPoP enabled - checking for cnf claim in ID Token:', profile);
287+ // if (profile && typeof profile === 'object' && 'cnf' in profile) {
288+ // console.log('cnf claim found:', profile.cnf);
289+ // } else {
290+ // console.log('No cnf claim found in ID Token');
291+ // }
292+ // }
293+
275294 authzResponse .parsed = profile;
276295
277296 const userinfoRes = await fetch (new URL (' /oauth/userinfo' , authzServer), {
You can’t perform that action at this time.
0 commit comments