Skip to content

Commit

Permalink
chore: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 9, 2024
1 parent 042b183 commit 846229a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class AccessTokenClient {
const hostname = url.replace(/https?:\/\//, '').replace(/\/$/, '');
const endpoint = tokenEndpoint ? (tokenEndpoint.startsWith('/') ? tokenEndpoint : tokenEndpoint.substring(1)) : '/token';
const scheme = url.split('://')[0];
console.log(`scheme: ${scheme}, hostname: ${hostname}, endpoint: ${endpoint}`);
return `${scheme ? scheme + '://' : 'https://'}${hostname}${endpoint}`;
}

Expand Down
11 changes: 7 additions & 4 deletions packages/client/lib/AuthorizationCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
ResponseType,
} from '@sphereon/oid4vci-common';
import { formPost } from '@sphereon/oid4vci-common';
import Debug from 'debug';

const debug = Debug('sphereon:oid4vci');

export const createAuthorizationRequestUrl = async ({
pkce,
Expand Down Expand Up @@ -87,24 +90,24 @@ export const createAuthorizationRequestUrl = async ({
if (!parEndpoint && parMode === PARMode.REQUIRE) {
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`);
} else if (parEndpoint && parMode !== PARMode.NEVER) {
console.log(`USING PAR with endpoint ${parEndpoint}`);
debug(`USING PAR with endpoint ${parEndpoint}`);
const parResponse = await formPost<PushedAuthorizationResponse>(parEndpoint, new URLSearchParams(queryObj));
if (parResponse.errorBody || !parResponse.successBody) {
throw Error(`PAR error`);
}
console.log(`PAR response: ${(parResponse.successBody, null, 2)}`);
debug(`PAR response: ${(parResponse.successBody, null, 2)}`);
queryObj = { request_uri: parResponse.successBody.request_uri };
}

console.log(`QUERY obj: ` + JSON.stringify(queryObj, null, 2));
debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2));
const url = convertJsonToURI(queryObj, {
baseUrl: endpointMetadata.authorization_endpoint,
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
// arrayTypeProperties: ['authorization_details'],
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
// We do not add the version here, as this always needs to be form encoded
});
console.log(`Authorization Request URL: ${url}`);
debug(`Authorization Request URL: ${url}`);
return url;
};

Expand Down
14 changes: 6 additions & 8 deletions packages/common/lib/functions/CredentialRequestUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
CredentialRequestV1_0_08,
CredentialRequestV1_0_11,
OpenId4VCIVersion,
UniformCredentialRequest,
} from '../types';
import { CredentialRequestV1_0_08, CredentialRequestV1_0_11, OpenId4VCIVersion, UniformCredentialRequest } from '../types';

import { getFormatForVersion } from './FormatUtils';

Expand All @@ -14,7 +9,10 @@ export function getTypesFromRequest(credentialRequest: UniformCredentialRequest,
} else if (credentialRequest.format === 'jwt_vc_json-ld' || credentialRequest.format === 'ldp_vc') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
types = 'credential_definition' in credentialRequest && credentialRequest.credential_definition ? credentialRequest.credential_definition.types : credentialRequest.types;
types =
'credential_definition' in credentialRequest && credentialRequest.credential_definition
? credentialRequest.credential_definition.types
: credentialRequest.types;
} else if (credentialRequest.format === 'vc+sd-jwt') {
types = [credentialRequest.vct];
}
Expand All @@ -41,7 +39,7 @@ export function getCredentialRequestForVersion(
proof: credentialRequest.proof,
type: types[0],
} satisfies CredentialRequestV1_0_08;
/* } else if (version === OpenId4VCIVersion.VER_1_0_11) {
/* } else if (version === OpenId4VCIVersion.VER_1_0_11) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { credential_definition = undefined, ...requestv11 } = credentialRequest;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/lib/types/Generic.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ICredentialContextType, IVerifiableCredential, W3CVerifiableCredential
import { ProofOfPossession } from './CredentialIssuance.types';
import { AuthorizationServerMetadata } from './ServerMetadata';
import { CredentialOfferSession } from './StateManager.types';
import { CredentialRequestV1_0_11 } from './v1_0_11.types'
import { CredentialRequestV1_0_11 } from './v1_0_11.types';

/**
* Important Note: please be aware that these Common interfaces are based on versions v1_0.11 and v1_0.09
Expand Down
5 changes: 1 addition & 4 deletions packages/issuer-rest/lib/oid4vci-api-functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import console from 'console'
import process from 'process'

import {
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
AuthorizationRequest,
Expand Down Expand Up @@ -353,7 +350,7 @@ export function getBaseUrl(url?: URL | string | undefined) {
}
}
if (!baseUrl) {
throw Error(`Not base URL provided`)
throw Error(`No base URL provided`)
}
return trimEnd(baseUrl.toString(), '/')
}
Expand Down

0 comments on commit 846229a

Please sign in to comment.