1919import { AuthenticationHelper } from './helpers' ;
2020import { AuthClientConfig , StrictAuthClientConfig } from './models' ;
2121import OIDCDiscoveryConstants from '../constants/OIDCDiscoveryConstants' ;
22- import OIDCRequestConstants from '../constants/OIDCRequestConstants' ;
2322import PKCEConstants from '../constants/PKCEConstants' ;
23+ import OIDCRequestConstants from '../constants/OIDCRequestConstants' ;
24+ import OIDCDiscoveryConstantsV2 from '../constants/v2/OIDCDiscoveryConstants' ;
2425import { AsgardeoAuthException } from '../errors/exception' ;
2526import { IsomorphicCrypto } from '../IsomorphicCrypto' ;
2627import { Crypto } from '../models/crypto' ;
2728import { ExtendedAuthorizeRequestUrlParams } from '../models/oauth-request' ;
2829import { OIDCDiscoveryApiResponse } from '../models/oidc-discovery' ;
2930import { OIDCEndpoints } from '../models/oidc-endpoints' ;
31+ import { Platform } from '../models/platforms' ;
3032import { SessionData , UserSession } from '../models/session' ;
3133import { Storage , TemporaryStore } from '../models/store' ;
3234import { TokenResponse , IdToken , TokenExchangeRequestConfig } from '../models/token' ;
@@ -149,7 +151,8 @@ export class AsgardeoAuthClient<T> {
149151 // Ref: https://github.com/asgardeo/asgardeo-auth-js-core/pull/205
150152 AsgardeoAuthClient . authHelperInstance = this . authHelper ;
151153
152- let { applicationId} = config ;
154+ const { applicationId, platform, endpoints} = config ;
155+ let resolvedApplicationId : string | undefined = applicationId ;
153156
154157 if ( applicationId ) {
155158 await this . storageManager . setPersistedData ( {
@@ -159,14 +162,23 @@ export class AsgardeoAuthClient<T> {
159162 const persistedData : TemporaryStore = await this . storageManager . getPersistedData ( ) ;
160163
161164 if ( persistedData [ 'applicationId' ] ) {
162- applicationId = persistedData [ 'applicationId' ] as string ;
165+ resolvedApplicationId = persistedData [ 'applicationId' ] as string ;
166+ }
167+ }
168+
169+ const resolvedEndpoints : Partial < OIDCEndpoints > = endpoints || { } ;
170+
171+ if ( platform === Platform . AsgardeoV2 ) {
172+ if ( ! resolvedEndpoints [ 'wellKnown' ] ) {
173+ resolvedEndpoints [ 'wellKnown' ] = OIDCDiscoveryConstantsV2 . Endpoints . WELL_KNOWN ;
163174 }
164175 }
165176
166177 await this . storageManager . setConfigData ( {
167178 ...DefaultConfig ,
168179 ...config ,
169- applicationId,
180+ applicationId : resolvedApplicationId ,
181+ endpoints : resolvedEndpoints ,
170182 scope : processOpenIDScopes ( config . scopes ) ,
171183 } ) ;
172184 }
@@ -434,13 +446,19 @@ export class AsgardeoAuthClient<T> {
434446 return Promise . resolve ( ) ;
435447 }
436448
437- const { wellKnownEndpoint} = configData as any ;
449+ const { wellKnownEndpoint, platform, discovery, baseUrl, endpoints} = configData as any ;
450+
451+ const resolvedWellKnownEndpoint : string | undefined =
452+ wellKnownEndpoint ||
453+ ( platform === Platform . AsgardeoV2 && discovery ?. wellKnown ?. enabled
454+ ? `${ baseUrl } ${ endpoints ?. wellKnown ?? '/.well-known/openid-configuration' } `
455+ : undefined ) ;
438456
439- if ( wellKnownEndpoint ) {
457+ if ( resolvedWellKnownEndpoint ) {
440458 let response : Response ;
441459
442460 try {
443- response = await fetch ( wellKnownEndpoint ) ;
461+ response = await fetch ( resolvedWellKnownEndpoint ) ;
444462 if ( response . status !== 200 || ! response . ok ) {
445463 throw new Error ( ) ;
446464 }
0 commit comments