@@ -29,6 +29,7 @@ import {
2929 OIDCEndpoints ,
3030 TokenResponse ,
3131 extractPkceStorageKeyFromState ,
32+ Config ,
3233} from '@asgardeo/javascript' ;
3334import { SPAHelper } from './spa-helper' ;
3435import {
@@ -103,26 +104,31 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
103104 config : SPACustomGrantConfig ,
104105 enableRetrievingSignOutURLFromSession ?: ( config : SPACustomGrantConfig ) => void ,
105106 ) : Promise < User | Response > {
107+ const _config : Config = ( await this . _storageManager . getConfigData ( ) ) as Config ;
106108 let useDefaultEndpoint = true ;
107109 let matches = false ;
108110
109111 // If the config does not contains a token endpoint, default token endpoint will be used.
110112 if ( config ?. tokenEndpoint ) {
111113 useDefaultEndpoint = false ;
112114
113- for ( const baseUrl of [
114- ... ( ( await this . _storageManager . getConfigData ( ) ) ?. resourceServerURLs ?? [ ] ) ,
115- ( config as any ) . baseUrl ,
116- ] ) {
117- if ( baseUrl && config . tokenEndpoint ?. startsWith ( baseUrl ) ) {
118- matches = true ;
119- break ;
115+ // Only validate URLs for WebWorker storage
116+ if ( _config . storage === BrowserStorage . WebWorker ) {
117+ for ( const baseUrl of [ ... ( _config ?. allowedExternalUrls ?? [ ] ) , ( config as any ) . baseUrl ] ) {
118+ if ( baseUrl && config . tokenEndpoint ?. startsWith ( baseUrl ) ) {
119+ matches = true ;
120+ break ;
121+ }
120122 }
123+ } else {
124+ matches = true ;
121125 }
122126 }
127+
123128 if ( config . shouldReplayAfterRefresh ) {
124129 this . _storageManager . setTemporaryDataParameter ( CUSTOM_GRANT_CONFIG , JSON . stringify ( config ) ) ;
125130 }
131+
126132 if ( useDefaultEndpoint || matches ) {
127133 return this . _authenticationClient
128134 . exchangeToken ( config )
@@ -147,9 +153,9 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
147153 new AsgardeoAuthException (
148154 'SPA-MAIN_THREAD_CLIENT-RCG-IV01' ,
149155 'Request to the provided endpoint is prohibited.' ,
150- 'Requests can only be sent to resource servers specified by the `resourceServerURLs `' +
156+ 'Requests can only be sent to resource servers specified by the `allowedExternalUrls `' +
151157 ' attribute while initializing the SDK. The specified token endpoint in this request ' +
152- 'cannot be found among the `resourceServerURLs `' ,
158+ 'cannot be found among the `allowedExternalUrls `' ,
153159 ) ,
154160 ) ;
155161 }
@@ -224,14 +230,19 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
224230 enableRetrievingSignOutURLFromSession ?: ( config : SPACustomGrantConfig ) => void ,
225231 ) : Promise < HttpResponse > {
226232 let matches = false ;
227- const config = await this . _storageManager . getConfigData ( ) ;
233+ const config : Config = ( await this . _storageManager . getConfigData ( ) ) as Config ;
228234
229- for ( const baseUrl of [ ...( ( await config ?. resourceServerURLs ) ?? [ ] ) , ( config as any ) . baseUrl ] ) {
230- if ( baseUrl && requestConfig ?. url ?. startsWith ( baseUrl ) ) {
231- matches = true ;
235+ // Only validate URLs for WebWorker storage
236+ if ( config . storage === BrowserStorage . WebWorker ) {
237+ for ( const baseUrl of [ ...( config ?. allowedExternalUrls ?? [ ] ) , ( config as any ) . baseUrl ] ) {
238+ if ( baseUrl && requestConfig ?. url ?. startsWith ( baseUrl ) ) {
239+ matches = true ;
232240
233- break ;
241+ break ;
242+ }
234243 }
244+ } else {
245+ matches = true ;
235246 }
236247
237248 if ( matches ) {
@@ -319,9 +330,9 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
319330 new AsgardeoAuthException (
320331 'SPA-AUTH_HELPER-HR-IV02' ,
321332 'Request to the provided endpoint is prohibited.' ,
322- 'Requests can only be sent to resource servers specified by the `resourceServerURLs `' +
333+ 'Requests can only be sent to resource servers specified by the `allowedExternalUrls `' +
323334 ' attribute while initializing the SDK. The specified endpoint in this request ' +
324- 'cannot be found among the `resourceServerURLs `' ,
335+ 'cannot be found among the `allowedExternalUrls `' ,
325336 ) ,
326337 ) ;
327338 }
@@ -335,23 +346,26 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
335346 httpFinishCallback ?: ( ) => void ,
336347 ) : Promise < HttpResponse [ ] | undefined > {
337348 let matches = true ;
338- const config = await this . _storageManager . getConfigData ( ) ;
349+ const config : Config = ( await this . _storageManager . getConfigData ( ) ) as Config ;
339350
340- for ( const requestConfig of requestConfigs ) {
341- let urlMatches = false ;
351+ // Only validate URLs for WebWorker storage
352+ if ( config . storage === BrowserStorage . WebWorker ) {
353+ for ( const requestConfig of requestConfigs ) {
354+ let urlMatches = false ;
342355
343- for ( const baseUrl of [ ...( ( await config ) ?. resourceServerURLs ?? [ ] ) , ( config as any ) . baseUrl ] ) {
344- if ( baseUrl && requestConfig . url ?. startsWith ( baseUrl ) ) {
345- urlMatches = true ;
356+ for ( const baseUrl of [ ...( config ?. allowedExternalUrls ?? [ ] ) , ( config as any ) . baseUrl ] ) {
357+ if ( baseUrl && requestConfig . url ?. startsWith ( baseUrl ) ) {
358+ urlMatches = true ;
346359
347- break ;
360+ break ;
361+ }
348362 }
349- }
350363
351- if ( ! urlMatches ) {
352- matches = false ;
364+ if ( ! urlMatches ) {
365+ matches = false ;
353366
354- break ;
367+ break ;
368+ }
355369 }
356370 }
357371
@@ -436,9 +450,9 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
436450 throw new AsgardeoAuthException (
437451 'SPA-AUTH_HELPER-HRA-IV02' ,
438452 'Request to the provided endpoint is prohibited.' ,
439- 'Requests can only be sent to resource servers specified by the `resourceServerURLs `' +
453+ 'Requests can only be sent to resource servers specified by the `allowedExternalUrls `' +
440454 ' attribute while initializing the SDK. The specified endpoint in this request ' +
441- 'cannot be found among the `resourceServerURLs `' ,
455+ 'cannot be found among the `allowedExternalUrls `' ,
442456 ) ;
443457 }
444458 }
0 commit comments