diff --git a/packages/siop-oid4vp/lib/authorization-request/Payload.ts b/packages/siop-oid4vp/lib/authorization-request/Payload.ts index 83c7d5ee..3219f700 100644 --- a/packages/siop-oid4vp/lib/authorization-request/Payload.ts +++ b/packages/siop-oid4vp/lib/authorization-request/Payload.ts @@ -66,7 +66,6 @@ export const createAuthorizationRequestPayload = async ( ...(state && { state }), ...(registration.payload && isTarget(PropertyTarget.AUTHORIZATION_REQUEST, registration.clientMetadataOpts.targets) ? registration.payload : {}), ...(claims && { claims }), - ...(opts.requestObject.payload?.redirectUri && { redirect_uri: opts.requestObject.payload.redirectUri }) } return removeNullUndefined(authRequestPayload) diff --git a/packages/siop-oid4vp/lib/authorization-request/URI.ts b/packages/siop-oid4vp/lib/authorization-request/URI.ts index e9857ef7..7aa04815 100644 --- a/packages/siop-oid4vp/lib/authorization-request/URI.ts +++ b/packages/siop-oid4vp/lib/authorization-request/URI.ts @@ -126,6 +126,7 @@ export class URI implements AuthorizationRequestURI { ...authorizationRequest.options.requestObject, version: authorizationRequest.options.version, uriScheme: authorizationRequest.options.uriScheme, + }, authorizationRequest.payload, authorizationRequest.requestObject, diff --git a/packages/siop-oid4vp/lib/authorization-request/types.ts b/packages/siop-oid4vp/lib/authorization-request/types.ts index 4d49e9f5..2889147b 100644 --- a/packages/siop-oid4vp/lib/authorization-request/types.ts +++ b/packages/siop-oid4vp/lib/authorization-request/types.ts @@ -62,6 +62,7 @@ interface AuthorizationRequestCommonOpts { payload?: AuthorizationRequestPayloadOpts requestObject: RequestObjectOpts uriScheme?: Schema | string // Use a custom scheme for the URI. By default openid:// will be used + responseRedirectUri?: string; } export type AuthorizationRequestOptsVID1 = AuthorizationRequestCommonOpts diff --git a/packages/siop-oid4vp/lib/rp/RP.ts b/packages/siop-oid4vp/lib/rp/RP.ts index 77e6108a..5c5a2e4d 100644 --- a/packages/siop-oid4vp/lib/rp/RP.ts +++ b/packages/siop-oid4vp/lib/rp/RP.ts @@ -41,6 +41,7 @@ export class RP { private readonly _verifyResponseOptions: Partial private readonly _eventEmitter?: EventEmitter private readonly _sessionManager?: IRPSessionManager + private readonly _responseRedirectUri?: string private constructor(opts: { builder?: RPBuilder @@ -52,6 +53,7 @@ export class RP { this._verifyResponseOptions = { ...createVerifyResponseOptsFromBuilderOrExistingOpts(opts) } this._eventEmitter = opts.builder?.eventEmitter this._sessionManager = opts.builder?.sessionManager + this._responseRedirectUri = opts.builder?._responseRedirectUri } public static fromRequestOpts(opts: CreateAuthorizationRequestOpts): RP { @@ -103,12 +105,12 @@ export class RP { responseURIType?: ResponseURIType }): Promise { const authorizationRequestOpts = this.newAuthorizationRequestOpts(opts) - if(authorizationRequestOpts.requestObject.payload?.redirectUri !== undefined) { - authorizationRequestOpts.requestObject.payload.redirectUri = authorizationRequestOpts.requestObject.payload.redirectUri + if(authorizationRequestOpts.responseRedirectUri !== undefined) { + authorizationRequestOpts.responseRedirectUri = authorizationRequestOpts.responseRedirectUri .replace(':correlation_id', opts.correlationId) .replace(':correlationId', opts.correlationId) if(typeof(opts.state) === 'string') { - authorizationRequestOpts.requestObject.payload.redirectUri = authorizationRequestOpts.requestObject.payload.redirectUri.replace(':state', opts.state) + authorizationRequestOpts.responseRedirectUri = authorizationRequestOpts.responseRedirectUri.replace(':state', opts.state) } } @@ -302,6 +304,8 @@ export class RP { newOpts.requestObject.payload.claims = { ...newOpts.requestObject.payload.claims, ...claimsWithTarget.propertyValue } } } + + newOpts.responseRedirectUri = this._responseRedirectUri return newOpts } diff --git a/packages/siop-oid4vp/lib/rp/RPBuilder.ts b/packages/siop-oid4vp/lib/rp/RPBuilder.ts index 608cc10d..73e5eb51 100644 --- a/packages/siop-oid4vp/lib/rp/RPBuilder.ts +++ b/packages/siop-oid4vp/lib/rp/RPBuilder.ts @@ -34,6 +34,7 @@ export class RPBuilder { supportedVersions: SupportedVersion[] eventEmitter?: EventEmitter sessionManager?: IRPSessionManager + _responseRedirectUri?: string private _authorizationRequestPayload: Partial = {} private _requestObjectPayload: Partial = {} @@ -133,7 +134,12 @@ export class RPBuilder { return this } - withResponsetUri(redirectUri: string, targets?: PropertyTargets): RPBuilder { + withResponseRedirectUri(redirectUri: string, targets?: PropertyTargets): RPBuilder { + this._responseRedirectUri = assignIfAuth({ propertyValue: redirectUri, targets }, false) + return this + } + + withResponseUri(redirectUri: string, targets?: PropertyTargets): RPBuilder { this._authorizationRequestPayload.response_uri = assignIfAuth({ propertyValue: redirectUri, targets }, false) this._requestObjectPayload.response_uri = assignIfRequestObject({ propertyValue: redirectUri, targets }, true) return this