File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -290,14 +290,37 @@ export class CalComOAuthService {
290290 }
291291
292292 private async getDiscoveryEndpoints ( ) : Promise < AuthSession . DiscoveryDocument > {
293+ const fallbackDiscovery : AuthSession . DiscoveryDocument = {
294+ authorizationEndpoint : `${ this . config . calcomBaseUrl } /auth/oauth2/authorize` ,
295+ tokenEndpoint : `${ this . config . calcomBaseUrl } /api/auth/oauth/token` ,
296+ revocationEndpoint : `${ this . config . calcomBaseUrl } /api/auth/oauth/revoke` ,
297+ } ;
298+
299+ const isCrossOriginWeb =
300+ Platform . OS === "web" &&
301+ typeof window !== "undefined" &&
302+ ( ( ) => {
303+ try {
304+ return new URL ( this . config . calcomBaseUrl ) . origin !== window . location . origin ;
305+ } catch {
306+ return true ;
307+ }
308+ } ) ( ) ;
309+
310+ // Skip discovery fetch when we know CORS will block it (e.g. companion.cal.com -> app.cal.com).
311+ if ( isCrossOriginWeb ) {
312+ return fallbackDiscovery ;
313+ }
314+
293315 try {
294316 const discovery = await AuthSession . fetchDiscoveryAsync ( this . config . calcomBaseUrl ) ;
295- return discovery ;
296- } catch {
297317 return {
298- authorizationEndpoint : `${ this . config . calcomBaseUrl } /auth/oauth2/authorize` ,
299- tokenEndpoint : `${ this . config . calcomBaseUrl } /api/auth/oauth/token` ,
300- } as AuthSession . DiscoveryDocument ;
318+ ...fallbackDiscovery ,
319+ ...discovery ,
320+ } ;
321+ } catch ( error ) {
322+ console . warn ( "Failed to load discovery document, using fallback endpoints" , error ) ;
323+ return fallbackDiscovery ;
301324 }
302325 }
303326
You can’t perform that action at this time.
0 commit comments