Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changes for oid4vc conformance tests #145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions packages/common/lib/jwt/JwtVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ export const getDidJwtVerifier = (jwt: { header: JwtHeader; payload: JwtPayload
return { method: 'did', didUrl: jwt.header.kid, type: type, alg: jwt.header.alg };
};

const getIssuer = (type: JwtType, payload: JwtPayload): string => {
// For 'request-object' the `iss` value is not required so we map the issuer to client_id
if (type === 'request-object') {
if (!payload.client_id) {
throw new Error('Missing required field client_id in request object JWT');
}
return payload.client_id as string;
}

if (typeof payload.iss !== 'string') {
throw new Error(`Received an invalid JWT. '${type}' contains an invalid iss claim or it is missing.`);
}
return payload.iss;
};

export const getX5cVerifier = (jwt: { header: JwtHeader; payload: JwtPayload }, options: { type: JwtType }): X5cJwtVerifier => {
const { type } = options;
if (!jwt.header.x5c) throw new Error(`Received an invalid JWT. Missing x5c header.`);
Expand All @@ -75,11 +90,13 @@ export const getX5cVerifier = (jwt: { header: JwtHeader; payload: JwtPayload },
throw new Error(`Received an invalid JWT.. '${type}' contains an invalid x5c header.`);
}

if (typeof jwt.payload.iss !== 'string') {
throw new Error(`Received an invalid JWT. '${type}' contains an invalid iss claim.`);
}

return { method: 'x5c', x5c: jwt.header.x5c, issuer: jwt.payload.iss, type: type, alg: jwt.header.alg };
return {
method: 'x5c',
x5c: jwt.header.x5c,
issuer: getIssuer(type, jwt.payload),
type: type,
alg: jwt.header.alg,
};
};

export const getJwkVerifier = async (jwt: { header: JwtHeader; payload: JwtPayload }, options: { type: JwtType }): Promise<JwkJwtVerifier> => {
Expand Down
3 changes: 1 addition & 2 deletions packages/siop-oid4vp/lib/authorization-response/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export const createResponsePayload = async (
const state: string | undefined = await authorizationRequest.getMergedProperty('state')

const responsePayload: AuthorizationResponsePayload = {
...(responseOpts.accessToken && { access_token: responseOpts.accessToken }),
...(responseOpts.accessToken && { access_token: responseOpts.accessToken, expires_in: responseOpts.expiresIn || 3600 }),
...(responseOpts.tokenType && { token_type: responseOpts.tokenType }),
...(responseOpts.refreshToken && { refresh_token: responseOpts.refreshToken }),
expires_in: responseOpts.expiresIn || 3600,
state,
}

Expand Down