react-native-credentials-manager 0.2.1 → 0.4.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 (34) hide show
  1. package/README.md +65 -3
  2. package/android/build.gradle +9 -9
  3. package/android/generated/java/com/credentialsmanager/NativeCredentialsManagerSpec.java +8 -0
  4. package/android/generated/jni/RNCredentialsManagerSpec-generated.cpp +12 -0
  5. package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI-generated.cpp +13 -0
  6. package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI.h +118 -0
  7. package/android/src/main/java/com/credentialsmanager/CredentialsManagerModuleImpl.kt +7 -0
  8. package/android/src/main/java/com/credentialsmanager/CredentialsManagerPackage.kt +6 -5
  9. package/android/src/main/java/com/credentialsmanager/handlers/CredentialHandler.kt +178 -0
  10. package/android/src/main/java/com/credentialsmanager/handlers/ErrorHandler.kt +56 -0
  11. package/android/src/newarch/java/com/credentialsmanager/CredentialsManagerModule.kt +138 -0
  12. package/android/src/oldarch/java/com/credentialsmanager/CredentialsManagerModule.kt +127 -0
  13. package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec-generated.mm +20 -0
  14. package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec.h +37 -0
  15. package/ios/generated/RNCredentialsManagerSpecJSI-generated.cpp +13 -0
  16. package/ios/generated/RNCredentialsManagerSpecJSI.h +118 -0
  17. package/lib/commonjs/NativeCredentialsManager.js.map +1 -1
  18. package/lib/commonjs/index.js +12 -0
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/NativeCredentialsManager.js.map +1 -1
  21. package/lib/module/index.js +10 -0
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts +16 -0
  24. package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/src/index.d.ts +7 -1
  26. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  27. package/lib/typescript/module/src/NativeCredentialsManager.d.ts +16 -0
  28. package/lib/typescript/module/src/NativeCredentialsManager.d.ts.map +1 -1
  29. package/lib/typescript/module/src/index.d.ts +7 -1
  30. package/lib/typescript/module/src/index.d.ts.map +1 -1
  31. package/package.json +15 -3
  32. package/src/NativeCredentialsManager.ts +17 -0
  33. package/src/index.tsx +17 -1
  34. package/android/src/main/java/com/credentialsmanager/CredentialsManagerModule.kt +0 -212
@@ -7,6 +7,16 @@ type PasskeyCredential = {
7
7
  type: 'passkey';
8
8
  authenticationResponseJson: string;
9
9
  };
