Skip to content

Commit 3cbe37a

Browse files
committed
chore: client assertion improvements
1 parent b857c5c commit 3cbe37a

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

packages/client/lib/functions/AccessTokenUtil.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const createJwtBearerClientAssertion = async (
1111
): Promise<void> => {
1212
const { asOpts, credentialIssuer } = opts;
1313
if (asOpts?.clientOpts?.clientAssertionType === 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer') {
14-
const { kid, clientId = request.client_id, signCallbacks, alg } = asOpts.clientOpts;
14+
const { clientId = request.client_id, signCallbacks, alg } = asOpts.clientOpts;
15+
let { kid } = asOpts.clientOpts;
1516
if (!clientId) {
1617
return Promise.reject(Error(`Not client_id supplied, but client-assertion jwt-bearer requested.`));
1718
} else if (!kid) {
@@ -21,10 +22,13 @@ export const createJwtBearerClientAssertion = async (
2122
} else if (!credentialIssuer) {
2223
return Promise.reject(Error(`No credential issuer supplied, but client-assertion jwt-bearer requested.`));
2324
}
25+
if (clientId.startsWith('http') && kid.includes('#')) {
26+
kid = kid.split('#')[1];
27+
}
2428
const jwt: Jwt = {
2529
header: {
2630
typ: 'JWT',
27-
kid: kid,
31+
kid,
2832
alg: alg ?? 'ES256',
2933
},
3034
payload: {

packages/common/lib/functions/ProofUtil.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export const createProofOfPossession = async <DIDDoc>(
4747
throw new Error(BAD_PARAMS);
4848
}
4949

50-
const signerArgs = createJWT(popMode, jwtProps, existingJwt);
51-
const jwt = await callbacks.signCallback(signerArgs, signerArgs.header.kid);
50+
const jwtPayload = createJWT(popMode, jwtProps, existingJwt);
51+
const jwt = await callbacks.signCallback(jwtPayload, jwtPayload.header.kid);
5252
const proof = {
5353
proof_type: 'JWT',
5454
jwt,
@@ -58,7 +58,7 @@ export const createProofOfPossession = async <DIDDoc>(
5858
partiallyValidateJWS(jwt);
5959
if (callbacks.verifyCallback) {
6060
debug(`Calling supplied verify callback....`);
61-
await callbacks.verifyCallback({ jwt, kid: signerArgs.header.kid });
61+
await callbacks.verifyCallback({ jwt, kid: jwtPayload.header.kid });
6262
debug(`Supplied verify callback return success result`);
6363
}
6464
} catch {
@@ -130,9 +130,9 @@ const createJWT = (mode: PoPMode, jwtProps?: JwtProps, existingJwt?: Jwt): Jwt =
130130
? getJwtProperty<string | string[]>('aud', true, jwtProps?.issuer, existingJwt?.payload?.aud)
131131
: getJwtProperty<string | string[]>('aud', false, jwtProps?.aud, existingJwt?.payload?.aud);
132132
const iss =
133-
// mode === 'pop'
134-
getJwtProperty<string>('iss', false, jwtProps?.clientId, existingJwt?.payload?.iss);
135-
// : getJwtProperty<string>('iss', false, jwtProps?.issuer, existingJwt?.payload?.iss);
133+
mode === 'pop'
134+
? getJwtProperty<string>('iss', false, jwtProps?.clientId, existingJwt?.payload?.iss)
135+
: getJwtProperty<string>('iss', false, jwtProps?.issuer, existingJwt?.payload?.iss);
136136
const client_id = mode === 'JWT' ? getJwtProperty<string>('client_id', false, jwtProps?.clientId, existingJwt?.payload?.client_id) : undefined;
137137
const jti = getJwtProperty<string>('jti', false, jwtProps?.jti, existingJwt?.payload?.jti);
138138
const typ = getJwtProperty<string>('typ', true, jwtProps?.typ, existingJwt?.header?.typ, 'openid4vci-proof+jwt');
@@ -142,7 +142,7 @@ const createJWT = (mode: PoPMode, jwtProps?: JwtProps, existingJwt?: Jwt): Jwt =
142142
const kid = getJwtProperty<string>('kid', false, jwtProps?.kid, existingJwt?.header?.kid);
143143
const jwk = getJwtProperty<BaseJWK>('jwk', false, jwtProps?.jwk, existingJwt?.header?.jwk);
144144
const x5c = getJwtProperty<string[]>('x5c', false, jwtProps?.x5c, existingJwt?.header.x5c);
145-
const jwt: Partial<Jwt> = existingJwt ? existingJwt : {};
145+
const jwt: Partial<Jwt> = { ...existingJwt };
146146
const now = +new Date();
147147
const jwtPayload: Partial<JWTPayload> = {
148148
...(aud && { aud }),

0 commit comments

Comments
 (0)