react-native-oauth-essentials 1.0.2 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +524 -3
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -4,11 +4,533 @@
4
4
  Sign-In, Apple Sign-In, and Password Sign-In**, delivering a **native sign-in experience** with a simple, promise-based
5
5
  API. It's a must-have for every React Native app.
6
6
 
7
+ ## Installation
8
+
9
+ Install the library via npm:
10
+
11
+ ```bash
12
+ npm install react-native-oauth-essentials
13
+ ```
14
+
15
+ ```bash
16
+ yarn add react-native-oauth-essentials
17
+ ```
18
+
7
19
  ## How to use it
8
20
 
9
- [Installation](./installation.md)
21
+ Please jump to our docs website
22
+
23
+ [Docs](https://lucaswitch.github.io/react-native-oauth-essentials/docs/intro)
24
+ [Installation](https://lucaswitch.github.io/react-native-oauth-essentials/docs/installation)
25
+
26
+ ### Platform Support Details
27
+
28
+ This library provides native OAuth implementations with platform-specific behaviors and requirements:
29
+
30
+ #### Google Sign-In
31
+
32
+ **iOS:**
33
+ - **Minimum:** iOS 13+
34
+ - Uses native iOS Google Sign-In SDK
35
+ - Presents native iOS authentication UI
36
+ - No Google Play Services dependency
37
+ - Requires Google OAuth 2.0 Web Client ID from Google Cloud Console
38
+ - Supports One Tap sign-in experience
39
+ - Available: `GOOGLE_ID_SUPPORTED` constant
40
+
41
+ **Android:**
42
+ - **Minimum:** Android 8.0+ (API 26+)
43
+ - Uses Credential Manager API with Google ID provider
44
+ - Requires Google Play Services to be installed and up-to-date
45
+ - Check `GOOGLE_PLAY_SERVICES_SUPPORTED` before using
46
+ - Supports additional options: `authorizedAccounts` and `autoSelectEnabled`
47
+ - Presents native Android credential picker UI
48
+ - Requires Google OAuth 2.0 Web Client ID from Google Cloud Console
49
+ - Available: `GOOGLE_ID_SUPPORTED` constant
50
+
51
+ **Common Features:**
52
+ - Returns standardized `GoogleIdCredentialResult` with user profile data
53
+ - Includes ID token for backend verification
54
+ - User can cancel, returning `CancelledCredentialResult`
55
+
56
+ ---
57
+
58
+ #### Apple Sign-In
59
+
60
+ **iOS:**
61
+ - **Minimum:** iOS 13+
62
+ - Uses native `AuthenticationServices` framework
63
+ - Presents native Apple Sign-In UI sheet
64
+ - Full integration with iOS Keychain
65
+ - Returns `AppleIdCredentialResult` with:
66
+ - ID token and authorization code
67
+ - User identifier (stable across app reinstalls)
68
+ - Email and full name (only on first sign-in)
69
+ - Real user indicator (`likelyReal`)
70
+ - Caches email and fullName for subsequent sign-ins
71
+ - No additional configuration needed
72
+ - Available: `APPLE_ID_SUPPORTED` constant
73
+
74
+ **Android:**
75
+ - **Minimum:** Android 8.0+ (API 26+)
76
+ - Uses browser-based OAuth flow via Chrome Custom Tabs (no native Apple Sign-In on Android)
77
+ - Opens device's default browser with your provided `androidWebUrl`
78
+ - Returns `WebAppleIdCredentialResult` with redirect URL components
79
+ - **Requires backend implementation** to handle OAuth flow
80
+ - You must implement Apple Sign-In REST API on your server
81
+ - See [Apple Sign-In REST API Documentation](https://developer.apple.com/documentation/signinwithapplerestapi)
82
+ - Available: `APPLE_ID_SUPPORTED` constant
83
+
84
+ **Implementation Note:** iOS provides a complete native experience, while Android uses Chrome Custom Tabs to open your OAuth endpoint in the browser, then captures the redirect URL.
85
+
86
+ ---
87
+
88
+ #### Password Sign-In
89
+
90
+ **iOS:**
91
+ - **Minimum:** iOS 12+
92
+ - Uses iOS Keychain Services
93
+ - Integrates with iCloud Keychain for sync across devices
94
+ - Presents native password autofill UI
95
+ - Supports AutoFill in WebViews
96
+ - Available: `PASSWORD_SUPPORTED` constant
97
+
98
+ **Android:**
99
+ - **Minimum:** Android 7.0+ (API 24+)
100
+ - Uses Credential Manager API
101
+ - Integrates with Google Smart Lock for Passwords
102
+ - Can sync credentials across devices via Google account
103
+ - Presents native credential picker UI
104
+ - Supports autofill in WebViews and native forms
105
+ - Available: `PASSWORD_SUPPORTED` constant
106
+
107
+ **Common Features:**
108
+ - `passwordSignIn()` - Saves credentials securely
109
+ - `getPassword()` - Retrieves stored credentials
110
+ - Returns `PasswordCredentialResult` with username and password
111
+ - Can be used alongside biometric authentication
112
+ - Returns `false` if no credentials stored
113
+
114
+ ---
115
+
116
+ #### Hybrid Sign-In
117
+
118
+ **Purpose:** Attempts all available sign-in methods simultaneously to find existing credentials.
119
+
120
+ **iOS:**
121
+ - Checks for: Apple ID, Google ID, and saved passwords
122
+ - Presents unified credential picker if multiple options available
123
+ - Returns first available credential
124
+ - Ideal for app launch to restore previous session
125
+ - Available: `HYBRID_SUPPORTED` constant
126
+
127
+ **Android:**
128
+ - Checks for: Google ID and saved passwords (Apple requires web flow)
129
+ - Uses Credential Manager to aggregate all options
130
+ - Presents native Android credential picker
131
+ - Returns first selected credential
132
+ - Available: `HYBRID_SUPPORTED` constant
133
+
134
+ **Use Case:** Perfect for "Continue with..." screens or automatic sign-in on app start.
135
+
136
+ **Returns:**
137
+ - `GoogleIdCredentialResult`
138
+ - `AppleIdCredentialResult` (iOS only)
139
+ - `PasswordCredentialResult`
140
+ - `CancelledCredentialResult`
141
+
142
+ ---
143
+
144
+ #### Passkeys
145
+
146
+ **iOS:**
147
+ - Uses `AuthenticationServices` framework (iOS 16+)
148
+ - Supports WebAuthn/FIDO2 standard
149
+ - Syncs via iCloud Keychain
150
+ - Presents native passkey creation/selection UI
151
+ - Available: `PASSKEYS_SUPPORTED` constant (iOS 16+)
152
+
153
+ **Android:**
154
+ - Uses Credential Manager API with passkey support (Android 9+ / API 28+)
155
+ - Supports WebAuthn/FIDO2 standard
156
+ - Syncs via Google Password Manager
157
+ - Additional options: `preferImmediatelyAvailableCredentials`, `isConditional`
158
+ - Available: `PASSKEYS_SUPPORTED` constant
159
+
160
+ **Common Features:**
161
+ - Standards-based implementation (WebAuthn)
162
+ - Requires `requestJson` string with `PublicKeyCredentialCreationOptions`
163
+ - Returns `PassKeyCredentialResult` with platform public key credential
164
+ - More secure than passwords (phishing-resistant)
165
+ - Biometric authentication integration
166
+
167
+ ---
168
+
169
+ ### Import
170
+
171
+ ```typescript
172
+ import {
173
+ googleSignIn,
174
+ appleSignIn,
175
+ passwordSignIn,
176
+ getPassword,
177
+ hybridSignIn,
178
+ createPassKey,
179
+ // Constants
180
+ GOOGLE_PLAY_SERVICES_SUPPORTED,
181
+ PASSWORD_SUPPORTED,
182
+ GOOGLE_ID_SUPPORTED,
183
+ APPLE_ID_SUPPORTED,
184
+ HYBRID_SUPPORTED,
185
+ PASSKEYS_SUPPORTED,
186
+ // Types
187
+ type GoogleSignInOptions,
188
+ type PasskeyOptions,
189
+ type GoogleIdCredentialResult,
190
+ type AppleIdCredentialResult,
191
+ type WebAppleIdCredentialResult,
192
+ type PasswordCredentialResult,
193
+ type PassKeyCredentialResult,
194
+ type CancelledCredentialResult,
195
+ CredentialsType,
196
+ CredentialError,
197
+ } from 'react-native-oauth-essentials';
198
+ ```
199
+
200
+ ### Constants
201
+
202
+ Check platform support before using OAuth methods:
203
+
204
+ | Constant | Type | Description |
205
+ |----------|------|-------------|
206
+ | `GOOGLE_PLAY_SERVICES_SUPPORTED` | `boolean` | Google Play Services are available. Always `false` on iOS. |
207
+ | `PASSWORD_SUPPORTED` | `boolean` | Password credential manager is supported on this device. |
208
+ | `GOOGLE_ID_SUPPORTED` | `boolean` | Google Sign-In is supported. **Use this to check if you can use `googleSignIn()`**. |
209
+ | `APPLE_ID_SUPPORTED` | `boolean` | Apple Sign-In is supported on this device. |
210
+ | `HYBRID_SUPPORTED` | `boolean` | Hybrid sign-in is supported (multiple methods at once). |
211
+ | `PASSKEYS_SUPPORTED` | `boolean` | Passkeys are supported on this device. |
212
+
213
+ **Example:**
214
+
215
+ ```typescript
216
+ if (GOOGLE_ID_SUPPORTED) {
217
+ await googleSignIn('YOUR_WEB_CLIENT_ID');
218
+ }
219
+ ```
220
+
221
+ ### Methods
222
+
223
+ #### `googleSignIn(webClientId, options?)`
224
+
225
+ Performs Google Sign-In with native UI.
226
+
227
+ **Parameters:**
228
+ - `webClientId` (string): Your Google OAuth 2.0 web client ID
229
+ - `options` (GoogleSignInOptions, optional): Sign-in configuration
230
+
231
+ **Returns:** `Promise<GoogleIdCredentialResult | CancelledCredentialResult>`
232
+
233
+ **Platform:** Android, iOS (check `GOOGLE_ID_SUPPORTED`)
234
+
235
+ **Example:**
236
+
237
+ ```typescript
238
+ const result = await googleSignIn('YOUR_WEB_CLIENT_ID', {
239
+ authorizedAccounts: true, // Android only
240
+ autoSelectEnabled: false, // Android only
241
+ });
242
+
243
+ if (result.type === CredentialsType.GOOGLE_ID) {
244
+ console.log('User ID:', result.data.id);
245
+ console.log('ID Token:', result.data.idToken);
246
+ console.log('Name:', result.data.displayName);
247
+ }
248
+ ```
249
+
250
+ ---
251
+
252
+ #### `appleSignIn(androidWebUrl?)`
253
+
254
+ Initiates Apple Sign-In process.
255
+
256
+ **Parameters:**
257
+ - `androidWebUrl` (string, optional): Web URL for Android OAuth flow. **Required on Android.**
258
+
259
+ **Returns:** `Promise<AppleIdCredentialResult | WebAppleIdCredentialResult>`
260
+
261
+ **Platform:**
262
+ - iOS: Native Apple Sign-In UI
263
+ - Android: Opens browser with your web URL for OAuth flow
264
+
265
+ **Platform:** Check `APPLE_ID_SUPPORTED`
266
+
267
+ **Example:**
268
+
269
+ ```typescript
270
+ const result = await appleSignIn('https://yourserver.com/apple-signin');
271
+
272
+ if (result.type === CredentialsType.APPLE_ID) {
273
+ // iOS result
274
+ console.log('User:', result.data.user);
275
+ console.log('ID Token:', result.data.idToken);
276
+ console.log('Email:', result.data.email);
277
+ } else if (result.type === CredentialsType.WEB_APPLE_ID) {
278
+ // Android result
279
+ console.log('Redirect URL:', result.data.url);
280
+ }
281
+ ```
282
+
283
+ ---
284
+
285
+ #### `passwordSignIn(username, password)`
10
286
 
11
- [Usage](./usage)
287
+ Saves username/password credentials to the platform's credential manager.
288
+
289
+ **Parameters:**
290
+ - `username` (string): Username to save
291
+ - `password` (string): Password to save
292
+
293
+ **Returns:** `Promise<boolean>`
294
+
295
+ **Platform:** Android, iOS (check `PASSWORD_SUPPORTED`)
296
+
297
+ **Example:**
298
+
299
+ ```typescript
300
+ const saved = await passwordSignIn('user@example.com', 'password123');
301
+ console.log('Credentials saved:', saved);
302
+ ```
303
+
304
+ ---
305
+
306
+ #### `getPassword()`
307
+
308
+ Retrieves stored password credentials.
309
+
310
+ **Returns:** `Promise<false | PasswordCredentialResult>`
311
+
312
+ **Platform:** Android, iOS (check `PASSWORD_SUPPORTED`)
313
+
314
+ **Example:**
315
+
316
+ ```typescript
317
+ const result = await getPassword();
318
+
319
+ if (result && result.type === CredentialsType.PASSWORD) {
320
+ console.log('Username:', result.data.username);
321
+ console.log('Password:', result.data.password);
322
+ } else {
323
+ console.log('No stored password found');
324
+ }
325
+ ```
326
+
327
+ ---
328
+
329
+ #### `hybridSignIn(googleClientId, options?)`
330
+
331
+ Attempts all available sign-in methods at once. Useful on app start to check for existing credentials.
332
+
333
+ **Parameters:**
334
+ - `googleClientId` (string): Your Google OAuth 2.0 web client ID
335
+ - `options` (GoogleSignInOptions, optional): Google sign-in configuration
336
+
337
+ **Returns:** `Promise<AppleIdCredentialResult | GoogleIdCredentialResult | PasswordCredentialResult | CancelledCredentialResult>`
338
+
339
+ **Platform:** Android, iOS (check `HYBRID_SUPPORTED`)
340
+
341
+ **Example:**
342
+
343
+ ```typescript
344
+ const result = await hybridSignIn('YOUR_WEB_CLIENT_ID');
345
+
346
+ switch (result.type) {
347
+ case CredentialsType.GOOGLE_ID:
348
+ console.log('Google user:', result.data.displayName);
349
+ break;
350
+ case CredentialsType.APPLE_ID:
351
+ console.log('Apple user:', result.data.user);
352
+ break;
353
+ case CredentialsType.PASSWORD:
354
+ console.log('Username:', result.data.username);
355
+ break;
356
+ case CredentialsType.CANCELLED:
357
+ console.log('User cancelled');
358
+ break;
359
+ }
360
+ ```
361
+
362
+ ---
363
+
364
+ #### `createPassKey(options)`
365
+
366
+ Creates a new passkey credential.
367
+
368
+ **Parameters:**
369
+ - `options` (PasskeyOptions): Passkey creation configuration
370
+
371
+ **Returns:** `Promise<PassKeyCredentialResult>`
372
+
373
+ **Platform:** Check `PASSKEYS_SUPPORTED`
374
+
375
+ **Example:**
376
+
377
+ ```typescript
378
+ const result = await createPassKey({
379
+ requestJson: JSON.stringify({ /* PublicKeyCredentialCreationOptions */ }),
380
+ preferImmediatelyAvailableCredentials: true, // Android only
381
+ isConditional: false, // Android only
382
+ });
383
+
384
+ if (result.type === CredentialsType.PASSKEY) {
385
+ console.log('Passkey created:', result.data);
386
+ }
387
+ ```
388
+
389
+ ---
390
+
391
+ ### Type Definitions
392
+
393
+ #### `GoogleSignInOptions`
394
+
395
+ ```typescript
396
+ type GoogleSignInOptions = {
397
+ authorizedAccounts?: boolean; // Android only: Filter to authorized accounts
398
+ autoSelectEnabled?: boolean; // Android only: Enable auto-selection
399
+ };
400
+ ```
401
+
402
+ #### `PasskeyOptions`
403
+
404
+ ```typescript
405
+ type PasskeyOptions = {
406
+ requestJson: string; // JSON string of PublicKeyCredentialCreationOptions
407
+ preferImmediatelyAvailableCredentials?: boolean; // Android only
408
+ isConditional?: boolean; // Android only
409
+ };
410
+ ```
411
+
412
+ ---
413
+
414
+ ### Result Types
415
+
416
+ #### `GoogleIdCredentialResult`
417
+
418
+ ```typescript
419
+ type GoogleIdCredentialResult = {
420
+ type: CredentialsType.GOOGLE_ID;
421
+ data: {
422
+ id: string; // User's Google ID
423
+ idToken: string; // JWT ID token
424
+ displayName: string; // Full name
425
+ givenName: string; // First name
426
+ familyName: string; // Last name
427
+ profilePictureUri?: string | null; // Profile picture URL
428
+ phoneNumber?: string | null; // Phone number (if available)
429
+ };
430
+ };
431
+ ```
432
+
433
+ #### `AppleIdCredentialResult`
434
+
435
+ ```typescript
436
+ type AppleIdCredentialResult = {
437
+ type: CredentialsType.APPLE_ID;
438
+ data: {
439
+ idToken: string; // JWT ID token
440
+ authorizationCode: string; // Authorization code
441
+ user: string; // Unique user identifier
442
+ email: string; // User's email
443
+ fullName: string; // Full name
444
+ likelyReal: boolean; // Indicates if user is likely real
445
+ };
446
+ };
447
+ ```
448
+
449
+ #### `WebAppleIdCredentialResult`
450
+
451
+ Android-specific result when using web-based Apple Sign-In:
452
+
453
+ ```typescript
454
+ type WebAppleIdCredentialResult = {
455
+ type: CredentialsType.WEB_APPLE_ID;
456
+ data: {
457
+ url: string; // Full redirect URL
458
+ scheme: string | null; // URL scheme
459
+ host: string | null; // URL host
460
+ path: string | null; // URL path
461
+ query: string | null; // URL query parameters
462
+ };
463
+ };
464
+ ```
465
+
466
+ #### `PasswordCredentialResult`
467
+
468
+ ```typescript
469
+ type PasswordCredentialResult = {
470
+ type: CredentialsType.PASSWORD;
471
+ data: {
472
+ username: string; // Stored username
473
+ password: string; // Stored password
474
+ };
475
+ };
476
+ ```
477
+
478
+ #### `PassKeyCredentialResult`
479
+
480
+ ```typescript
481
+ type PassKeyCredentialResult = {
482
+ type: CredentialsType.PASSKEY;
483
+ data: string; // JSON string of platform public key credential
484
+ };
485
+ ```
486
+
487
+ #### `CancelledCredentialResult`
488
+
489
+ ```typescript
490
+ type CancelledCredentialResult = {
491
+ type: CredentialsType.CANCELLED;
492
+ data: null; // User cancelled the operation
493
+ };
494
+ ```
495
+
496
+ ---
497
+
498
+ ### Credential Types Enum
499
+
500
+ ```typescript
501
+ enum CredentialsType {
502
+ GOOGLE_ID = 'GOOGLE_ID', // Google Sign-In credential
503
+ PASSWORD = 'PASSWORD', // Username/password credential
504
+ APPLE_ID = 'APPLE_ID', // iOS native Apple Sign-In credential
505
+ WEB_APPLE_ID = 'WEB_APPLE_ID', // Android web-based Apple Sign-In credential
506
+ CANCELLED = 'CANCELLED', // User cancelled the sign-in flow
507
+ PASSKEY = 'PASSKEY', // Passkey credential
508
+ }
509
+ ```
510
+
511
+ ---
512
+
513
+ ### Error Codes
514
+
515
+ ```typescript
516
+ enum CredentialError {
517
+ NO_PLAY_SERVICES_ERROR = 'NO_PLAY_SERVICES_ERROR', // Google Play Services unavailable
518
+ NO_ACTIVITY_ERROR = 'NO_ACTIVITY_ERROR', // No Android activity available
519
+ INVALID_RESULT_ERROR = 'INVALID_RESULT_ERROR', // Invalid result from native module
520
+ }
521
+ ```
522
+
523
+ **Error Handling:**
524
+
525
+ ```typescript
526
+ try {
527
+ const result = await googleSignIn('YOUR_WEB_CLIENT_ID');
528
+ } catch (error) {
529
+ if (error.code === CredentialError.NO_PLAY_SERVICES_ERROR) {
530
+ console.error('Google Play Services not available');
531
+ }
532
+ }
533
+ ```
12
534
 
13
535
  ## Short history
14
536
 
@@ -27,4 +549,3 @@ make me want to throw my laptop out the window?
27
549
  ## Philosophy
28
550
 
29
551
  Free forever, up-to-date features, and focused only on the essentials your mobile app really needs.
30
-
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-oauth-essentials",
3
- "version": "1.0.2",
4
- "description": "Essential oauth tools for every app.need.",
3
+ "version": "1.0.5",
4
+ "description": "Essential Auth tools for every app.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
7
7
  "exports": {