Skip to content

Commit 967dfa5

Browse files
fix(android): add pathPrefix to Android manifest for proper App Links functionality (#1288)
1 parent 8f097ec commit 967dfa5

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/plugin/__tests__/__snapshots__/withAuth0-test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ exports[`addAndroidAuth0Manifest with multiple domains and schemes should have t
6060
{
6161
"$": {
6262
"android:host": "sample.us.auth0.com",
63+
"android:pathPrefix": "/android/com.sample.application/callback",
6364
"android:scheme": "com.sample.us.auth0",
6465
},
6566
},
6667
{
6768
"$": {
6869
"android:host": "sample.eu.auth0.com",
70+
"android:pathPrefix": "/android/com.sample.application/callback",
6971
"android:scheme": "com.sample.eu.auth0",
7072
},
7173
},
@@ -138,12 +140,14 @@ exports[`addAndroidAuth0Manifest with multiple domains should have that value an
138140
{
139141
"$": {
140142
"android:host": "sample.us.auth0.com",
143+
"android:pathPrefix": "/android/com.sample.application/callback",
141144
"android:scheme": "com.sample.application.auth0",
142145
},
143146
},
144147
{
145148
"$": {
146149
"android:host": "sample.eu.auth0.com",
150+
"android:pathPrefix": "/android/com.sample.application/callback",
147151
"android:scheme": "com.sample.application.auth0",
148152
},
149153
},
@@ -216,6 +220,7 @@ exports[`addAndroidAuth0Manifest with scheme should have that value 1`] = `
216220
{
217221
"$": {
218222
"android:host": "sample.auth0.com",
223+
"android:pathPrefix": "/android/undefined/callback",
219224
"android:scheme": "com.sample.application",
220225
},
221226
},
@@ -288,6 +293,7 @@ exports[`addAndroidAuth0Manifest without scheme should have package name 1`] = `
288293
{
289294
"$": {
290295
"android:host": "sample.auth0.com",
296+
"android:pathPrefix": "/android/com.auth0.sample/callback",
291297
"android:scheme": "com.auth0.sample.auth0",
292298
},
293299
},

src/plugin/__tests__/withAuth0-test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,69 @@ describe(addAndroidAuth0Manifest, () => {
149149
}
150150
expect(check()).toMatchSnapshot();
151151
});
152+
153+
it(`should correctly add pathPrefix to Android manifest with application ID`, () => {
154+
const config = getConfig();
155+
const result = addAndroidAuth0Manifest(
156+
[{ domain: 'sample.auth0.com' }],
157+
config,
158+
'com.auth0.testapp'
159+
);
160+
161+
// Access the RedirectActivity to check if the pathPrefix is correctly added
162+
const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(
163+
result.modResults
164+
);
165+
const redirectActivity = mainApplication.activity?.find(
166+
(activity) =>
167+
activity.$['android:name'] ===
168+
'com.auth0.android.provider.RedirectActivity'
169+
);
170+
171+
const intentFilter = redirectActivity?.['intent-filter']?.[0];
172+
const dataElement = intentFilter?.data?.[0];
173+
174+
expect(dataElement).toBeDefined();
175+
expect(dataElement?.$['android:pathPrefix']).toBe(
176+
'/android/com.auth0.testapp/callback'
177+
);
178+
expect(dataElement?.$['android:scheme']).toBe('com.auth0.testapp.auth0');
179+
expect(dataElement?.$['android:host']).toBe('sample.auth0.com');
180+
});
181+
182+
it(`should correctly add pathPrefix to Android manifest with custom scheme`, () => {
183+
const config = getConfig();
184+
const result = addAndroidAuth0Manifest(
185+
[
186+
{
187+
domain: 'sample.auth0.com',
188+
customScheme: 'com.custom.scheme',
189+
},
190+
],
191+
config,
192+
'com.auth0.testapp'
193+
);
194+
195+
// Access the RedirectActivity to check if the pathPrefix is correctly added
196+
const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(
197+
result.modResults
198+
);
199+
const redirectActivity = mainApplication.activity?.find(
200+
(activity) =>
201+
activity.$['android:name'] ===
202+
'com.auth0.android.provider.RedirectActivity'
203+
);
204+
205+
const intentFilter = redirectActivity?.['intent-filter']?.[0];
206+
const dataElement = intentFilter?.data?.[0];
207+
208+
expect(dataElement).toBeDefined();
209+
expect(dataElement?.$['android:pathPrefix']).toBe(
210+
'/android/com.auth0.testapp/callback'
211+
);
212+
expect(dataElement?.$['android:scheme']).toBe('com.custom.scheme');
213+
expect(dataElement?.$['android:host']).toBe('sample.auth0.com');
214+
});
152215
});
153216

154217
describe(addIOSAuth0ConfigInInfoPList, () => {

src/plugin/withAuth0.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const addAndroidAuth0Manifest = (
8888
const dataElement = {
8989
$: {
9090
'android:scheme': auth0Scheme,
91+
'android:pathPrefix': `/android/${applicationId}/callback`,
9192
'android:host': config.domain,
9293
},
9394
};

0 commit comments

Comments
 (0)