@@ -37,7 +37,7 @@ import {
3737 SupportedVersion ,
3838 Verification ,
3939 VerifiedAuthorizationResponse ,
40- CallbackOpts
40+ CallbackOpts , AuthorizationRequestState
4141} from '../types'
4242
4343
@@ -282,14 +282,33 @@ export class RP {
282282 return this . _verifyResponseOptions
283283 }
284284
285- public getResponseRedirectUri ( mappings ?: Record < string , string > ) : string | undefined {
286- if ( ! this . _responseRedirectUri ) {
287- return undefined
288- }
285+ public async getResponseRedirectUri ( mappings ?: Record < string , string > ) : Promise < string | undefined > {
289286 if ( ! mappings ) {
287+ if ( ! this . _responseRedirectUri ) {
288+ return undefined
289+ }
290290 return this . _responseRedirectUri
291291 }
292- return Object . entries ( mappings ) . reduce ( ( uri , [ key , value ] ) => uri . replace ( `:${ key } ` , value ) , this . _responseRedirectUri )
292+
293+ let state : AuthorizationRequestState
294+ const correlationId = mappings [ 'correlation_id' ] ?? mappings [ 'correlationId' ]
295+ if ( correlationId ) {
296+ state = await this . sessionManager . getRequestStateByCorrelationId ( correlationId , true )
297+ } else {
298+ const stateId = mappings [ 'state' ]
299+ if ( stateId ) {
300+ state = await this . sessionManager . getRequestStateByState ( stateId , true )
301+ }
302+ }
303+
304+ let redirectUri : string | undefined
305+ if ( state ) {
306+ redirectUri = state . responseRedirectURI
307+ }
308+ if ( ! redirectUri ) {
309+ redirectUri = this . _responseRedirectUri
310+ }
311+ return Object . entries ( mappings ) . reduce ( ( uri , [ key , value ] ) => uri . replace ( `:${ key } ` , value ) , redirectUri )
293312 }
294313
295314 private newAuthorizationRequestOpts ( opts : {
0 commit comments