Skip to content

Commit

Permalink
chore: getTypesFromObject improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jun 21, 2024
1 parent 53e027b commit 31597bc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
11 changes: 7 additions & 4 deletions packages/client/lib/AuthorizationCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ export async function createSignedAuthRequestWhenNeeded(requestObject: Record<st
} else if (!opts.kid) {
throw Error(`No kid found, whilst request object mode was set to ${opts.requestObjectMode}`);
}
let client_metadata: any
let client_metadata: any;
if (opts.clientMetadata || opts.jwksUri) {
client_metadata = opts.clientMetadata ?? {};
if (opts.jwksUri) {
client_metadata['jwks_uri'] = opts.jwksUri;
}
}
let authorization_details = requestObject['authorization_details']
let authorization_details = requestObject['authorization_details'];
if (typeof authorization_details === 'string') {
authorization_details = JSON.parse(requestObject.authorization_details);
}
if (!requestObject.aud && opts.aud) {
requestObject.aud = opts.aud;
}
const iss = requestObject.iss ?? opts.iss ?? requestObject.client_id
const iss = requestObject.iss ?? opts.iss ?? requestObject.client_id;

const jwt: Jwt = { header: { alg: 'ES256', kid: opts.kid, typ: 'jwt' }, payload: {...requestObject, iss, authorization_details, ...(client_metadata && {client_metadata})} };
const jwt: Jwt = {
header: { alg: 'ES256', kid: opts.kid, typ: 'jwt' },
payload: { ...requestObject, iss, authorization_details, ...(client_metadata && { client_metadata }) },
};
const pop = await ProofOfPossessionBuilder.fromJwt({
jwt,
callbacks: opts.signCallbacks,
Expand Down
22 changes: 20 additions & 2 deletions packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { CredentialDefinitionV1_0_13, CredentialOfferFormat, JsonLdIssuerCredentialDefinition, VCI_LOG_COMMON } from '../index';
import {
CredentialDefinitionV1_0_13,
CredentialOfferFormat,
CredentialOfferPayload,
JsonLdIssuerCredentialDefinition,
UniformCredentialOfferRequest,
VCI_LOG_COMMON,
} from '../index';
import {
AuthorizationServerMetadata,
CredentialConfigurationSupported,
Expand Down Expand Up @@ -236,7 +243,14 @@ export function getIssuerName(
* @param subject
*/
export function getTypesFromObject(
subject: CredentialConfigurationSupported | CredentialOfferFormat | CredentialDefinitionV1_0_13 | JsonLdIssuerCredentialDefinition | string,
subject:
| CredentialConfigurationSupported
| CredentialOfferFormat
| CredentialOfferPayload
| CredentialDefinitionV1_0_13
| JsonLdIssuerCredentialDefinition
| UniformCredentialOfferRequest
| string,
): string[] | undefined {
if (subject === undefined) {
return undefined;
Expand All @@ -250,6 +264,10 @@ export function getTypesFromObject(
return Array.isArray(subject.type) ? subject.type : [subject.type];
} else if ('vct' in subject && subject.vct) {
return [subject.vct];
} else if ('credentials' in subject && subject.credentials) {
return getTypesFromObject(subject.credentials);
} else if ('credential_offer' in subject && subject.credential_offer) {
return getTypesFromObject(subject.credential_offer);
}

VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!');
Expand Down
4 changes: 2 additions & 2 deletions packages/common/lib/functions/ProofUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ const createJWT = (mode: PoPMode, jwtProps?: JwtProps, existingJwt?: Jwt): Jwt =
: getJwtProperty<string | string[]>('aud', false, jwtProps?.aud, existingJwt?.payload?.aud);
const iss =
// mode === 'pop'
getJwtProperty<string>('iss', false, jwtProps?.clientId, existingJwt?.payload?.iss)
// : getJwtProperty<string>('iss', false, jwtProps?.issuer, existingJwt?.payload?.iss);
getJwtProperty<string>('iss', false, jwtProps?.clientId, existingJwt?.payload?.iss);
// : getJwtProperty<string>('iss', false, jwtProps?.issuer, existingJwt?.payload?.iss);
const client_id = mode === 'jwt' ? getJwtProperty<string>('client_id', false, jwtProps?.clientId, existingJwt?.payload?.client_id) : undefined;
const jti = getJwtProperty<string>('jti', false, jwtProps?.jti, existingJwt?.payload?.jti);
const typ = getJwtProperty<string>('typ', true, jwtProps?.typ, existingJwt?.header?.typ, 'jwt');
Expand Down

0 comments on commit 31597bc

Please sign in to comment.