|
13 | 13 | - [Set global headers during initialization](#set-global-headers-during-initialization) |
14 | 14 | - [Using custom headers with Auth0Provider component](#using-custom-headers-with-auth0provider-component) |
15 | 15 | - [Set request-specific headers](#set-request-specific-headers) |
| 16 | +- [Biometric Authentication](#biometric-authentication) |
| 17 | + - [Biometric Policy Types](#biometric-policy-types) |
| 18 | + - [Using with Auth0Provider (Hooks)](#using-with-auth0provider-hooks) |
| 19 | + - [Using with Auth0 Class](#using-with-auth0-class) |
| 20 | + - [Platform-Specific Behavior](#platform-specific-behavior) |
| 21 | + - [Additional Configuration Options](#additional-configuration-options) |
| 22 | + - [Migration from Previous Behavior](#migration-from-previous-behavior) |
16 | 23 | - [Management API (Users)](#management-api-users) |
17 | 24 | - [Patch user with user_metadata](#patch-user-with-user_metadata) |
18 | 25 | - [Get full user profile](#get-full-user-profile) |
@@ -253,6 +260,128 @@ auth0.auth |
253 | 260 | .catch(console.error); |
254 | 261 | ``` |
255 | 262 |
|
| 263 | +## Biometric Authentication |
| 264 | + |
| 265 | +> **Platform Support:** Native only (iOS/Android) |
| 266 | +
|
| 267 | +Configure biometric authentication to protect credential access. The SDK supports four biometric policies that control when biometric prompts are shown. |
| 268 | + |
| 269 | +### Biometric Policy Types |
| 270 | + |
| 271 | +- **`BiometricPolicy.default`**: System-managed behavior. Reuses the same `LAContext` on iOS, allowing the system to optimize prompt frequency. May skip the biometric prompt if authentication was recently successful. |
| 272 | + |
| 273 | +- **`BiometricPolicy.always`**: Always requires biometric authentication on every credential access. Creates a fresh `LAContext` on iOS and uses the "Always" policy on Android to ensure a new prompt is shown. |
| 274 | + |
| 275 | +- **`BiometricPolicy.session`**: Requires biometric authentication only once per session. After successful authentication, credentials can be accessed without prompting for the specified timeout duration. |
| 276 | + |
| 277 | +- **`BiometricPolicy.appLifecycle`**: Similar to session policy, but persists for the app's lifecycle. Session remains valid until the app restarts or `clearCredentials()` is called. Default timeout is 1 hour (3600 seconds). |
| 278 | + |
| 279 | +### Using with Auth0Provider (Hooks) |
| 280 | + |
| 281 | +```jsx |
| 282 | +import { Auth0Provider, BiometricPolicy } from 'react-native-auth0'; |
| 283 | + |
| 284 | +function App() { |
| 285 | + return ( |
| 286 | + <Auth0Provider |
| 287 | + domain="YOUR_AUTH0_DOMAIN" |
| 288 | + clientId="YOUR_CLIENT_ID" |
| 289 | + localAuthenticationOptions={{ |
| 290 | + title: 'Authenticate to access credentials', |
| 291 | + // Option 1: Default policy (system-managed, backward compatible) |
| 292 | + biometricPolicy: BiometricPolicy.default, |
| 293 | + |
| 294 | + // Option 2: Always require biometric authentication |
| 295 | + // biometricPolicy: BiometricPolicy.always, |
| 296 | + |
| 297 | + // Option 3: Session-based (5 minutes) |
| 298 | + // biometricPolicy: BiometricPolicy.session, |
| 299 | + // biometricTimeout: 300, |
| 300 | + |
| 301 | + // Option 4: App lifecycle (1 hour) |
| 302 | + // biometricPolicy: BiometricPolicy.appLifecycle, |
| 303 | + // biometricTimeout: 3600, |
| 304 | + }} |
| 305 | + > |
| 306 | + <YourApp /> |
| 307 | + </Auth0Provider> |
| 308 | + ); |
| 309 | +} |
| 310 | +``` |
| 311 | + |
| 312 | +### Using with Auth0 Class |
| 313 | + |
| 314 | +```js |
| 315 | +import Auth0, { BiometricPolicy } from 'react-native-auth0'; |
| 316 | + |
| 317 | +const auth0 = new Auth0({ |
| 318 | + domain: 'YOUR_AUTH0_DOMAIN', |
| 319 | + clientId: 'YOUR_AUTH0_CLIENT_ID', |
| 320 | + localAuthenticationOptions: { |
| 321 | + title: 'Authenticate to access credentials', |
| 322 | + biometricPolicy: BiometricPolicy.session, |
| 323 | + biometricTimeout: 300, // 5 minutes |
| 324 | + }, |
| 325 | +}); |
| 326 | + |
| 327 | +// Get credentials - will prompt for biometric authentication based on policy |
| 328 | +const credentials = await auth0.credentialsManager.getCredentials(); |
| 329 | +``` |
| 330 | + |
| 331 | +### Platform-Specific Behavior |
| 332 | + |
| 333 | +#### Android |
| 334 | + |
| 335 | +- `BiometricPolicy.default` and `BiometricPolicy.always` both map to the Android SDK's "Always" policy |
| 336 | +- Uses `BiometricPrompt` for authentication |
| 337 | +- Session state is stored in memory and cleared on app restart |
| 338 | + |
| 339 | +#### iOS |
| 340 | + |
| 341 | +- `BiometricPolicy.default` reuses the same `LAContext`, allowing the system to manage prompt frequency |
| 342 | +- `BiometricPolicy.always`, `session`, and `appLifecycle` create a fresh `LAContext` to ensure reliable prompts |
| 343 | +- Uses Face ID or Touch ID based on device capabilities |
| 344 | +- Session state is thread-safe and managed in memory |
| 345 | + |
| 346 | +### Additional Configuration Options |
| 347 | + |
| 348 | +You can combine biometric policies with other authentication options: |
| 349 | + |
| 350 | +```js |
| 351 | +import Auth0, { |
| 352 | + BiometricPolicy, |
| 353 | + LocalAuthenticationLevel, |
| 354 | + LocalAuthenticationStrategy, |
| 355 | +} from 'react-native-auth0'; |
| 356 | + |
| 357 | +const auth0 = new Auth0({ |
| 358 | + domain: 'YOUR_AUTH0_DOMAIN', |
| 359 | + clientId: 'YOUR_AUTH0_CLIENT_ID', |
| 360 | + localAuthenticationOptions: { |
| 361 | + title: 'Authenticate', |
| 362 | + subtitle: 'Please authenticate to continue', // Android only |
| 363 | + description: 'We need to verify your identity', // Android only |
| 364 | + cancelTitle: 'Cancel', |
| 365 | + fallbackTitle: 'Use Passcode', // iOS only |
| 366 | + |
| 367 | + // Biometric policy |
| 368 | + biometricPolicy: BiometricPolicy.session, |
| 369 | + biometricTimeout: 300, |
| 370 | + |
| 371 | + // iOS: Choose authentication policy |
| 372 | + evaluationPolicy: LocalAuthenticationStrategy.deviceOwnerWithBiometrics, |
| 373 | + |
| 374 | + // Android: Set authentication strength |
| 375 | + authenticationLevel: LocalAuthenticationLevel.strong, |
| 376 | + deviceCredentialFallback: true, // Allow PIN/pattern/password fallback |
| 377 | + }, |
| 378 | +}); |
| 379 | +``` |
| 380 | + |
| 381 | +### Migration from Previous Behavior |
| 382 | + |
| 383 | +If you were not explicitly configuring biometric authentication before, the new `BiometricPolicy.default` maintains backward-compatible behavior. To enforce stricter biometric requirements, switch to `BiometricPolicy.always`. |
| 384 | + |
256 | 385 | ## Management API (Users) |
257 | 386 |
|
258 | 387 | ### Patch user with user_metadata |
|
0 commit comments