Skip to content

Commit

Permalink
chore: redirect_uri changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Oct 3, 2024
1 parent b10e7a4 commit fba3f6b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/siop-oid4vp/lib/authorization-request/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/siop-oid4vp/lib/authorization-request/URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class URI implements AuthorizationRequestURI {
...authorizationRequest.options.requestObject,
version: authorizationRequest.options.version,
uriScheme: authorizationRequest.options.uriScheme,

},
authorizationRequest.payload,
authorizationRequest.requestObject,
Expand Down
1 change: 1 addition & 0 deletions packages/siop-oid4vp/lib/authorization-request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface AuthorizationRequestCommonOpts<CT extends ClaimPayloadCommonOpts> {
payload?: AuthorizationRequestPayloadOpts<CT>
requestObject: RequestObjectOpts<CT>
uriScheme?: Schema | string // Use a custom scheme for the URI. By default openid:// will be used
responseRedirectUri?: string;
}

export type AuthorizationRequestOptsVID1 = AuthorizationRequestCommonOpts<ClaimPayloadOptsVID1>
Expand Down
10 changes: 7 additions & 3 deletions packages/siop-oid4vp/lib/rp/RP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class RP {
private readonly _verifyResponseOptions: Partial<VerifyAuthorizationResponseOpts>
private readonly _eventEmitter?: EventEmitter
private readonly _sessionManager?: IRPSessionManager
private readonly _responseRedirectUri?: string

private constructor(opts: {
builder?: RPBuilder
Expand All @@ -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 {
Expand Down Expand Up @@ -103,12 +105,12 @@ export class RP {
responseURIType?: ResponseURIType
}): Promise<URI> {
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)
}
}

Expand Down Expand Up @@ -302,6 +304,8 @@ export class RP {
newOpts.requestObject.payload.claims = { ...newOpts.requestObject.payload.claims, ...claimsWithTarget.propertyValue }
}
}

newOpts.responseRedirectUri = this._responseRedirectUri
return newOpts
}

Expand Down
8 changes: 7 additions & 1 deletion packages/siop-oid4vp/lib/rp/RPBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class RPBuilder {
supportedVersions: SupportedVersion[]
eventEmitter?: EventEmitter
sessionManager?: IRPSessionManager
_responseRedirectUri?: string
private _authorizationRequestPayload: Partial<AuthorizationRequestPayload> = {}
private _requestObjectPayload: Partial<RequestObjectPayload> = {}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fba3f6b

Please sign in to comment.