Skip to content

Commit 214b01c

Browse files
Off2Racezibs
andauthored
feat: Add a config plugin for Expo 53 with CNG (#1086)
Co-authored-by: Eli Zibin <[email protected]>
1 parent 65591ef commit 214b01c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+9561
-2083
lines changed

.github/workflows/pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- name: Install dependencies
2121
run: yarn install --frozen-lockfile
2222

23+
- name: Build Plugin
24+
run: yarn run build
25+
2326
- name: Lint
2427
run: yarn run lint
2528

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Install dependencies
3535
run: yarn install --frozen-lockfile
3636

37+
- name: Build Plugin
38+
run: yarn run build
39+
3740
- name: Unit Tests
3841
run: yarn test
3942

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,20 @@ node_modules/
4343
npm-debug.log
4444
yarn-error.log
4545

46+
# TypeScript
47+
#
48+
*.tsbuildinfo
49+
4650
# BUCK
4751
buck-out/
4852
\.buckd/
4953
*.keystore
5054

5155
Example/yarn.lock
56+
57+
examples/expo-cng/.expo
58+
examples/expo-cng/ios
59+
examples/expo-cng/android
60+
examples/expo-cng/*.tsbuildinfo
61+
62+

app.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ios": {
3+
"bundleIdentifier": "com.anonymous.rnaa"
4+
}
5+
}

docs/docs/introduction.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,32 @@ try {
3939
}
4040
```
4141

42-
## Setup
42+
## Expo Setup (SDK 53+)
43+
44+
If you're using **Expo with Continuous Native Generation (CNG)**, you can use our config plugin for automatic setup:
45+
46+
```json
47+
{
48+
"expo": {
49+
"plugins": [
50+
[
51+
"react-native-app-auth",
52+
{
53+
"redirectUrls": ["com.yourapp.scheme://oauth"]
54+
}
55+
]
56+
]
57+
}
58+
}
59+
```
60+
61+
Then run `expo prebuild` to generate your iOS and Android projects with the correct OAuth URL scheme configuration.
62+
63+
**📖 [Complete Expo Setup Guide →](./usage/expo-setup)**
64+
65+
## Manual Setup
66+
67+
> **💡 Using Expo?** Check out the [Expo Setup Guide](./usage/expo-setup) for a simpler configuration process.
4368
4469
### iOS Setup
4570

@@ -273,6 +298,8 @@ If you want to support universal links, add the following to `AppDelegate.m` und
273298
274299
### Android Setup
275300
301+
> **💡 Using Expo?** Check out the [Expo Setup Guide](./usage/expo-setup) for automatic configuration.
302+
276303
To setup the Android project, you need to add redirect scheme manifest placeholder:
277304
278305
To [capture the authorization redirect](https://github.com/openid/AppAuth-android#capturing-the-authorization-redirect),

docs/docs/usage/authorization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 2
2+
sidebar_position: 4
33
---
44

55
# Authorization

docs/docs/usage/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 1
2+
sidebar_position: 3
33
---
44

55
# Configuration

docs/docs/usage/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 9
33
---
44

55
# Error Messages

docs/docs/usage/expo-setup.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Expo Setup
6+
7+
React Native App Auth provides seamless integration with Expo through our config plugin, supporting **Expo SDK 53+** with Continuous Native Generation (CNG).
8+
9+
## Prerequisites
10+
11+
- Expo SDK 53 or later
12+
- CNG workflow (not Expo Go)
13+
- `expo prebuild` capability
14+
15+
## Quick Start
16+
17+
### 1. Install the Library
18+
19+
```bash
20+
npm install react-native-app-auth
21+
# or
22+
yarn add react-native-app-auth
23+
```
24+
25+
### 2. Configure the Plugin
26+
27+
Add the plugin to your `app.json` or `app.config.js`:
28+
29+
```json
30+
{
31+
"expo": {
32+
"plugins": [
33+
[
34+
"react-native-app-auth",
35+
{
36+
"redirectUrls": ["com.yourapp.scheme://oauth"]
37+
}
38+
]
39+
]
40+
}
41+
}
42+
```
43+
44+
**Configuration Options:**
45+
46+
- `redirectUrls` (required): Array of OAuth redirect URLs for your app
47+
- The URL scheme (before `://`) will be automatically configured for both iOS and Android
48+
- Example: `"com.myapp://oauth"` → scheme is `com.myapp`
49+
50+
### 3. Generate Native Projects
51+
52+
Run prebuild to generate iOS and Android projects with OAuth configuration:
53+
54+
```bash
55+
npx expo prebuild --clean
56+
```
57+
58+
This automatically:
59+
- **iOS**: Adds URL scheme to `Info.plist` and configures bridging headers
60+
- **Android**: Sets up manifest placeholders in `build.gradle`
61+
62+
### 4. Use the Library
63+
64+
```typescript
65+
import { authorize, AuthConfiguration } from 'react-native-app-auth';
66+
67+
const config: AuthConfiguration = {
68+
issuer: 'https://your-oauth-provider.com',
69+
clientId: 'your-client-id',
70+
redirectUrl: 'com.yourapp.scheme://oauth', // Must match app.json
71+
scopes: ['openid', 'profile', 'email'],
72+
};
73+
74+
// Perform authentication
75+
try {
76+
const result = await authorize(config);
77+
console.log('Access token:', result.accessToken);
78+
} catch (error) {
79+
console.error('Auth error:', error);
80+
}
81+
```
82+
83+
## Validation
84+
85+
After running `expo prebuild`, verify the configuration was applied correctly:
86+
87+
### iOS Configuration
88+
89+
Check that your URL scheme was added to `ios/YourApp/Info.plist`:
90+
91+
```xml
92+
<key>CFBundleURLTypes</key>
93+
<array>
94+
<dict>
95+
<key>CFBundleURLName</key>
96+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
97+
<key>CFBundleURLSchemes</key>
98+
<array>
99+
<string>com.yourapp.scheme</string>
100+
</array>
101+
</dict>
102+
</array>
103+
```
104+
105+
### Android Configuration
106+
107+
Check that the manifest placeholder was added to `android/app/build.gradle`:
108+
109+
```gradle
110+
android {
111+
defaultConfig {
112+
manifestPlaceholders = [
113+
appAuthRedirectScheme: 'com.yourapp.scheme',
114+
]
115+
}
116+
}
117+
```
118+
119+
## TypeScript Support
120+
121+
The plugin is built with TypeScript and provides full type safety. Import types as needed:
122+
123+
```typescript
124+
import {
125+
AuthConfiguration,
126+
AuthorizeResult,
127+
RefreshResult
128+
} from 'react-native-app-auth';
129+
```
130+
131+
## Example App
132+
133+
Check out our working example in [`examples/expo-cng/`](https://github.com/FormidableLabs/react-native-app-auth/tree/main/examples/expo-cng) which demonstrates:
134+
135+
- Complete TypeScript implementation
136+
- Expo config plugin setup
137+
- OAuth flow with Duende IdentityServer demo
138+
- Native project generation validation
139+
140+
## Troubleshooting
141+
142+
### Plugin Not Found
143+
144+
If you see "Package 'react-native-app-auth' does not contain a valid config plugin":
145+
146+
1. Ensure you're using the latest version of the library
147+
2. Clear your cache: `npx expo install --fix`
148+
3. Try `npx expo prebuild --clean` to regenerate projects
149+
150+
### URL Scheme Conflicts
151+
152+
If you have React Navigation deep linking, ensure your OAuth scheme is different:
153+
154+
```json
155+
{
156+
"expo": {
157+
"plugins": [
158+
[
159+
"react-native-app-auth",
160+
{ "redirectUrls": ["com.myapp.auth://oauth"] }
161+
]
162+
]
163+
}
164+
}
165+
```
166+
167+
168+
## Migration from Manual Setup
169+
170+
If you're migrating from manual iOS/Android setup:
171+
172+
1. Remove manual URL scheme configurations from `Info.plist` and `build.gradle`
173+
2. Remove manual AppDelegate modifications (the plugin handles this automatically for Expo SDK 53+)
174+
3. Add the plugin configuration to `app.json`
175+
4. Run `npx expo prebuild --clean`
176+
177+
## Limitations
178+
179+
- **Expo SDK 53+ only**: Earlier versions require [manual setup](../#manual-setup)
180+
- **CNG workflow only**: Expo Go is not supported (OAuth requires native configuration)
181+
- **First-party providers**: Some OAuth providers may require additional native configuration
182+
183+
For advanced use cases or non-Expo projects, see the [Manual Setup Guide](../#manual-setup).

docs/docs/usage/logout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 6
2+
sidebar_position: 8
33
---
44

55
# Logout

0 commit comments

Comments
 (0)