react-native-auth-session-plugin
v1.0.1
Published
react-native-auth-session-plugin
Maintainers
Readme
react-native-auth-session-plugin
This React Native plugin enables secure biometric authentication followed by web-based login or logout flows, using native modules on iOS and Android. It's perfect for OAuth services like Auth0, where biometric verification is required before redirecting the user to an authentication session.
Features
- Biometric authentication (Face ID / Touch ID / Fingerprint)
- Secure OAuth login via native browser (ASWebAuthenticationSession / CustomTabsIntent)
- Support for custom callback URL schemes
- Works on both iOS and Android
Installation
npm install react-native-auth-session-plugin1. Link Native Code
Make sure the native modules are added in both the iOS and Android projects.
If you're not using autolinking, run:
npx react-native link react-native-auth-session-pluginUsage
import { NativeModules } from 'react-native';
const { RNAuthSessionPlugin } = NativeModules;
// Login
RNAuthSessionPlugin.login(
'https://your-domain.auth0.com/authorize?...',
'myapp' // callback scheme
).then(url => {
console.log('Redirected back with URL:', url);
}).catch(err => {
console.error('Login error:', err);
});
// Logout
RNAuthSessionPlugin.logout(
'https://your-domain.auth0.com/v2/logout?...',
'myapp'
).then(url => {
console.log('Logout redirect URL:', url);
}).catch(err => {
console.error('Logout error:', err);
});
If your plugin is locally added or manually created, ensure:
- iOS:
RNAuthSessionPlugin.swiftis added to your Xcode project. - Android: Add the Java module in your app’s package structure and register it in
MainApplication.java.
2. iOS Setup
- Update your
Info.plist. - Add your app's custom URL scheme:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string> <!-- Replace with your scheme -->
</array>
</dict>
</array>
CocoaPods
Run:
npx pod-install
3. Android Setup
- Update your
AndroidManifest.xml. - Add an intent filter in your
<activity>(usually insideMainActivity):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" /> <!-- Replace with your scheme -->
</intent-filter>
Permissions
No additional permissions are required, but biometric support depends on the device.
Platform Details
iOS
- Uses LocalAuthentication for biometrics
- Opens URLs via ASWebAuthenticationSession
- The callback scheme is handled securely by the OS
- iOS 13+ required
Android
- Uses BiometricPrompt for biometric check
- Opens URLs using CustomTabsIntent (Chrome Custom Tabs)
- Callback is handled through deep linking (intent filters)
Troubleshooting
- Ensure biometric hardware is available and enrolled.
- Ensure your redirect URI is registered in both the Auth0 dashboard and native app config.
- For Android, ensure Chrome is available (for Custom Tabs).
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
