Skip to content

Commit a4abd9d

Browse files
committed
feat: add c_hash generation for DPoP proof JWT in App.svelte
1 parent cc77e30 commit a4abd9d

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/App.svelte

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,16 @@
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,
@@ -272,6 +280,17 @@
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), {

0 commit comments

Comments
 (0)