react-native-credentials-manager 0.5.3 → 0.6.0

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 (36) hide show
  1. package/README.md +192 -1
  2. package/android/build.gradle +6 -5
  3. package/android/generated/java/com/credentialsmanager/NativeCredentialsManagerSpec.java +5 -1
  4. package/android/generated/jni/RNCredentialsManagerSpec-generated.cpp +7 -1
  5. package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI-generated.cpp +8 -2
  6. package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI.h +151 -3
  7. package/android/src/main/java/com/credentialsmanager/handlers/CredentialHandler.kt +35 -21
  8. package/android/src/newarch/java/com/credentialsmanager/CredentialsManagerModule.kt +28 -1
  9. package/android/src/oldarch/java/com/credentialsmanager/CredentialsManagerModule.kt +30 -1
  10. package/ios/CredentialsManager.h +8 -2
  11. package/ios/CredentialsManager.mm +396 -4
  12. package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec-generated.mm +14 -1
  13. package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec.h +38 -1
  14. package/ios/generated/RNCredentialsManagerSpecJSI-generated.cpp +8 -2
  15. package/ios/generated/RNCredentialsManagerSpecJSI.h +151 -3
  16. package/lib/commonjs/NativeCredentialsManager.js +6 -0
  17. package/lib/commonjs/NativeCredentialsManager.js.map +1 -1
  18. package/lib/commonjs/index.js +50 -3
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/NativeCredentialsManager.js +13 -0
  21. package/lib/module/NativeCredentialsManager.js.map +1 -1
  22. package/lib/module/index.js +49 -3
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts +49 -7
  25. package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/src/index.d.ts +10 -4
  27. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  28. package/lib/typescript/module/src/NativeCredentialsManager.d.ts +49 -7
  29. package/lib/typescript/module/src/NativeCredentialsManager.d.ts.map +1 -1
  30. package/lib/typescript/module/src/index.d.ts +10 -4
  31. package/lib/typescript/module/src/index.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/react-native-credentials-manager.podspec +4 -1
  34. package/react-native.config.js +0 -1
  35. package/src/NativeCredentialsManager.ts +67 -8
  36. package/src/index.tsx +82 -5
@@ -1,19 +1,25 @@
1
- import type { Credential, GoogleCredential, SignInOption } from './NativeCredentialsManager';
1
+ import type { Credential, GoogleCredential, AppleCredential, SignInOption } from './NativeCredentialsManager';
2
2
  type GoogleSignInParams = {
3
3
  nonce?: string;
4
4
  serverClientId: string;
5
5
  autoSelectEnabled?: boolean;
6
6
  };
7
+ type AppleSignInParams = {
8
+ nonce?: string;
9
+ requestedScopes?: ('fullName' | 'email')[];
10
+ };
7
11
  export declare function signUpWithPasskeys(requestJson: Object, preferImmediatelyAvailableCredentials?: boolean): Promise<Object>;
8
12
  export declare function signUpWithPassword({ username, password, }: {
9
13
  username: string;
10
14
  password: string;
11
- }): void;
15
+ }): Promise<Object>;
12
16
  export declare function signIn(options: SignInOption[], params: {
13
17
  passkeys?: Object;
14
18
  googleSignIn?: GoogleSignInParams;
19
+ appleSignIn?: AppleSignInParams;
15
20
  }): Promise<Credential>;
16
- export declare function signUpWithGoogle(params: GoogleSignInParams): Promise<GoogleCredential>;
21
+ export declare function signUpWithGoogle(params: GoogleSignInParams): Promise<GoogleCredential | AppleCredential>;
22
+ export declare function signUpWithApple(params?: AppleSignInParams): Promise<AppleCredential>;
17
23
  export declare function signOut(): Promise<null>;
18
- export {};
24
+ export type { Credential, GoogleCredential, AppleCredential, SignInOption, GoogleSignInParams, AppleSignInParams, };
19
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,4BAA4B,CAAC;AAEpC,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,qCAAqC,GAAE,OAAe,GACrD,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,QAEA;AAED,wBAAgB,MAAM,CACpB,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,EAAE;IACN,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CASrB;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED,wBAAgB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,CAAC,UAAU,GAAG,OAAO,CAAC,EAAE,CAAC;CAC5C,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,qCAAqC,GAAE,OAAe,GACrD,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAWlB;AAED,wBAAgB,MAAM,CACpB,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,EAAE;IACN,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,GACA,OAAO,CAAC,UAAU,CAAC,CAgCrB;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,gBAAgB,GAAG,eAAe,CAAC,CAe7C;AAED,wBAAgB,eAAe,CAC7B,MAAM,GAAE,iBAAsB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAc1B;AAED,wBAAgB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvC;AAGD,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,GAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-credentials-manager",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "A React Native library that implements the Credential Manager API for Android. This library allows you to manage passwords and passkeys in your React Native applications.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -11,12 +11,15 @@ Pod::Spec.new do |s|
11
11
  s.license = package["license"]
12
12
  s.authors = package["author"]
13
13
 
