From 90cfdae5b5729bb36e1db78fbc4dd6a41710277b Mon Sep 17 00:00:00 2001 From: Subhankar Maiti Date: Tue, 2 Sep 2025 16:05:16 +0530 Subject: [PATCH] feat(android): add pathPrefix to Android manifest for callback handling --- .../__snapshots__/withAuth0-test.ts.snap | 6 ++ src/plugin/__tests__/withAuth0-test.ts | 63 +++++++++++++++++++ src/plugin/withAuth0.ts | 1 + 3 files changed, 70 insertions(+) diff --git a/src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap b/src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap index 2a77de46..4f4b359d 100644 --- a/src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap +++ b/src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap @@ -60,12 +60,14 @@ exports[`addAndroidAuth0Manifest with multiple domains and schemes should have t { "$": { "android:host": "sample.us.auth0.com", + "android:pathPrefix": "/android/com.sample.application/callback", "android:scheme": "com.sample.us.auth0", }, }, { "$": { "android:host": "sample.eu.auth0.com", + "android:pathPrefix": "/android/com.sample.application/callback", "android:scheme": "com.sample.eu.auth0", }, }, @@ -138,12 +140,14 @@ exports[`addAndroidAuth0Manifest with multiple domains should have that value an { "$": { "android:host": "sample.us.auth0.com", + "android:pathPrefix": "/android/com.sample.application/callback", "android:scheme": "com.sample.application.auth0", }, }, { "$": { "android:host": "sample.eu.auth0.com", + "android:pathPrefix": "/android/com.sample.application/callback", "android:scheme": "com.sample.application.auth0", }, }, @@ -216,6 +220,7 @@ exports[`addAndroidAuth0Manifest with scheme should have that value 1`] = ` { "$": { "android:host": "sample.auth0.com", + "android:pathPrefix": "/android/undefined/callback", "android:scheme": "com.sample.application", }, }, @@ -288,6 +293,7 @@ exports[`addAndroidAuth0Manifest without scheme should have package name 1`] = ` { "$": { "android:host": "sample.auth0.com", + "android:pathPrefix": "/android/com.auth0.sample/callback", "android:scheme": "com.auth0.sample.auth0", }, }, diff --git a/src/plugin/__tests__/withAuth0-test.ts b/src/plugin/__tests__/withAuth0-test.ts index 9a038251..9863f7df 100644 --- a/src/plugin/__tests__/withAuth0-test.ts +++ b/src/plugin/__tests__/withAuth0-test.ts @@ -149,6 +149,69 @@ describe(addAndroidAuth0Manifest, () => { } expect(check()).toMatchSnapshot(); }); + + it(`should correctly add pathPrefix to Android manifest with application ID`, () => { + const config = getConfig(); + const result = addAndroidAuth0Manifest( + [{ domain: 'sample.auth0.com' }], + config, + 'com.auth0.testapp' + ); + + // Access the RedirectActivity to check if the pathPrefix is correctly added + const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow( + result.modResults + ); + const redirectActivity = mainApplication.activity?.find( + (activity) => + activity.$['android:name'] === + 'com.auth0.android.provider.RedirectActivity' + ); + + const intentFilter = redirectActivity?.['intent-filter']?.[0]; + const dataElement = intentFilter?.data?.[0]; + + expect(dataElement).toBeDefined(); + expect(dataElement?.$['android:pathPrefix']).toBe( + '/android/com.auth0.testapp/callback' + ); + expect(dataElement?.$['android:scheme']).toBe('com.auth0.testapp.auth0'); + expect(dataElement?.$['android:host']).toBe('sample.auth0.com'); + }); + + it(`should correctly add pathPrefix to Android manifest with custom scheme`, () => { + const config = getConfig(); + const result = addAndroidAuth0Manifest( + [ + { + domain: 'sample.auth0.com', + customScheme: 'com.custom.scheme', + }, + ], + config, + 'com.auth0.testapp' + ); + + // Access the RedirectActivity to check if the pathPrefix is correctly added + const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow( + result.modResults + ); + const redirectActivity = mainApplication.activity?.find( + (activity) => + activity.$['android:name'] === + 'com.auth0.android.provider.RedirectActivity' + ); + + const intentFilter = redirectActivity?.['intent-filter']?.[0]; + const dataElement = intentFilter?.data?.[0]; + + expect(dataElement).toBeDefined(); + expect(dataElement?.$['android:pathPrefix']).toBe( + '/android/com.auth0.testapp/callback' + ); + expect(dataElement?.$['android:scheme']).toBe('com.custom.scheme'); + expect(dataElement?.$['android:host']).toBe('sample.auth0.com'); + }); }); describe(addIOSAuth0ConfigInInfoPList, () => { diff --git a/src/plugin/withAuth0.ts b/src/plugin/withAuth0.ts index 9ee1176c..62cf034b 100644 --- a/src/plugin/withAuth0.ts +++ b/src/plugin/withAuth0.ts @@ -88,6 +88,7 @@ export const addAndroidAuth0Manifest = ( const dataElement = { $: { 'android:scheme': auth0Scheme, + 'android:pathPrefix': `/android/${applicationId}/callback`, 'android:host': config.domain, }, };