Skip to content

Commit

Permalink
Merge pull request #140 from TimoGlastra/fix/jwk-thumbprint-digest
Browse files Browse the repository at this point in the history
fix: jwk thumbprint digest
  • Loading branch information
nklomp authored Aug 3, 2024
2 parents f0ca0e7 + c9220ee commit ac29c5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/common/lib/jwt/JwkThumbprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function calculateJwkThumbprint(jwk: JWK, digestAlgorithm?: DigestA
default:
throw Error('"kty" (Key Type) Parameter missing or unsupported');
}
return u8a.toString(defaultHasher(algorithm, JSON.stringify(components)), 'base64url');
return u8a.toString(defaultHasher(JSON.stringify(components), algorithm), 'base64url');
}

export async function getDigestAlgorithmFromJwkThumbprintUri(uri: string): Promise<DigestAlgorithm> {
Expand Down
16 changes: 16 additions & 0 deletions packages/common/lib/jwt/__tests__/JwkThumbprint.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { calculateJwkThumbprint } from '../JwkThumbprint';

describe('JwkThumbprint', () => {
test('correctly calculates jwk thumbprint', async () => {
// Based on https://www.rfc-editor.org/rfc/rfc7638.html#section-3.1
expect(
await calculateJwkThumbprint({
kty: 'RSA',
n: '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw',
e: 'AQAB',
alg: 'RS256',
kid: '2011-04-29',
}),
).toEqual('NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs');
});
});

0 comments on commit ac29c5d

Please sign in to comment.