14
- s.platforms = { :ios => min_ios_version_supported }
14
+ s.platforms = { :ios => "15.1" }
15
15
  s.source = { :git => "https://github.com/benjamineruvieru/react-native-credentials-manager.git", :tag => "#{s.version}" }
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
18
  s.private_header_files = "ios/generated/**/*.h"
19
19
 
20
+ # iOS frameworks for credential management
21
+ s.frameworks = 'AuthenticationServices', 'LocalAuthentication', 'Security'
22
+
20
23
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
24
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
25
  if respond_to?(:install_modules_dependencies, true)
@@ -7,7 +7,6 @@ module.exports = {
7
7
  android: {
8
8
  cmakeListsPath: 'generated/jni/CMakeLists.txt',
9
9
  },
10
- ios: null,
11
10
  },
12
11
  },
13
12
  };
@@ -1,18 +1,31 @@
1
1
  import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
3
 
4
- export type SignInOption = 'passkeys' | 'password' | 'google-signin';
4
+ export type SignInOption =
5
+ | 'passkeys'
6
+ | 'password'
7
+ | 'google-signin'
8
+ | 'apple-signin';
5
9
 
10
+ // Password authentication types
6
11
  type CredObject = {
7
12
  username: string;
8
13
  password: string;
9
14
  };
10
15
 
16
+ type PasswordCredential = {
17
+ type: 'password';
18
+ username: string;
19
+ password: string;
20
+ };
21
+
22
+ // Passkey authentication types
11
23
  type PasskeyCredential = {
12
24
  type: 'passkey';
13
25
  authenticationResponseJson: string;
14
26
  };
15
27
 
