Skip to content

Commit f10220d

Browse files
committed
Add expo plugin to support AppAuth in app delegate
1 parent 9d43050 commit f10220d

4 files changed

Lines changed: 173 additions & 4 deletions

File tree

examples/onetrust/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"favicon": "./assets/favicon.png"
2727
},
2828
"plugins": [
29-
"react-native-app-auth"
29+
"react-native-app-auth",
30+
"@contentpass/react-native-contentpass-cmp-onetrust"
3031
]
3132
}
3233
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const { withDangerousMod } = require("@expo/config-plugins");
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
/**
6+
* Fills gaps left by react-native-app-auth's Expo config plugin on SDK 55+.
7+
*
8+
* The upstream plugin hardcodes "public class AppDelegate" in its string
9+
* replacements, but Expo SDK 55 generates "class AppDelegate" (without
10+
* "public"), causing the replacements to silently fail. This plugin runs
11+
* via withDangerousMod (after all mods) and patches whatever is still missing.
12+
*
13+
* Upstream issue: https://github.com/FormidableLabs/react-native-app-auth/issues/1110
14+
* Upstream fix (pending): https://github.com/FormidableLabs/react-native-app-auth/pull/1109
15+
*/
16+
function withAppAuthProtocol(config) {
17+
return withDangerousMod(config, [
18+
"ios",
19+
(config) => {
20+
const appDelegatePath = path.join(
21+
config.modRequest.platformProjectRoot,
22+
config.modRequest.projectName,
23+
"AppDelegate.swift"
24+
);
25+
26+
if (!fs.existsSync(appDelegatePath)) {
27+
return config;
28+
}
29+
30+
let contents = fs.readFileSync(appDelegatePath, "utf-8");
31+
let modified = false;
32+
33+
// 1. Add protocol conformance if missing
34+
if (!contents.includes("RNAppAuthAuthorizationFlowManager")) {
35+
contents = contents.replace(
36+
/class AppDelegate:\s*ExpoAppDelegate\s*\{/,
37+
"class AppDelegate: ExpoAppDelegate, RNAppAuthAuthorizationFlowManager {"
38+
);
39+
modified = true;
40+
}
41+
42+
// 2. Add delegate property if missing
43+
if (!contents.includes("authorizationFlowManagerDelegate")) {
44+
contents = contents.replace(
45+
/(var reactNativeFactory: RCTReactNativeFactory\?)/,
46+
"$1\n\n public weak var authorizationFlowManagerDelegate: RNAppAuthAuthorizationFlowManagerDelegate?"
47+
);
48+
modified = true;
49+
}
50+
51+
// 3. Add URL-handling delegate check if missing
52+
if (!contents.includes("resumeExternalUserAgentFlow")) {
53+
const authFlowCheck =
54+
" if let authorizationFlowManagerDelegate = self.authorizationFlowManagerDelegate {\n" +
55+
" if authorizationFlowManagerDelegate.resumeExternalUserAgentFlow(with: url) {\n" +
56+
" return true\n" +
57+
" }\n" +
58+
" }\n";
59+
contents = contents.replace(
60+
/(return super\.application\(app, open: url, options: options\))/,
61+
authFlowCheck + " $1"
62+
);
63+
modified = true;
64+
}
65+
66+
if (modified) {
67+
fs.writeFileSync(appDelegatePath, contents);
68+
}
69+
70+
return config;
71+
},
72+
]);
73+
}
74+
75+
module.exports = withAppAuthProtocol;

packages/react-native-contentpass-cmp-onetrust/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
"types": "./lib/typescript/react-native-contentpass-cmp-onetrust/src/index.d.ts",
1616
"default": "./lib/commonjs/index.js"
1717
}
18-
}
18+
},
19+
"./app.plugin": "./app.plugin.js",
20+
"./app.plugin.js": "./app.plugin.js"
1921
},
2022
"types": "./lib/typescript/react-native-contentpass-cmp-onetrust/src/index.d.ts",
2123
"files": [
2224
"lib",
25+
"app.plugin.js",
2326
"!**/*.test.ts",
2427
"!**/*.test.tsx",
2528
"!**/__tests__",
@@ -54,10 +57,17 @@
5457
},
5558
"peerDependencies": {
5659
"@contentpass/react-native-contentpass": "*",
60+
"@expo/config-plugins": ">=9.0.0",
5761
"react-native-onetrust-cmp": "*"
5862
},
63+
"peerDependenciesMeta": {
64+
"@expo/config-plugins": {
65+
"optional": true
66+
}
67+
},
5968
"devDependencies": {
6069
"@contentpass/react-native-contentpass": "workspace:*",
70+
"@expo/config-plugins": "^9.0.0",
6171
"@react-native-community/cli": "20.1.1",
6272
"@react-native/babel-preset": "0.83.1",
6373
"@types/jest": "^30.0.0",

yarn.lock

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ __metadata:
5353
languageName: node
5454
linkType: hard
5555

56+
"@babel/code-frame@npm:~7.10.4":
57+
version: 7.10.4
58+
resolution: "@babel/code-frame@npm:7.10.4"
59+
dependencies:
60+
"@babel/highlight": ^7.10.4
61+
checksum: feb4543c8a509fe30f0f6e8d7aa84f82b41148b963b826cd330e34986f649a85cb63b2f13dd4effdf434ac555d16f14940b8ea5f4433297c2f5ff85486ded019
62+
languageName: node
63+
linkType: hard
64+
5665
"@babel/compat-data@npm:^7.22.6, @babel/compat-data@npm:^7.25.9, @babel/compat-data@npm:^7.26.0":
5766
version: 7.26.3
5867
resolution: "@babel/compat-data@npm:7.26.3"
@@ -548,6 +557,18 @@ __metadata:
548557
languageName: node
549558
linkType: hard
550559

560+
"@babel/highlight@npm:^7.10.4":
561+
version: 7.25.9
562+
resolution: "@babel/highlight@npm:7.25.9"
563+
dependencies:
564+
"@babel/helper-validator-identifier": ^7.25.9
565+
chalk: ^2.4.2
566+
js-tokens: ^4.0.0
567+
picocolors: ^1.0.0
568+
checksum: a6e0ac0a1c4bef7401915ca3442ab2b7ae4adf360262ca96b91396bfb9578abb28c316abf5e34460b780696db833b550238d9256bdaca60fade4ba7a67645064
569+
languageName: node
570+
linkType: hard
571+
551572
"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.25.3, @babel/parser@npm:^7.25.9, @babel/parser@npm:^7.26.0, @babel/parser@npm:^7.26.3":
552573
version: 7.26.3
553574
resolution: "@babel/parser@npm:7.26.3"
@@ -3203,6 +3224,7 @@ __metadata:
32033224
resolution: "@contentpass/react-native-contentpass-cmp-onetrust@workspace:packages/react-native-contentpass-cmp-onetrust"
32043225
dependencies:
32053226
"@contentpass/react-native-contentpass": "workspace:*"
3227+
"@expo/config-plugins": ^9.0.0
32063228
"@react-native-community/cli": 20.1.1
32073229
"@react-native/babel-preset": 0.83.1
32083230
"@types/jest": ^30.0.0
@@ -3216,7 +3238,11 @@ __metadata:
32163238
typescript: ^5.9.3
32173239
peerDependencies:
32183240
"@contentpass/react-native-contentpass": "*"
3241+
"@expo/config-plugins": ">=9.0.0"
32193242
react-native-onetrust-cmp: "*"
3243+
peerDependenciesMeta:
3244+
"@expo/config-plugins":
3245+
optional: true
32203246
languageName: unknown
32213247
linkType: soft
32223248

@@ -3519,6 +3545,28 @@ __metadata:
35193545
languageName: node
35203546
linkType: hard
35213547

3548+
"@expo/config-plugins@npm:^9.0.0":
3549+
version: 9.1.7
3550+
resolution: "@expo/config-plugins@npm:9.1.7"
3551+
dependencies:
3552+
"@expo/config-types": ^53.0.0
3553+
"@expo/json-file": ~9.1.3
3554+
"@expo/plist": ^0.3.3
3555+
"@expo/sdk-runtime-versions": ^1.0.0
3556+
chalk: ^4.1.2
3557+
debug: ^4.3.5
3558+
getenv: ^1.0.0
3559+
glob: ^10.4.2
3560+
resolve-from: ^5.0.0
3561+
semver: ^7.5.4
3562+
slash: ^3.0.0
3563+
slugify: ^1.6.6
3564+
xcode: ^3.0.1
3565+
xml2js: 0.6.0
3566+
checksum: 8eba71d88100c1c0572307256900b10b8375d3fac2496d0486e7d9d66d8dc4a979e907a12e5dfb3a7811871bef4ba5cc906559ceb371517b7308bd909f17730a
3567+
languageName: node
3568+
linkType: hard
3569+
35223570
"@expo/config-plugins@npm:~55.0.7":
35233571
version: 55.0.7
35243572
resolution: "@expo/config-plugins@npm:55.0.7"
@@ -3540,6 +3588,13 @@ __metadata:
35403588
languageName: node
35413589
linkType: hard
35423590

3591+
"@expo/config-types@npm:^53.0.0":
3592+
version: 53.0.5
3593+
resolution: "@expo/config-types@npm:53.0.5"
3594+
checksum: 3f4db2d9590c18fb178f7395739ee2200512ad7c253655be0bad7f3f0d948df89c1c69c7e949f202faa98eecbd4bbae3edfcf9264f97f49d4f7087f85c68af5d
3595+
languageName: node
3596+
linkType: hard
3597+
35433598
"@expo/config-types@npm:^55.0.5":
35443599
version: 55.0.5
35453600
resolution: "@expo/config-types@npm:55.0.5"
@@ -3661,6 +3716,16 @@ __metadata:
36613716
languageName: node
36623717
linkType: hard
36633718

3719+
"@expo/json-file@npm:~9.1.3":
3720+
version: 9.1.5
3721+
resolution: "@expo/json-file@npm:9.1.5"
3722+
dependencies:
3723+
"@babel/code-frame": ~7.10.4
3724+
json5: ^2.2.3
3725+
checksum: beedf9077dcff476acd895219e391e18079d3c375e58bb4902a4147fffe9774e11d4d1607cfc3488f8e9daec2c30e4d7c17c46fb701035ad7aabacaaf6d465b4
3726+
languageName: node
3727+
linkType: hard
3728+
36643729
"@expo/local-build-cache-provider@npm:55.0.7":
36653730
version: 55.0.7
36663731
resolution: "@expo/local-build-cache-provider@npm:55.0.7"
@@ -3764,6 +3829,17 @@ __metadata:
37643829
languageName: node
37653830
linkType: hard
37663831

3832+
"@expo/plist@npm:^0.3.3":
3833+
version: 0.3.5
3834+
resolution: "@expo/plist@npm:0.3.5"
3835+
dependencies:
3836+
"@xmldom/xmldom": ^0.8.8
3837+
base64-js: ^1.2.3
3838+
xmlbuilder: ^15.1.1
3839+
checksum: b78fda216c63ab553b24e75e87021be09155cd16e0fcf666846c1a5ea33defa2d7f631ea504788a8e2c5d67b5f59b35d6a46fa79a244d5890ee26870caffec22
3840+
languageName: node
3841+
linkType: hard
3842+
37673843
"@expo/plist@npm:^0.5.2":
37683844
version: 0.5.2
37693845
resolution: "@expo/plist@npm:0.5.2"
@@ -6640,7 +6716,7 @@ __metadata:
66406716
languageName: node
66416717
linkType: hard
66426718

6643-
"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1":
6719+
"base64-js@npm:^1.2.3, base64-js@npm:^1.3.1, base64-js@npm:^1.5.1":
66446720
version: 1.5.1
66456721
resolution: "base64-js@npm:1.5.1"
66466722
checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005
@@ -8978,6 +9054,13 @@ __metadata:
89789054
languageName: node
89799055
linkType: hard
89809056

9057+
"getenv@npm:^1.0.0":
9058+
version: 1.0.0
9059+
resolution: "getenv@npm:1.0.0"
9060+
checksum: 19ae5cad603a1cf1bcb8fa3bed48e00d062eb0572a4404c02334b67f3b3499f238383082b064bb42515e9e25c2b08aef1a3e3d2b6852347721aa8b174825bd56
9061+
languageName: node
9062+
linkType: hard
9063+
89819064
"getenv@npm:^2.0.0":
89829065
version: 2.0.0
89839066
resolution: "getenv@npm:2.0.0"
@@ -9032,7 +9115,7 @@ __metadata:
90329115
languageName: node
90339116
linkType: hard
90349117

9035-
"glob@npm:^10.5.0":
9118+
"glob@npm:^10.4.2, glob@npm:^10.5.0":
90369119
version: 10.5.0
90379120
resolution: "glob@npm:10.5.0"
90389121
dependencies:

0 commit comments

Comments
 (0)