Skip to content

Commit

Permalink
Merge pull request #169 from Sphereon-Opensource/feature/SPRIND-116
Browse files Browse the repository at this point in the history
Feature/sprind 116
  • Loading branch information
zoemaas authored Jan 14, 2025
2 parents 7e8d503 + 642c60b commit c159817
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
6 changes: 6 additions & 0 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class OpenID4VCIClient {
pkce,
authorizationRequest,
createAuthorizationRequestURL,
endpointMetadata
}: {
credentialIssuer: string;
kid?: string;
Expand All @@ -139,6 +140,7 @@ export class OpenID4VCIClient {
createAuthorizationRequestURL?: boolean;
authorizationRequest?: AuthorizationRequestOpts; // Can be provided here, or when manually calling createAuthorizationUrl
pkce?: PKCEOpts;
endpointMetadata?: EndpointMetadataResult
}) {
const client = new OpenID4VCIClient({
kid,
Expand All @@ -147,6 +149,7 @@ export class OpenID4VCIClient {
credentialIssuer,
pkce,
authorizationRequest,
endpointMetadata
});
if (retrieveServerMetadata === undefined || retrieveServerMetadata) {
await client.retrieveServerMetadata();
Expand All @@ -173,6 +176,7 @@ export class OpenID4VCIClient {
createAuthorizationRequestURL,
authorizationRequest,
resolveOfferUri,
endpointMetadata
}: {
uri: string;
kid?: string;
Expand All @@ -183,6 +187,7 @@ export class OpenID4VCIClient {
pkce?: PKCEOpts;
clientId?: string;
authorizationRequest?: AuthorizationRequestOpts; // Can be provided here, or when manually calling createAuthorizationUrl
endpointMetadata?: EndpointMetadataResult
}): Promise<OpenID4VCIClient> {
const credentialOfferClient = await CredentialOfferClient.fromURI(uri, { resolve: resolveOfferUri });
const client = new OpenID4VCIClient({
Expand All @@ -192,6 +197,7 @@ export class OpenID4VCIClient {
clientId: clientId ?? authorizationRequest?.clientId ?? credentialOfferClient.clientId,
pkce,
authorizationRequest,
endpointMetadata
});

if (retrieveServerMetadata === undefined || retrieveServerMetadata) {
Expand Down
16 changes: 11 additions & 5 deletions packages/siop-oid4vp/lib/authorization-request/URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,22 @@ export class URI implements AuthorizationRequestURI {
return { scheme, authorizationRequestPayload }
}

public static async parseAndResolve(uri: string) {
public static async parseAndResolve(uri: string, rpRegistrationMetadata?: RPRegistrationMetadataPayload) {
if (!uri) {
throw Error(SIOPErrors.BAD_PARAMS)
}
const { authorizationRequestPayload, scheme } = this.parse(uri)

const requestObjectJwt = await fetchByReferenceOrUseByValue(authorizationRequestPayload.request_uri, authorizationRequestPayload.request, true)
const registrationMetadata: RPRegistrationMetadataPayload = await fetchByReferenceOrUseByValue(
authorizationRequestPayload['client_metadata_uri'] ?? authorizationRequestPayload['registration_uri'],
authorizationRequestPayload['client_metadata'] ?? authorizationRequestPayload['registration'],
)
let registrationMetadata: RPRegistrationMetadataPayload
if (rpRegistrationMetadata !== undefined && rpRegistrationMetadata !== null) {
registrationMetadata = rpRegistrationMetadata
} else {
registrationMetadata = await fetchByReferenceOrUseByValue(
authorizationRequestPayload['client_metadata_uri'] ?? authorizationRequestPayload['registration_uri'],
authorizationRequestPayload['client_metadata'] ?? authorizationRequestPayload['registration'],
)
}
assertValidRPRegistrationMedataPayload(registrationMetadata)
return { scheme, authorizationRequestPayload, requestObjectJwt, registrationMetadata }
}
Expand Down
7 changes: 4 additions & 3 deletions packages/siop-oid4vp/lib/op/OP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
RegisterEventListener,
RequestObjectPayload,
ResponseIss,
ResponseMode,
ResponseMode, RPRegistrationMetadataPayload,
SIOPErrors,
SupportedVersion,
UrlEncodingFormat,
Expand Down Expand Up @@ -275,9 +275,10 @@ export class OP {
* Create an Authentication Request Payload from a URI string
*
* @param encodedUri
* @param rpRegistrationMetadata
*/
public async parseAuthorizationRequestURI(encodedUri: string): Promise<ParsedAuthorizationRequestURI> {
const { scheme, requestObjectJwt, authorizationRequestPayload, registrationMetadata } = await URI.parseAndResolve(encodedUri)
public async parseAuthorizationRequestURI(encodedUri: string, rpRegistrationMetadata?: RPRegistrationMetadataPayload): Promise<ParsedAuthorizationRequestURI> {
const { scheme, requestObjectJwt, authorizationRequestPayload, registrationMetadata } = await URI.parseAndResolve(encodedUri, rpRegistrationMetadata)

return {
encodedUri,
Expand Down
20 changes: 15 additions & 5 deletions packages/siop-oid4vp/lib/types/SIOP.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// noinspection JSUnusedGlobalSymbols
import { JarmClientMetadata } from '@sphereon/jarm'
import { DynamicRegistrationClientMetadata, JWKS, SigningAlgo } from '@sphereon/oid4vc-common'
import {
DynamicRegistrationClientMetadata,
JWKS,
SigningAlgo
} from '@sphereon/oid4vc-common'
import { Format, PresentationDefinitionV1, PresentationDefinitionV2 } from '@sphereon/pex-models'
import {
AdditionalClaims,
Expand All @@ -11,22 +15,28 @@ import {
PresentationSubmission,
W3CVerifiableCredential,
W3CVerifiablePresentation,
WrappedVerifiablePresentation,
WrappedVerifiablePresentation
} from '@sphereon/ssi-types'

import { AuthorizationRequest, CreateAuthorizationRequestOpts, PropertyTargets, VerifyAuthorizationRequestOpts } from '../authorization-request'
import {
AuthorizationRequest,
CreateAuthorizationRequestOpts,
PropertyTargets,
VerifyAuthorizationRequestOpts
} from '../authorization-request'
import {
AuthorizationResponse,
AuthorizationResponseOpts,
PresentationDefinitionWithLocation,
PresentationVerificationCallback,
VerifyAuthorizationResponseOpts,
VerifyAuthorizationResponseOpts
} from '../authorization-response'
import { JwksMetadataParams } from '../helpers/ExtractJwks'
import { JwksMetadataParams } from '../helpers'
import { RequestObject, RequestObjectOpts } from '../request-object'
import { IRPSessionManager } from '../rp'

import { JWTPayload, VerifiedJWT } from './index'

export const DEFAULT_EXPIRATION_TIME = 10 * 60

// https://openid.net/specs/openid-connect-core-1_0.html#RequestObject
Expand Down

0 comments on commit c159817

Please sign in to comment.