28
+ // Google Sign In types
16
29
  type GoogleSignInParams = {
17
30
  nonce: string;
18
31
  serverClientId: string;
@@ -30,32 +43,78 @@ export type GoogleCredential = {
30
43
  phoneNumber?: string;
31
44
  };
32
45
 
33
- type PasswordCredential = {
34
- type: 'password';
35
- username: string;
36
- password: string;
46
+ // Apple Sign In types
47
+ type AppleSignInParams = {
48
+ nonce: string;
49
+ requestedScopes: string[];
37
50
  };
38
51
 
52
+ export type AppleCredential = {
53
+ type: 'apple-signin';
54
+ id: string;
55
+ idToken: string;
56
+ displayName?: string;
57
+ familyName?: string;
58
+ givenName?: string;
59
+ email?: string;
60
+ };
61
+
62
+ // Combined credential type
39
63
  export type Credential =
40
64
  | PasskeyCredential
41
65
  | PasswordCredential
42
- | GoogleCredential;
66
+ | GoogleCredential
67
+ | AppleCredential;
43
68
 
69
+ // Native module interface
44
70
  export interface Spec extends TurboModule {
71
+ /**
72
+ * Sign up with passkeys (supported on both Android and iOS)
73
+ * @param requestJson WebAuthn request object
74
+ * @param preferImmediatelyAvailableCredentials Android-specific parameter, ignored on iOS
75
+ */
45
76
  signUpWithPasskeys(
46
77
  requestJson: Object,
47
78
  preferImmediatelyAvailableCredentials: boolean
48
79
  ): Promise<Object>;
49
- signUpWithPassword(credObject: CredObject): void;
50
80
 
81
+ /**
82
+ * Sign up with password (Android only - not supported on iOS)
83
+ * iOS will reject with UNSUPPORTED_OPERATION error
84
+ */
85
+ signUpWithPassword(credObject: CredObject): Promise<Object>;
86
+
87
+ /**
88
+ * Sign in with various methods
89
+ * - 'passkeys': Supported on both platforms
90
+ * - 'password': Supported on both platforms (uses AutoFill)
91
+ * - 'google-signin': Android only
92
+ * - 'apple-signin': iOS only (not available on Android)
93
+ */
51
94
  signIn(
52
95
  options: SignInOption[],
53
96
  params: {
54
97
  passkeys?: Object;
55
- googleSignIn?: GoogleSignInParams;
98
+ googleSignIn?: GoogleSignInParams; // Used only on Android
99
+ appleSignIn?: AppleSignInParams; // Used only on iOS
56
100
  }
57
101
  ): Promise<Credential>;
102
+
103
+ /**
104
+ * Sign up with Google (Android-specific implementation)
105
+ */
58
106
  signUpWithGoogle(params: GoogleSignInParams): Promise<GoogleCredential>;
107
+
108
+ /**
109
+ * Sign up with Apple (iOS-specific implementation)
110
+ * Will reject with UNSUPPORTED_OPERATION on Android
111
+ */
112
+ signUpWithApple(params: AppleSignInParams): Promise<AppleCredential>;
113
+
114
+ /**
115
+ * Sign out (behavior varies by platform)
116
+ * On iOS, this is a no-op as AuthenticationServices doesn't provide a sign-out method
117
+ */
59
118
  signOut(): Promise<null>;
60
119
  }
61
120
 
package/src/index.tsx CHANGED
@@ -2,8 +2,10 @@ import CredentialsManager from './NativeCredentialsManager';
2
2
  import type {
3
3
  Credential,
4
4
  GoogleCredential,
5
+ AppleCredential,
5
6
  SignInOption,
6
7
  } from './NativeCredentialsManager';
8
+ import { Platform } from 'react-native';
7
9
 
8
10
  type GoogleSignInParams = {
9
11
  nonce?: string;
@@ -11,6 +13,11 @@ type GoogleSignInParams = {
11
13
  autoSelectEnabled?: boolean;
12
14
  };
13
15
 
16
+ type AppleSignInParams = {
17
+ nonce?: string;
18
+ requestedScopes?: ('fullName' | 'email')[];
19
+ };
20
+
14
21
  export function signUpWithPasskeys(
15
22
  requestJson: Object,
16
23
  preferImmediatelyAvailableCredentials: boolean = false
@@ -27,8 +34,17 @@ export function signUpWithPassword({
27
34
  }: {
28
35
  username: string;
29
36
  password: string;
30
- }) {
31
- CredentialsManager.signUpWithPassword({ password, username });
37
+ }): Promise<Object> {
38
+ if (Platform.OS === 'ios') {
39
+ // iOS only supports AutoFill passwords through Apple's Authentication Services
40
+ // Manual password storage is not supported
41
+ return Promise.reject(
42
+ new Error(
43
+ 'Manual password storage is not supported on iOS. Use AutoFill passwords through signIn method instead.'
44
+ )
45
+ );
46
+ }
47
+ return CredentialsManager.signUpWithPassword({ password, username });
32
48
  }
33
49
 
34
50
  export function signIn(
@@ -36,21 +52,54 @@ export function signIn(
36
52
  params: {
37
53
  passkeys?: Object;
38
54
  googleSignIn?: GoogleSignInParams;
55
+ appleSignIn?: AppleSignInParams;
39
56
  }
40
57
  ): Promise<Credential> {
41
- return CredentialsManager.signIn(options, {
58
+ // Transform options for iOS compatibility
59
+ const processedOptions = options.map((option) => {
60
+ if (option === 'google-signin' && Platform.OS === 'ios') {
61
+ // Automatically replace google-signin with apple-signin on iOS
62
+ return 'apple-signin';
63
+ }
64
+ return option;
65
+ });
66
+
67
+ // Prepare parameters for both platforms
68
+ const signInParams: any = {
42
69
  ...params,
43
70
  googleSignIn: {
44
71
  serverClientId: params?.googleSignIn?.serverClientId ?? '',
45
72
  nonce: params?.googleSignIn?.nonce ?? '',
46
73
  autoSelectEnabled: params?.googleSignIn?.autoSelectEnabled ?? true,
47
74
  },
48
- });
75
+ };
76
+
77
+ // If we have Apple Sign In option on iOS, add Apple params
78
+ if (Platform.OS === 'ios' && processedOptions.includes('apple-signin')) {
79
+ signInParams.appleSignIn = {
80
+ nonce: params?.appleSignIn?.nonce || params?.googleSignIn?.nonce || '',
81
+ requestedScopes: params?.appleSignIn?.requestedScopes || [
82
+ 'fullName',
83
+ 'email',
84
+ ],
85
+ };
86
+ }
87
+
88
+ return CredentialsManager.signIn(processedOptions, signInParams);
49
89
  }
50
90
 
51
91
  export function signUpWithGoogle(
52
92
  params: GoogleSignInParams
53
- ): Promise<GoogleCredential> {
93
+ ): Promise<GoogleCredential | AppleCredential> {
94
+ if (Platform.OS === 'ios') {
95
+ // On iOS, automatically use Apple Sign In instead of Google Sign In
96
+ // This provides seamless cross-platform compatibility
97
+ return signUpWithApple({
98
+ nonce: params.nonce,
99
+ requestedScopes: ['fullName', 'email'],
100
+ }) as Promise<AppleCredential>;
101
+ }
102
+
54
103
  return CredentialsManager.signUpWithGoogle({
55
104
  ...params,
56
105
  nonce: params.nonce ?? '',
@@ -58,6 +107,34 @@ export function signUpWithGoogle(
58
107
  });
59
108
  }
60
109
 
110
+ export function signUpWithApple(
111
+ params: AppleSignInParams = {}
112
+ ): Promise<AppleCredential> {
113
+ if (Platform.OS !== 'ios') {
114
+ return Promise.reject(
115
+ new Error(
116
+ 'Apple Sign In is only available on iOS. Use signUpWithGoogle on Android.'
117
+ )
118
+ );
119
+ }
120
+
121
+ // Call the native signUpWithApple method directly - uses Apple's Authentication Services
122
+ return CredentialsManager.signUpWithApple({
123
+ nonce: params.nonce || '',
124
+ requestedScopes: params.requestedScopes || ['fullName', 'email'],
125
+ });
126
+ }
127
+
61
128
  export function signOut(): Promise<null> {
62
129
  return CredentialsManager.signOut();
63
130
  }
131
+
132
+ // Export types
133
+ export type {
134
+ Credential,
135
+ GoogleCredential,
136
+ AppleCredential,
137
+ SignInOption,
138
+ GoogleSignInParams,
139
+ AppleSignInParams,
140
+ };