capacitor-oidc 0.0.5 → 0.0.6
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/android/build.gradle
CHANGED
|
@@ -71,5 +71,6 @@ dependencies {
|
|
|
71
71
|
implementation "androidx.activity:activity:$androidxActivityVersion"
|
|
72
72
|
implementation "androidx.browser:browser:$androidxBrowserVersion"
|
|
73
73
|
testImplementation "junit:junit:$junitVersion"
|
|
74
|
+
testImplementation "org.mockito:mockito-core:5.20.0"
|
|
74
75
|
testImplementation "org.json:json:20250517"
|
|
75
76
|
}
|
|
@@ -28,6 +28,7 @@ public final class CapacitorOidcPlugin extends Plugin {
|
|
|
28
28
|
private ActivityResultLauncher<Intent> authLauncher;
|
|
29
29
|
private PluginCall pendingAuthCall;
|
|
30
30
|
private Uri pendingCallback;
|
|
31
|
+
private boolean cancellationPending;
|
|
31
32
|
private TokenVault vault;
|
|
32
33
|
|
|
33
34
|
@Override
|
|
@@ -65,8 +66,7 @@ public final class CapacitorOidcPlugin extends Plugin {
|
|
|
65
66
|
|
|
66
67
|
boolean ephemeral = Boolean.TRUE.equals(call.getBoolean("prefersEphemeralWebBrowserSession", false));
|
|
67
68
|
AuthTabIntent authTab = new AuthTabIntent.Builder().setEphemeralBrowsingEnabled(ephemeral).build();
|
|
68
|
-
|
|
69
|
-
pendingCallback = callback;
|
|
69
|
+
beginAuth(call, callback);
|
|
70
70
|
|
|
71
71
|
try {
|
|
72
72
|
if ("https".equalsIgnoreCase(callback.getScheme())) {
|
|
@@ -100,6 +100,16 @@ public final class CapacitorOidcPlugin extends Plugin {
|
|
|
100
100
|
call.resolve(response);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
@Override
|
|
104
|
+
protected void handleOnResume() {
|
|
105
|
+
if (!cancellationPending) return;
|
|
106
|
+
|
|
107
|
+
// Android delivers both activity results and new intents before the next resume.
|
|
108
|
+
PluginCall call = pendingAuthCall;
|
|
109
|
+
clearPendingAuth();
|
|
110
|
+
if (call != null) call.reject("The authentication session was cancelled.", USER_CANCELLED);
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
@PluginMethod
|
|
104
114
|
public void storageSet(PluginCall call) {
|
|
105
115
|
String namespace = requiredString(call, "namespace");
|
|
@@ -174,32 +184,43 @@ public final class CapacitorOidcPlugin extends Plugin {
|
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
private void handleAuthResult(AuthTabIntent.AuthResult result) {
|
|
187
|
+
handleAuthResult(result.resultCode, result.resultUri);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
void handleAuthResult(int resultCode, Uri resultUri) {
|
|
177
191
|
PluginCall call = pendingAuthCall;
|
|
178
192
|
Uri expectedCallback = pendingCallback;
|
|
179
|
-
clearPendingAuth();
|
|
180
193
|
if (call == null) return;
|
|
181
194
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
195
|
+
if (resultCode == AuthTabIntent.RESULT_CANCELED) {
|
|
196
|
+
cancellationPending = true;
|
|
184
197
|
return;
|
|
185
198
|
}
|
|
186
|
-
|
|
199
|
+
clearPendingAuth();
|
|
200
|
+
if (resultCode != AuthTabIntent.RESULT_OK || resultUri == null) {
|
|
187
201
|
call.reject("The browser did not return a valid callback.", INVALID_CALLBACK);
|
|
188
202
|
return;
|
|
189
203
|
}
|
|
190
|
-
if (!CallbackUriMatcher.matches(
|
|
204
|
+
if (!CallbackUriMatcher.matches(resultUri, expectedCallback)) {
|
|
191
205
|
call.reject("The authentication callback does not match the configured redirect URL.", INVALID_CALLBACK);
|
|
192
206
|
return;
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
JSObject response = new JSObject();
|
|
196
|
-
response.put("url",
|
|
210
|
+
response.put("url", resultUri.toString());
|
|
197
211
|
call.resolve(response);
|
|
198
212
|
}
|
|
199
213
|
|
|
214
|
+
void beginAuth(PluginCall call, Uri callback) {
|
|
215
|
+
pendingAuthCall = call;
|
|
216
|
+
pendingCallback = callback;
|
|
217
|
+
cancellationPending = false;
|
|
218
|
+
}
|
|
219
|
+
|
|
200
220
|
private void clearPendingAuth() {
|
|
201
221
|
pendingAuthCall = null;
|
|
202
222
|
pendingCallback = null;
|
|
223
|
+
cancellationPending = false;
|
|
203
224
|
}
|
|
204
225
|
|
|
205
226
|
private static String requiredString(PluginCall call, String name) {
|
package/package.json
CHANGED