@capgo/capacitor-autofill-save-password 7.0.2 → 7.0.4
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/README.md
CHANGED
|
@@ -11,6 +11,10 @@ Prompt to display dialog for saving password to keychain from webview app
|
|
|
11
11
|
|
|
12
12
|
Fork of original plugin to work with Capacitor 7
|
|
13
13
|
|
|
14
|
+
IOS work for old versions and 18.3
|
|
15
|
+
|
|
16
|
+
Android still WIP
|
|
17
|
+
|
|
14
18
|
## Install
|
|
15
19
|
|
|
16
20
|
```bash
|
|
@@ -49,6 +53,30 @@ login(username: string, password: string) {
|
|
|
49
53
|
}
|
|
50
54
|
```
|
|
51
55
|
|
|
56
|
+
|
|
57
|
+
### Android
|
|
58
|
+
|
|
59
|
+
Add `apply plugin: 'com.google.gms.google-services'` beneath `apply plugin: 'com.android.application'` in `android/app/build.gradle`
|
|
60
|
+
|
|
61
|
+
this will allow the plugin to import the proper lib.
|
|
62
|
+
|
|
63
|
+
Then you need to make sure you did set properly your domain and did add google-services.json.
|
|
64
|
+
|
|
65
|
+
guide here https://developer.android.com/identity/sign-in/credential-manager
|
|
66
|
+
|
|
67
|
+
You need to have the file at this path `android/google-services.json` set, if you dont use firebase add empty json
|
|
68
|
+
|
|
69
|
+
then add your domain in `example-app/android/app/src/main/res/values/strings.xml`
|
|
70
|
+
|
|
71
|
+
with
|
|
72
|
+
```xml
|
|
73
|
+
<string name="asset_statements" translatable="false">
|
|
74
|
+
[{
|
|
75
|
+
\"include\": \"https://YOURDOMAIN/.well-known/assetlinks.json\"
|
|
76
|
+
}]
|
|
77
|
+
</string>
|
|
78
|
+
```
|
|
79
|
+
|
|
52
80
|
## API
|
|
53
81
|
|
|
54
82
|
<docgen-index>
|
package/android/build.gradle
CHANGED
|
@@ -47,14 +47,12 @@ repositories {
|
|
|
47
47
|
mavenCentral()
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
dependencies {
|
|
52
51
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
52
|
implementation project(':capacitor-android')
|
|
54
53
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
implementation
|
|
56
|
-
implementation
|
|
57
|
-
// implementation 'androidx.credentials:credentials:1.5.0'
|
|
54
|
+
implementation "androidx.credentials:credentials:1.5.0"
|
|
55
|
+
implementation "androidx.credentials:credentials-play-services-auth:1.5.0"
|
|
58
56
|
testImplementation "junit:junit:$junitVersion"
|
|
59
57
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
58
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
@@ -1,78 +1,111 @@
|
|
|
1
1
|
package ee.forgr.autofill_password;
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import com.getcapacitor.PluginCall;
|
|
6
|
-
import com.getcapacitor.PluginMethod;
|
|
7
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.os.Build;
|
|
8
5
|
import android.util.Log;
|
|
9
|
-
|
|
6
|
+
|
|
10
7
|
import androidx.credentials.CredentialManager;
|
|
11
|
-
import androidx.credentials.CredentialManagerCallback;
|
|
12
8
|
import androidx.credentials.CreatePasswordRequest;
|
|
13
9
|
import androidx.credentials.CreateCredentialResponse;
|
|
10
|
+
import androidx.credentials.PendingGetCredentialRequest;
|
|
11
|
+
import androidx.credentials.CredentialManagerCallback;
|
|
14
12
|
import androidx.credentials.exceptions.CreateCredentialException;
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
import com.getcapacitor.Plugin;
|
|
15
|
+
import com.getcapacitor.PluginCall;
|
|
16
|
+
import com.getcapacitor.PluginMethod;
|
|
17
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
|
+
|
|
19
|
+
import java.util.HashMap;
|
|
20
|
+
import java.util.Map;
|
|
21
|
+
|
|
22
|
+
import androidx.core.content.ContextCompat;
|
|
16
23
|
|
|
17
24
|
@CapacitorPlugin(name = "SavePassword")
|
|
18
25
|
public class SavePasswordPlugin extends Plugin {
|
|
26
|
+
private static final String TAG = "CredentialManager";
|
|
27
|
+
private CredentialManager credentialManager;
|
|
28
|
+
private Map<String, PendingGetCredentialRequest> pendingRequestsByElementId = new HashMap<>();
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
@Override
|
|
31
|
+
public void load() {
|
|
32
|
+
super.load();
|
|
33
|
+
try {
|
|
34
|
+
credentialManager = CredentialManager.create(getContext());
|
|
35
|
+
} catch (Exception e) {
|
|
36
|
+
Log.e(TAG, "Error initializing CredentialManager", e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
21
39
|
|
|
22
40
|
@PluginMethod
|
|
23
|
-
public void promptDialog(PluginCall call) {
|
|
41
|
+
public void promptDialog(final PluginCall call) {
|
|
42
|
+
if (!isCredentialManagerAvailable(call)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
24
46
|
String username = call.getString("username");
|
|
25
47
|
String password = call.getString("password");
|
|
26
48
|
|
|
27
49
|
if (username == null || username.isEmpty()) {
|
|
28
|
-
call.reject("Username
|
|
29
|
-
Log.w(TAG, "Username was null or empty.");
|
|
50
|
+
call.reject("Username is required");
|
|
30
51
|
return;
|
|
31
52
|
}
|
|
32
53
|
|
|
33
|
-
if (password == null) {
|
|
34
|
-
call.reject("Password
|
|
35
|
-
Log.w(TAG, "Password was null.");
|
|
54
|
+
if (password == null || password.isEmpty()) {
|
|
55
|
+
call.reject("Password is required");
|
|
36
56
|
return;
|
|
37
57
|
}
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
CredentialManager credentialManager = CredentialManager.create(getActivity());
|
|
50
|
-
|
|
51
|
-
// Set up executor and cancellation signal
|
|
52
|
-
Executor executor = getActivity().getMainExecutor();
|
|
53
|
-
CancellationSignal cancellationSignal = new CancellationSignal();
|
|
54
|
-
|
|
55
|
-
credentialManager.createCredentialAsync(
|
|
56
|
-
getActivity(),
|
|
57
|
-
createPasswordRequest,
|
|
58
|
-
cancellationSignal,
|
|
59
|
-
executor,
|
|
60
|
-
new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
|
|
61
|
-
@Override
|
|
62
|
-
public void onResult(CreateCredentialResponse result) {
|
|
63
|
-
JSObject response = new JSObject();
|
|
64
|
-
response.put("prompted", true);
|
|
65
|
-
Log.d(TAG, "Password save prompt completed successfully.");
|
|
66
|
-
call.resolve(response);
|
|
59
|
+
try {
|
|
60
|
+
// Build request directly with username & password (API 1.5.0 signature)
|
|
61
|
+
CreatePasswordRequest request = new CreatePasswordRequest(username, password);
|
|
62
|
+
|
|
63
|
+
// Execute on main thread
|
|
64
|
+
bridge.executeOnMainThread(() -> {
|
|
65
|
+
Activity activity = getActivity();
|
|
66
|
+
if (activity == null) {
|
|
67
|
+
call.reject("Activity not available");
|
|
68
|
+
return;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
try {
|
|
72
|
+
credentialManager.createCredentialAsync(
|
|
73
|
+
activity,
|
|
74
|
+
request,
|
|
75
|
+
null,
|
|
76
|
+
ContextCompat.getMainExecutor(getContext()),
|
|
77
|
+
new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
|
|
78
|
+
@Override
|
|
79
|
+
public void onResult(CreateCredentialResponse response) {
|
|
80
|
+
call.resolve();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Override
|
|
84
|
+
public void onError(CreateCredentialException e) {
|
|
85
|
+
call.reject("Error saving credential: " + e.getMessage(), e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
} catch (Exception e) {
|
|
90
|
+
call.reject("Error saving credential", e);
|
|
74
91
|
}
|
|
75
|
-
}
|
|
76
|
-
)
|
|
92
|
+
});
|
|
93
|
+
} catch (Exception e) {
|
|
94
|
+
call.reject("Error building save credential request", e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private boolean isCredentialManagerAvailable(PluginCall call) {
|
|
99
|
+
if (credentialManager == null) {
|
|
100
|
+
call.reject("Credential Manager not available on this device");
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
|
105
|
+
call.reject("Credential Manager requires Android API level 28 or higher");
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return true;
|
|
77
110
|
}
|
|
78
111
|
}
|
package/package.json
CHANGED