@@ -144,38 +144,9 @@ export class CalComOAuthService {
144144 }
145145 }
146146
147- // Detect browser extension environment using reliable indicators
148- private isBrowserExtension ( ) : boolean {
149- if ( Platform . OS !== "web" || typeof window === "undefined" ) {
150- return false ;
151- }
152-
153- if ( typeof chrome !== "undefined" && chrome . runtime ?. id ) {
154- return true ;
155- }
156-
157- if ( window . location . protocol === "chrome-extension:" ) {
158- return true ;
159- }
160-
161- // Extension content script injects companion app as iframe
162- if ( window . parent !== window ) {
163- try {
164- const parentOrigin = window . parent . location . origin ;
165- const currentOrigin = window . location . origin ;
166-
167- if ( parentOrigin !== currentOrigin && window . location . hostname === "localhost" ) {
168- return true ;
169- }
170- } catch {
171- // Cross-origin access blocked - expected for extension iframes
172- if ( window . location . hostname === "localhost" ) {
173- return true ;
174- }
175- }
176- }
177-
178- return false ;
147+ // Detect if this is a mobile app (not web/extension)
148+ private isMobileApp ( ) : boolean {
149+ return Platform . OS !== "web" ;
179150 }
180151
181152 private async launchExtensionAuthFlow ( authUrl : string ) : Promise < string > {
@@ -251,9 +222,17 @@ export class CalComOAuthService {
251222 ) : Promise < AuthSession . AuthSessionResult | { type : string ; params : Record < string , string > } > {
252223 const authUrl = this . buildAuthorizationUrl ( codeChallenge , state ) ;
253224
254- const isExtension = this . isBrowserExtension ( ) ;
225+ if ( this . isMobileApp ( ) ) {
226+ const result = await WebBrowser . openAuthSessionAsync ( authUrl , this . config . redirectUri ) ;
227+
228+ if ( result . type === "success" ) {
229+ const params = this . parseCallbackUrl ( result . url ) ;
230+ return { type : "success" as const , params } ;
231+ }
255232
256- if ( isExtension ) {
233+ return { type : result . type , params : { } } as { type : string ; params : Record < string , string > } ;
234+ } else {
235+ // Treat everything else as browser extension
257236 try {
258237 const responseUrl = await this . launchExtensionAuthFlow ( authUrl ) ;
259238 const params = this . parseCallbackUrl ( responseUrl ) ;
@@ -265,27 +244,6 @@ export class CalComOAuthService {
265244 params : Record < string , string > ;
266245 } ;
267246 }
268- } else if ( Platform . OS === "web" ) {
269- const discovery = await this . getDiscoveryEndpoints ( ) ;
270- const request = new AuthSession . AuthRequest ( {
271- clientId : this . config . clientId ,
272- redirectUri : this . config . redirectUri ,
273- responseType : AuthSession . ResponseType . Code ,
274- state : state ,
275- codeChallenge : codeChallenge ,
276- codeChallengeMethod : AuthSession . CodeChallengeMethod . S256 ,
277- } ) ;
278-
279- return await request . promptAsync ( discovery ) ;
280- } else {
281- const result = await WebBrowser . openAuthSessionAsync ( authUrl , this . config . redirectUri ) ;
282-
283- if ( result . type === "success" ) {
284- const params = this . parseCallbackUrl ( result . url ) ;
285- return { type : "success" as const , params } ;
286- }
287-
288- return { type : result . type , params : { } } as { type : string ; params : Record < string , string > } ;
289247 }
290248 }
291249
@@ -348,7 +306,7 @@ export class CalComOAuthService {
348306 }
349307
350308 // Extension: use APIs to avoid CORS
351- if ( this . isBrowserExtension ( ) && window . parent !== window ) {
309+ if ( ! this . isMobileApp ( ) && typeof window !== "undefined" && window . parent !== window ) {
352310 return await this . exchangeTokensViaExtension ( code , state ) ;
353311 }
354312
0 commit comments