react-native-credentials-manager 0.2.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.
- package/LICENSE +20 -0
- package/README.md +258 -0
- package/android/build.gradle +116 -0
- package/android/generated/RCTAppDependencyProvider.h +25 -0
- package/android/generated/RCTAppDependencyProvider.mm +55 -0
- package/android/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
- package/android/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
- package/android/generated/RCTThirdPartyComponentsProvider.h +16 -0
- package/android/generated/RCTThirdPartyComponentsProvider.mm +23 -0
- package/android/generated/ReactAppDependencyProvider.podspec +34 -0
- package/android/generated/java/com/credentialsmanager/NativeCredentialsManagerSpec.java +47 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNCredentialsManagerSpec-generated.cpp +44 -0
- package/android/generated/jni/RNCredentialsManagerSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI-generated.cpp +43 -0
- package/android/generated/jni/react/renderer/components/RNCredentialsManagerSpec/RNCredentialsManagerSpecJSI.h +136 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/credentialsmanager/CredentialsManagerModule.kt +212 -0
- package/android/src/main/java/com/credentialsmanager/CredentialsManagerPackage.kt +35 -0
- package/ios/CredentialsManager.h +6 -0
- package/ios/CredentialsManager.mm +18 -0
- package/ios/generated/RCTAppDependencyProvider.h +25 -0
- package/ios/generated/RCTAppDependencyProvider.mm +55 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.mm +23 -0
- package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec-generated.mm +58 -0
- package/ios/generated/RNCredentialsManagerSpec/RNCredentialsManagerSpec.h +93 -0
- package/ios/generated/RNCredentialsManagerSpecJSI-generated.cpp +43 -0
- package/ios/generated/RNCredentialsManagerSpecJSI.h +136 -0
- package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
- package/lib/commonjs/NativeCredentialsManager.js +9 -0
- package/lib/commonjs/NativeCredentialsManager.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/j.js +9 -0
- package/lib/commonjs/j.js.map +1 -0
- package/lib/module/NativeCredentialsManager.js +5 -0
- package/lib/module/NativeCredentialsManager.js.map +1 -0
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/j.js +5 -0
- package/lib/module/j.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts +23 -0
- package/lib/typescript/commonjs/src/NativeCredentialsManager.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +8 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeCredentialsManager.d.ts +23 -0
- package/lib/typescript/module/src/NativeCredentialsManager.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +8 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +228 -0
- package/react-native-credentials-manager.podspec +42 -0
- package/react-native.config.js +12 -0
- package/src/NativeCredentialsManager.ts +32 -0
- package/src/index.tsx +28 -0
- package/src/j.js +33 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJniCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "RNCredentialsManagerSpec.h"
|
|
12
|
+
|
|
13
|
+
namespace facebook::react {
|
|
14
|
+
|
|
15
|
+
static facebook::jsi::Value __hostFunction_NativeCredentialsManagerSpecJSI_signUpWithPasskeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
16
|
+
static jmethodID cachedMethodId = nullptr;
|
|
17
|
+
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "signUpWithPasskeys", "(Lcom/facebook/react/bridge/ReadableMap;ZLcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static facebook::jsi::Value __hostFunction_NativeCredentialsManagerSpecJSI_signUpWithPassword(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
21
|
+
static jmethodID cachedMethodId = nullptr;
|
|
22
|
+
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, VoidKind, "signUpWithPassword", "(Lcom/facebook/react/bridge/ReadableMap;)V", args, count, cachedMethodId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static facebook::jsi::Value __hostFunction_NativeCredentialsManagerSpecJSI_signInWithSavedCredentials(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
26
|
+
static jmethodID cachedMethodId = nullptr;
|
|
27
|
+
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "signInWithSavedCredentials", "(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
NativeCredentialsManagerSpecJSI::NativeCredentialsManagerSpecJSI(const JavaTurboModule::InitParams ¶ms)
|
|
31
|
+
: JavaTurboModule(params) {
|
|
32
|
+
methodMap_["signUpWithPasskeys"] = MethodMetadata {2, __hostFunction_NativeCredentialsManagerSpecJSI_signUpWithPasskeys};
|
|
33
|
+
methodMap_["signUpWithPassword"] = MethodMetadata {1, __hostFunction_NativeCredentialsManagerSpecJSI_signUpWithPassword};
|
|
34
|
+
methodMap_["signInWithSavedCredentials"] = MethodMetadata {1, __hostFunction_NativeCredentialsManagerSpecJSI_signInWithSavedCredentials};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
std::shared_ptr<TurboModule> RNCredentialsManagerSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
38
|
+
if (moduleName == "CredentialsManager") {
|
|
39
|
+
return std::make_shared<NativeCredentialsManagerSpecJSI>(params);
|
|
40
|
+
}
|
|
41
|
+
return nullptr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJniH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
14
|
+
#include <ReactCommon/TurboModule.h>
|
|
15
|
+
#include <jsi/jsi.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook::react {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* JNI C++ class for module 'NativeCredentialsManager'
|
|
21
|
+
*/
|
|
22
|
+
class JSI_EXPORT NativeCredentialsManagerSpecJSI : public JavaTurboModule {
|
|
23
|
+
public:
|
|
24
|
+
NativeCredentialsManagerSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
JSI_EXPORT
|
|
29
|
+
std::shared_ptr<TurboModule> RNCredentialsManagerSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
30
|
+
|
|
31
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleCpp.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "RNCredentialsManagerSpecJSI.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
static jsi::Value __hostFunction_NativeCredentialsManagerCxxSpecJSI_signUpWithPasskeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
15
|
+
return static_cast<NativeCredentialsManagerCxxSpecJSI *>(&turboModule)->signUpWithPasskeys(
|
|
16
|
+
rt,
|
|
17
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt),
|
|
18
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asBool()
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
static jsi::Value __hostFunction_NativeCredentialsManagerCxxSpecJSI_signUpWithPassword(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
22
|
+
static_cast<NativeCredentialsManagerCxxSpecJSI *>(&turboModule)->signUpWithPassword(
|
|
23
|
+
rt,
|
|
24
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt)
|
|
25
|
+
);
|
|
26
|
+
return jsi::Value::undefined();
|
|
27
|
+
}
|
|
28
|
+
static jsi::Value __hostFunction_NativeCredentialsManagerCxxSpecJSI_signInWithSavedCredentials(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
29
|
+
return static_cast<NativeCredentialsManagerCxxSpecJSI *>(&turboModule)->signInWithSavedCredentials(
|
|
30
|
+
rt,
|
|
31
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
NativeCredentialsManagerCxxSpecJSI::NativeCredentialsManagerCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
36
|
+
: TurboModule("CredentialsManager", jsInvoker) {
|
|
37
|
+
methodMap_["signUpWithPasskeys"] = MethodMetadata {2, __hostFunction_NativeCredentialsManagerCxxSpecJSI_signUpWithPasskeys};
|
|
38
|
+
methodMap_["signUpWithPassword"] = MethodMetadata {1, __hostFunction_NativeCredentialsManagerCxxSpecJSI_signUpWithPassword};
|
|
39
|
+
methodMap_["signInWithSavedCredentials"] = MethodMetadata {1, __hostFunction_NativeCredentialsManagerCxxSpecJSI_signInWithSavedCredentials};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleH.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <ReactCommon/TurboModule.h>
|
|
13
|
+
#include <react/bridging/Bridging.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
#pragma mark - NativeCredentialsManagerCredObject
|
|
20
|
+
|
|
21
|
+
template <typename P0, typename P1>
|
|
22
|
+
struct NativeCredentialsManagerCredObject {
|
|
23
|
+
P0 username;
|
|
24
|
+
P1 password;
|
|
25
|
+
bool operator==(const NativeCredentialsManagerCredObject &other) const {
|
|
26
|
+
return username == other.username && password == other.password;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
struct NativeCredentialsManagerCredObjectBridging {
|
|
32
|
+
static T types;
|
|
33
|
+
|
|
34
|
+
static T fromJs(
|
|
35
|
+
jsi::Runtime &rt,
|
|
36
|
+
const jsi::Object &value,
|
|
37
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
38
|
+
T result{
|
|
39
|
+
bridging::fromJs<decltype(types.username)>(rt, value.getProperty(rt, "username"), jsInvoker),
|
|
40
|
+
bridging::fromJs<decltype(types.password)>(rt, value.getProperty(rt, "password"), jsInvoker)};
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#ifdef DEBUG
|
|
45
|
+
static jsi::String usernameToJs(jsi::Runtime &rt, decltype(types.username) value) {
|
|
46
|
+
return bridging::toJs(rt, value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static jsi::String passwordToJs(jsi::Runtime &rt, decltype(types.password) value) {
|
|
50
|
+
return bridging::toJs(rt, value);
|
|
51
|
+
}
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
static jsi::Object toJs(
|
|
55
|
+
jsi::Runtime &rt,
|
|
56
|
+
const T &value,
|
|
57
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
58
|
+
auto result = facebook::jsi::Object(rt);
|
|
59
|
+
result.setProperty(rt, "username", bridging::toJs(rt, value.username, jsInvoker));
|
|
60
|
+
result.setProperty(rt, "password", bridging::toJs(rt, value.password, jsInvoker));
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
class JSI_EXPORT NativeCredentialsManagerCxxSpecJSI : public TurboModule {
|
|
66
|
+
protected:
|
|
67
|
+
NativeCredentialsManagerCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
|
68
|
+
|
|
69
|
+
public:
|
|
70
|
+
virtual jsi::Value signUpWithPasskeys(jsi::Runtime &rt, jsi::Object requestJson, bool preferImmediatelyAvailableCredentials) = 0;
|
|
71
|
+
virtual void signUpWithPassword(jsi::Runtime &rt, jsi::Object credObject) = 0;
|
|
72
|
+
virtual jsi::Value signInWithSavedCredentials(jsi::Runtime &rt, jsi::Object requestJson) = 0;
|
|
73
|
+
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
template <typename T>
|
|
77
|
+
class JSI_EXPORT NativeCredentialsManagerCxxSpec : public TurboModule {
|
|
78
|
+
public:
|
|
79
|
+
jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
|
80
|
+
return delegate_.create(rt, propName);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
|
|
84
|
+
return delegate_.getPropertyNames(runtime);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static constexpr std::string_view kModuleName = "CredentialsManager";
|
|
88
|
+
|
|
89
|
+
protected:
|
|
90
|
+
NativeCredentialsManagerCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
|
91
|
+
: TurboModule(std::string{NativeCredentialsManagerCxxSpec::kModuleName}, jsInvoker),
|
|
92
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
class Delegate : public NativeCredentialsManagerCxxSpecJSI {
|
|
97
|
+
public:
|
|
98
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
|
99
|
+
NativeCredentialsManagerCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
jsi::Value signUpWithPasskeys(jsi::Runtime &rt, jsi::Object requestJson, bool preferImmediatelyAvailableCredentials) override {
|
|
104
|
+
static_assert(
|
|
105
|
+
bridging::getParameterCount(&T::signUpWithPasskeys) == 3,
|
|
106
|
+
"Expected signUpWithPasskeys(...) to have 3 parameters");
|
|
107
|
+
|
|
108
|
+
return bridging::callFromJs<jsi::Value>(
|
|
109
|
+
rt, &T::signUpWithPasskeys, jsInvoker_, instance_, std::move(requestJson), std::move(preferImmediatelyAvailableCredentials));
|
|
110
|
+
}
|
|
111
|
+
void signUpWithPassword(jsi::Runtime &rt, jsi::Object credObject) override {
|
|
112
|
+
static_assert(
|
|
113
|
+
bridging::getParameterCount(&T::signUpWithPassword) == 2,
|
|
114
|
+
"Expected signUpWithPassword(...) to have 2 parameters");
|
|
115
|
+
|
|
116
|
+
return bridging::callFromJs<void>(
|
|
117
|
+
rt, &T::signUpWithPassword, jsInvoker_, instance_, std::move(credObject));
|
|
118
|
+
}
|
|
119
|
+
jsi::Value signInWithSavedCredentials(jsi::Runtime &rt, jsi::Object requestJson) override {
|
|
120
|
+
static_assert(
|
|
121
|
+
bridging::getParameterCount(&T::signInWithSavedCredentials) == 2,
|
|
122
|
+
"Expected signInWithSavedCredentials(...) to have 2 parameters");
|
|
123
|
+
|
|
124
|
+
return bridging::callFromJs<jsi::Value>(
|
|
125
|
+
rt, &T::signInWithSavedCredentials, jsInvoker_, instance_, std::move(requestJson));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private:
|
|
129
|
+
friend class NativeCredentialsManagerCxxSpec;
|
|
130
|
+
T *instance_;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
Delegate delegate_;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.credentialsmanager
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class CredentialsManagerPackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(
|
|
12
|
+
name: String,
|
|
13
|
+
reactContext: ReactApplicationContext,
|
|
14
|
+
): NativeModule? =
|
|
15
|
+
if (name == CredentialsManagerModule.NAME) {
|
|
16
|
+
CredentialsManagerModule(reactContext)
|
|
17
|
+
} else {
|
|
18
|
+
null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
|
|
22
|
+
ReactModuleInfoProvider {
|
|
23
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
24
|
+
moduleInfos[CredentialsManagerModule.NAME] =
|
|
25
|
+
ReactModuleInfo(
|
|
26
|
+
CredentialsManagerModule.NAME,
|
|
27
|
+
CredentialsManagerModule.NAME,
|
|
28
|
+
false, // canOverrideExistingModule
|
|
29
|
+
false, // needsEagerInit
|
|
30
|
+
false, // isCxxModule
|
|
31
|
+
true, // isTurboModule
|
|
32
|
+
)
|
|
33
|
+
moduleInfos
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import "CredentialsManager.h"
|
|
2
|
+
|
|
3
|
+
@implementation CredentialsManager
|
|
4
|
+
RCT_EXPORT_MODULE()
|
|
5
|
+
|
|
6
|
+
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
7
|
+
NSNumber *result = @(a * b);
|
|
8
|
+
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
13
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
14
|
+
{
|
|
15
|
+
return std::make_shared<facebook::react::NativeCredentialsManagerSpecJSI>(params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
|
|
11
|
+
#if __has_include(<React-RCTAppDelegate/RCTDependencyProvider.h>)
|
|
12
|
+
#import <React-RCTAppDelegate/RCTDependencyProvider.h>
|
|
13
|
+
#elif __has_include(<React_RCTAppDelegate/RCTDependencyProvider.h>)
|
|
14
|
+
#import <React_RCTAppDelegate/RCTDependencyProvider.h>
|
|
15
|
+
#else
|
|
16
|
+
#import "RCTDependencyProvider.h"
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
20
|
+
|
|
21
|
+
@interface RCTAppDependencyProvider : NSObject <RCTDependencyProvider>
|
|
22
|
+
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#import "RCTAppDependencyProvider.h"
|
|
9
|
+
#import <ReactCodegen/RCTModulesConformingToProtocolsProvider.h>
|
|
10
|
+
#import <ReactCodegen/RCTThirdPartyComponentsProvider.h>
|
|
11
|
+
|
|
12
|
+
@implementation RCTAppDependencyProvider {
|
|
13
|
+
NSArray<NSString *> * _URLRequestHandlerClassNames;
|
|
14
|
+
NSArray<NSString *> * _imageDataDecoderClassNames;
|
|
15
|
+
NSArray<NSString *> * _imageURLLoaderClassNames;
|
|
16
|
+
NSDictionary<NSString *,Class<RCTComponentViewProtocol>> * _thirdPartyFabricComponents;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (nonnull NSArray<NSString *> *)URLRequestHandlerClassNames {
|
|
20
|
+
static dispatch_once_t requestUrlToken;
|
|
21
|
+
dispatch_once(&requestUrlToken, ^{
|
|
22
|
+
self->_URLRequestHandlerClassNames = RCTModulesConformingToProtocolsProvider.URLRequestHandlerClassNames;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return _URLRequestHandlerClassNames;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (nonnull NSArray<NSString *> *)imageDataDecoderClassNames {
|
|
29
|
+
static dispatch_once_t dataDecoderToken;
|
|
30
|
+
dispatch_once(&dataDecoderToken, ^{
|
|
31
|
+
_imageDataDecoderClassNames = RCTModulesConformingToProtocolsProvider.imageDataDecoderClassNames;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return _imageDataDecoderClassNames;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (nonnull NSArray<NSString *> *)imageURLLoaderClassNames {
|
|
38
|
+
static dispatch_once_t urlLoaderToken;
|
|
39
|
+
dispatch_once(&urlLoaderToken, ^{
|
|
40
|
+
_imageURLLoaderClassNames = RCTModulesConformingToProtocolsProvider.imageURLLoaderClassNames;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return _imageURLLoaderClassNames;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (nonnull NSDictionary<NSString *,Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents {
|
|
47
|
+
static dispatch_once_t nativeComponentsToken;
|
|
48
|
+
dispatch_once(&nativeComponentsToken, ^{
|
|
49
|
+
_thirdPartyFabricComponents = RCTThirdPartyComponentsProvider.thirdPartyFabricComponents;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return _thirdPartyFabricComponents;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
@interface RCTModulesConformingToProtocolsProvider: NSObject
|
|
11
|
+
|
|
12
|
+
+(NSArray<NSString *> *)imageURLLoaderClassNames;
|
|
13
|
+
|
|
14
|
+
+(NSArray<NSString *> *)imageDataDecoderClassNames;
|
|
15
|
+
|
|
16
|
+
+(NSArray<NSString *> *)URLRequestHandlerClassNames;
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#import "RCTModulesConformingToProtocolsProvider.h"
|
|
9
|
+
|
|
10
|
+
@implementation RCTModulesConformingToProtocolsProvider
|
|
11
|
+
|
|
12
|
+
+(NSArray<NSString *> *)imageURLLoaderClassNames
|
|
13
|
+
{
|
|
14
|
+
return @[
|
|
15
|
+
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
+(NSArray<NSString *> *)imageDataDecoderClassNames
|
|
20
|
+
{
|
|
21
|
+
return @[
|
|
22
|
+
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
+(NSArray<NSString *> *)URLRequestHandlerClassNames
|
|
27
|
+
{
|
|
28
|
+
return @[
|
|
29
|
+
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|