|
| 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). |
0 commit comments