10
+ export type GoogleCredential = {
11
+ type: 'google-signin';
12
+ id: string;
13
+ idToken: string;
14
+ displayName?: string;
15
+ familyName?: string;
16
+ givenName?: string;
17
+ profilePicture?: string;
18
+ phoneNumber?: string;
19
+ };
10
20
  type PasswordCredential = {
11
21
  type: 'password';
12
22
  username: string;
@@ -17,6 +27,12 @@ export interface Spec extends TurboModule {
17
27
  signUpWithPasskeys(requestJson: Object, preferImmediatelyAvailableCredentials: boolean): Promise<Object>;
18
28
  signUpWithPassword(credObject: CredObject): void;
19
29
  signInWithSavedCredentials(requestJson: Object): Promise<Credential>;
30
+ signInWithGoogle(params: {
31
+ nonce: string;
32
+ serverClientId: string;
33
+ autoSelectEnabled: boolean;
34
+ }): Promise<GoogleCredential>;
35
+ signOut(): Promise<null>;
20
36
  }
21
37
  declare const _default: Spec;
22
38
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"NativeCredentialsManager.d.ts","sourceRoot":"","sources":["../../../../src/NativeCredentialsManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,KAAK,UAAU,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IAC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BAAkB,GAAG;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAEhE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,kBAAkB,CAChB,WAAW,EAAE,MAAM,EACnB,qCAAqC,EAAE,OAAO,GAC7C,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAEjD,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACrE,gBAAgB,CAAC,MAAM,EAAE;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,OAAO,CAAC;KAC5B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;;AAED,wBAA4E"}
@@ -1,8 +1,14 @@
1
- import type { Credential } from './NativeCredentialsManager';
1
+ import type { Credential, GoogleCredential } from './NativeCredentialsManager';
2
2
  export declare function signUpWithPasskeys(requestJson: Object, preferImmediatelyAvailableCredentials?: boolean): Promise<Object>;
3
3
  export declare function signUpWithPassword({ username, password, }: {
4
4
  username: string;
5
5
  password: string;
6
6
  }): void;
7
7
  export declare function signInWithSavedCredentials(requestJson: Object): Promise<Credential>;
8
+ export declare function signInWithGoogle(params: {
9
+ nonce?: string;
10
+ serverClientId: string;
11
+ autoSelectEnabled?: boolean;
12
+ }): Promise<GoogleCredential>;
13
+ export declare function signOut(): Promise<null>;
8
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,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,0BAA0B,CACxC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAErB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE/E,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,0BAA0B,CACxC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAErB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAM5B;AAED,wBAAgB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-credentials-manager",
3
- "version": "0.2.1",
3
+ "version": "0.4.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",
@@ -48,7 +48,18 @@
48
48
  "keywords": [
49
49
  "react-native",
50
50
  "ios",
51
- "android"
51
+ "android",
52
+ "passkeys",
53
+ "webauthn",
54
+ "authentication",
55
+ "credential-manager",
56
+ "google-signin",
57
+ "passwordless",
58
+ "biometric",
59
+ "security",
60
+ "identity",
61
+ "fido2",
62
+ "signin"
52
63
  ],
53
64
  "repository": {
54
65
  "type": "git",
@@ -59,7 +70,7 @@
59
70
  "bugs": {
60
71
  "url": "https://github.com/benjamineruvieru/react-native-credentials-manager/issues"
61
72
  },
62
- "homepage": "https://github.com/benjamineruvieru/react-native-credentials-manager#readme",
73
+ "homepage": "https://docs.benjamineruvieru.com/docs/react-native-credentials-manager/",
63
74
  "publishConfig": {
64
75
  "registry": "https://registry.npmjs.org/"
65
76
  },
@@ -82,6 +93,7 @@
82
93
  "react": "18.3.1",
83
94
  "react-native": "0.77.0",
84
95
  "react-native-builder-bob": "^0.36.0",
96
+ "react-native-dotenv": "^3.4.11",
85
97
  "release-it": "^17.10.0",
86
98
  "turbo": "^1.10.7",
87
99
  "typescript": "^5.2.2"
@@ -11,6 +11,17 @@ type PasskeyCredential = {
11
11
  authenticationResponseJson: string;
12
12
  };
13
13
 
14
+ export type GoogleCredential = {
15
+ type: 'google-signin';
16
+ id: string;
17
+ idToken: string;
18
+ displayName?: string;
19
+ familyName?: string;
20
+ givenName?: string;
21
+ profilePicture?: string;
22
+ phoneNumber?: string;
23
+ };
24
+
14
25
  type PasswordCredential = {
15
26
  type: 'password';
16
27
  username: string;
@@ -27,6 +38,12 @@ export interface Spec extends TurboModule {
27
38
  signUpWithPassword(credObject: CredObject): void;
28
39
 
29
40
  signInWithSavedCredentials(requestJson: Object): Promise<Credential>;
41
+ signInWithGoogle(params: {
42
+ nonce: string;
43
+ serverClientId: string;
44
+ autoSelectEnabled: boolean;
45
+ }): Promise<GoogleCredential>;
46
+ signOut(): Promise<null>;
30
47
  }
31
48
 
32
49
  export default TurboModuleRegistry.getEnforcing<Spec>('CredentialsManager');
package/src/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import CredentialsManager from './NativeCredentialsManager';
2
- import type { Credential } from './NativeCredentialsManager';
2
+ import type { Credential, GoogleCredential } from './NativeCredentialsManager';
3
3
 
4
4
  export function signUpWithPasskeys(
5
5
  requestJson: Object,
@@ -26,3 +26,19 @@ export function signInWithSavedCredentials(
26
26
  ): Promise<Credential> {
27
27
  return CredentialsManager.signInWithSavedCredentials(requestJson);
28
28
  }
29
+
30
+ export function signInWithGoogle(params: {
31
+ nonce?: string;
32
+ serverClientId: string;
33
+ autoSelectEnabled?: boolean;
34
+ }): Promise<GoogleCredential> {
35
+ return CredentialsManager.signInWithGoogle({
36
+ ...params,
37
+ nonce: params.nonce ?? '',
38
+ autoSelectEnabled: params.autoSelectEnabled ?? true,
39
+ });
40
+ }
41
+
42
+ export function signOut(): Promise<null> {
43
+ return CredentialsManager.signOut();
44
+ }
@@ -1,212 +0,0 @@
1
- package com.credentialsmanager
2
-
3
- import android.util.Log
4
- import androidx.credentials.CreatePasswordRequest
5
- import androidx.credentials.CreatePublicKeyCredentialRequest
6
- import androidx.credentials.CreatePublicKeyCredentialResponse
7
- import androidx.credentials.CredentialManager
8
- import androidx.credentials.CustomCredential
9
- import androidx.credentials.GetCredentialRequest
10
- import androidx.credentials.GetPasswordOption
11
- import androidx.credentials.GetPublicKeyCredentialOption
12
- import androidx.credentials.PasswordCredential
13
- import androidx.credentials.PublicKeyCredential
14
- import androidx.credentials.exceptions.CreateCredentialCancellationException
15
- import androidx.credentials.exceptions.CreateCredentialCustomException
16
- import androidx.credentials.exceptions.CreateCredentialException
17
- import androidx.credentials.exceptions.CreateCredentialInterruptedException
18
- import androidx.credentials.exceptions.CreateCredentialProviderConfigurationException
19
- import androidx.credentials.exceptions.CreateCredentialUnknownException
20
- import androidx.credentials.exceptions.publickeycredential.CreatePublicKeyCredentialDomException
21
- import com.facebook.react.bridge.Arguments
22
- import com.facebook.react.bridge.Promise
23
- import com.facebook.react.bridge.ReactApplicationContext
24
- import com.facebook.react.bridge.ReadableMap
25
- import com.facebook.react.module.annotations.ReactModule
26
- import kotlinx.coroutines.CoroutineScope
27
- import kotlinx.coroutines.Dispatchers
28
- import kotlinx.coroutines.launch
29
- import org.json.JSONObject
30
-
31
- @ReactModule(name = CredentialsManagerModule.NAME)
32
- class CredentialsManagerModule(
33
- reactContext: ReactApplicationContext,
34
- ) : NativeCredentialsManagerSpec(reactContext) {
35
- private val coroutineScope = CoroutineScope(Dispatchers.IO)
36
- val credentialManager = CredentialManager.create(getReactApplicationContext())
37
-
38
- override fun getName(): String = NAME
39
-
40
- override fun signUpWithPasskeys(
41
- requestJson: ReadableMap,
42
- preferImmediatelyAvailableCredentials: Boolean,
43
- promise: Promise,
44
- ) {
45
- val jsonString = requestJson.toString()
46
-
47
- val request =
48
- CreatePublicKeyCredentialRequest(
49
- requestJson = jsonString,
50
- preferImmediatelyAvailableCredentials = preferImmediatelyAvailableCredentials,
51
- )
52
-
53
- coroutineScope.launch {
54
- try {
55
- val response =
56
- credentialManager.createCredential(
57
- getReactApplicationContext(),
58
- request,
59
- ) as CreatePublicKeyCredentialResponse
60
-
61
- response?.let {
62
- val dataBundle = it.data
63
- val responseJson = dataBundle.getString("androidx.credentials.BUNDLE_KEY_REGISTRATION_RESPONSE_JSON")
64
- responseJson?.let { json ->
65
-
66
- val jsonObject = Arguments.createMap()
67
- val parsedObject = JSONObject(json)
68
-
69
- parsedObject.keys().forEach { key ->
70
- jsonObject.putString(key, parsedObject.getString(key))
71
- }
72
-
73
- Log.d("CredentialManager", "Passkey creation result: $jsonObject")
74
- promise.resolve(jsonObject)
75
- } ?: run {
76
- promise.reject("ERROR", "Response JSON is null")
77
- }
78
- } ?: run {
79
- promise.reject("ERROR", "No response received")
80
- }
81
- } catch (e: CreateCredentialException) {
82
- handleFailure(e)
83
- promise.reject("ERROR", e.message.toString())
84
- }
85
- }
86
- }
87
-
88
- override fun signUpWithPassword(credObject: ReadableMap) {
89
- val username = credObject.getString("username") ?: ""
90
- val password = credObject.getString("password") ?: ""
91
- coroutineScope.launch {
92
- createPassword(username, password)
93
- }
94
- }
95
-
96
- override fun signInWithSavedCredentials(
97
- requestJson: ReadableMap,
98
- promise: Promise,
99
- ) {
100
- val jsonString = requestJson.toString()
101
- coroutineScope.launch {
102
- val data = getSavedCredentials(jsonString)
103
- promise.resolve(data)
104
- }
105
- }
106
-
107
- private suspend fun getSavedCredentials(jsonString: String): ReadableMap? {
108
- val getPublicKeyCredentialOption =
109
- GetPublicKeyCredentialOption(jsonString, null)
110
-
111
- val getPasswordOption = GetPasswordOption()
112
-
113
- val result =
114
- try {
115
- credentialManager.getCredential(
116
- getReactApplicationContext(),
117
- GetCredentialRequest(
118
- listOf(
119
- getPublicKeyCredentialOption,
120
- getPasswordOption,
121
- ),
122
- ),
123
- )
124
- } catch (e: Exception) {
125
- Log.e("CredentialManager", "getCredential failed with exception: " + e.message.toString())
126
-
127
- return null
128
- }
129
-
130
- val resultMap = Arguments.createMap()
131
- when (result.credential) {
132
- is PublicKeyCredential -> {
133
- val cred = result.credential as PublicKeyCredential
134
- resultMap.putString("type", "passkey")
135
- resultMap.putString("authenticationResponseJson", cred.authenticationResponseJson)
136
- Log.d("CredentialManager", "Passkey: ${cred.authenticationResponseJson}")
137
- }
138
- is PasswordCredential -> {
139
- val cred = result.credential as PasswordCredential
140
- resultMap.putString("type", "password")
141
- resultMap.putString("username", cred.id)
142
- resultMap.putString("password", cred.password)
143
- Log.d("CredentialManager", "Got Password - User:${cred.id} Password: ${cred.password}")
144
- }
145
- is CustomCredential -> {
146
- return null
147
- }
148
- else -> return null
149
- }
150
-
151
- return resultMap
152
- }
153
-
154
- private suspend fun createPassword(
155
- username: String,
156
- password: String,
157
- ) {
158
- val createPasswordRequest =
159
- CreatePasswordRequest(id = username, password = password)
160
-
161
- try {
162
- val result =
163
- credentialManager.createCredential(
164
- getReactApplicationContext(),
165
- createPasswordRequest,
166
- )
167
- } catch (e: CreateCredentialException) {
168
- handleFailure(e)
169
- }
170
- }
171
-
172
- private fun handleFailure(e: CreateCredentialException) {
173
- when (e) {
174
- is CreatePublicKeyCredentialDomException -> {
175
- // Handle the passkey DOM errors thrown according to the
176
- // WebAuthn spec.
177
- Log.d("CredentialManager", "passkey DOM errors")
178
- // handlePasskeyError(e.domError)
179
- }
180
- is CreateCredentialCancellationException -> {
181
- // The user intentionally canceled the operation and chose not
182
- // to register the credential.
183
- Log.d("CredentialManager", "User cancelled")
184
- }
185
- is CreateCredentialInterruptedException -> {
186
- // Retry-able error. Consider retrying the call.
187
- Log.d("CredentialManager", "Retry process")
188
- }
189
- is CreateCredentialProviderConfigurationException -> {
190
- // Your app is missing the provider configuration dependency.
191
- // Most likely, you're missing the
192
- // "credentials-play-services-auth" module.
193
- }
194
- is CreateCredentialUnknownException -> {
195
- Log.d("CredentialManager", "Unknown error")
196
- }
197
- is CreateCredentialCustomException -> {
198
- // You have encountered an error from a 3rd-party SDK. If you
199
- // make the API call with a request object that's a subclass of
200
- // CreateCustomCredentialRequest using a 3rd-party SDK, then you
201
- // should check for any custom exception type constants within
202
- // that SDK to match with e.type. Otherwise, drop or log the
203
- // exception.
204
- }
205
- else -> Log.w("CredentialManager", "Unexpected exception type ${e::class.java.name}")
206
- }
207
- }
208
-
209
- companion object {
210
- const val NAME = "CredentialsManager"
211
- }
212
- }