@capgo/capacitor-social-login 8.7.4 → 8.7.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/README.md +71 -19
- package/android/build.gradle +1 -2
- package/android/consumer-proguard-rules.pro +0 -9
- package/android/src/main/java/ee/forgr/capacitor/social/login/AppleProvider.java +56 -70
- package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleAuthorizationDecision.java +80 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleProvider.java +342 -173
- package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2Provider.java +155 -171
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +57 -7
- package/android/src/main/java/ee/forgr/capacitor/social/login/TwitterProvider.java +98 -110
- package/android/src/main/java/ee/forgr/capacitor/social/login/helpers/DependencyAvailabilityChecker.java +4 -28
- package/android/src/main/java/ee/forgr/capacitor/social/login/helpers/PluginHttpClient.java +430 -0
- package/dist/docs.json +3 -7
- package/dist/esm/definitions.d.ts +37 -6
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
package ee.forgr.capacitor.social.login.helpers;
|
|
2
|
+
|
|
3
|
+
import java.io.BufferedReader;
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.io.InputStream;
|
|
6
|
+
import java.io.InputStreamReader;
|
|
7
|
+
import java.io.OutputStream;
|
|
8
|
+
import java.net.HttpURLConnection;
|
|
9
|
+
import java.net.SocketTimeoutException;
|
|
10
|
+
import java.net.URL;
|
|
11
|
+
import java.net.URLEncoder;
|
|
12
|
+
import java.nio.charset.StandardCharsets;
|
|
13
|
+
import java.util.HashMap;
|
|
14
|
+
import java.util.Map;
|
|
15
|
+
import java.util.concurrent.ExecutorService;
|
|
16
|
+
import java.util.concurrent.Executors;
|
|
17
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Minimal async HTTP client using {@link HttpURLConnection} (replaces OkHttp for plugin HTTP calls).
|
|
21
|
+
*/
|
|
22
|
+
public final class PluginHttpClient {
|
|
23
|
+
|
|
24
|
+
private static final int EXECUTOR_THREADS = 4;
|
|
25
|
+
private static final int MAX_REDIRECT_HOPS = 5;
|
|
26
|
+
|
|
27
|
+
public static final PluginHttpClient DEFAULT = new PluginHttpClient(10_000, 10_000, 10_000);
|
|
28
|
+
public static final PluginHttpClient THIRTY_SECOND_TIMEOUTS = new PluginHttpClient(30_000, 30_000, 30_000);
|
|
29
|
+
|
|
30
|
+
private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(EXECUTOR_THREADS);
|
|
31
|
+
|
|
32
|
+
private final int connectTimeoutMs;
|
|
33
|
+
private final int readTimeoutMs;
|
|
34
|
+
private final int writeTimeoutMs;
|
|
35
|
+
|
|
36
|
+
public PluginHttpClient(int connectTimeoutMs, int readTimeoutMs, int writeTimeoutMs) {
|
|
37
|
+
this.connectTimeoutMs = connectTimeoutMs;
|
|
38
|
+
this.readTimeoutMs = readTimeoutMs;
|
|
39
|
+
this.writeTimeoutMs = writeTimeoutMs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public interface Callback {
|
|
43
|
+
void onFailure(IOException e);
|
|
44
|
+
|
|
45
|
+
void onResponse(int code, String body) throws IOException;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public void enqueueGet(String url, Map<String, String> headers, Callback callback) {
|
|
49
|
+
enqueue("GET", url, null, headers, callback);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public void enqueuePostForm(String url, Map<String, String> formFields, Map<String, String> headers, Callback callback) {
|
|
53
|
+
enqueue("POST", url, formFields, headers, callback);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int requestDeadlineMs() {
|
|
57
|
+
return connectTimeoutMs + writeTimeoutMs + readTimeoutMs;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private void enqueue(String method, String url, Map<String, String> formFields, Map<String, String> headers, Callback callback) {
|
|
61
|
+
EXECUTOR.execute(() -> {
|
|
62
|
+
final int requestDeadlineMs = requestDeadlineMs();
|
|
63
|
+
final AtomicReference<HttpURLConnection> connectionRef = new AtomicReference<>();
|
|
64
|
+
final int[] responseCode = new int[1];
|
|
65
|
+
final String[] responseBody = new String[1];
|
|
66
|
+
final IOException[] error = new IOException[1];
|
|
67
|
+
|
|
68
|
+
Thread worker = new Thread(
|
|
69
|
+
() -> {
|
|
70
|
+
try {
|
|
71
|
+
ExchangeResult result;
|
|
72
|
+
if ("POST".equals(method) && formFields != null) {
|
|
73
|
+
result = performPostFormExchange(url, formFields, headers, connectionRef);
|
|
74
|
+
} else {
|
|
75
|
+
result = performGetExchange(url, headers, connectionRef);
|
|
76
|
+
}
|
|
77
|
+
responseCode[0] = result.code;
|
|
78
|
+
responseBody[0] = result.body;
|
|
79
|
+
} catch (IOException e) {
|
|
80
|
+
error[0] = e;
|
|
81
|
+
} catch (RuntimeException e) {
|
|
82
|
+
error[0] = new IOException(e);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"PluginHttpClient-request"
|
|
86
|
+
);
|
|
87
|
+
worker.start();
|
|
88
|
+
try {
|
|
89
|
+
worker.join(requestDeadlineMs);
|
|
90
|
+
} catch (InterruptedException e) {
|
|
91
|
+
Thread.currentThread().interrupt();
|
|
92
|
+
HttpURLConnection connection = connectionRef.get();
|
|
93
|
+
if (connection != null) {
|
|
94
|
+
connection.disconnect();
|
|
95
|
+
}
|
|
96
|
+
worker.interrupt();
|
|
97
|
+
callback.onFailure(new IOException("Request interrupted", e));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (worker.isAlive()) {
|
|
101
|
+
worker.interrupt();
|
|
102
|
+
HttpURLConnection connection = connectionRef.get();
|
|
103
|
+
if (connection != null) {
|
|
104
|
+
connection.disconnect();
|
|
105
|
+
}
|
|
106
|
+
callback.onFailure(new SocketTimeoutException("Request timed out after " + requestDeadlineMs + "ms"));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (error[0] != null) {
|
|
110
|
+
callback.onFailure(error[0]);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
callback.onResponse(responseCode[0], responseBody[0]);
|
|
115
|
+
} catch (IOException e) {
|
|
116
|
+
callback.onFailure(e);
|
|
117
|
+
} catch (RuntimeException e) {
|
|
118
|
+
callback.onFailure(new IOException(e));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private static final class ExchangeResult {
|
|
124
|
+
|
|
125
|
+
final int code;
|
|
126
|
+
final String body;
|
|
127
|
+
|
|
128
|
+
ExchangeResult(int code, String body) {
|
|
129
|
+
this.code = code;
|
|
130
|
+
this.body = body;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private ExchangeResult performPostFormExchange(
|
|
135
|
+
String urlString,
|
|
136
|
+
Map<String, String> formFields,
|
|
137
|
+
Map<String, String> headers,
|
|
138
|
+
AtomicReference<HttpURLConnection> connectionRef
|
|
139
|
+
) throws IOException {
|
|
140
|
+
URL originalUrl = new URL(urlString);
|
|
141
|
+
byte[] body = encodeFormBody(formFields);
|
|
142
|
+
String currentUrl = urlString;
|
|
143
|
+
|
|
144
|
+
for (int hop = 0; hop <= MAX_REDIRECT_HOPS; hop++) {
|
|
145
|
+
HttpURLConnection connection = createPostFormConnection(currentUrl, body, headers);
|
|
146
|
+
connectionRef.set(connection);
|
|
147
|
+
try {
|
|
148
|
+
writePostFormBody(connection, body);
|
|
149
|
+
int code = connection.getResponseCode();
|
|
150
|
+
if (isRedirectStatus(code) && hop < MAX_REDIRECT_HOPS) {
|
|
151
|
+
String location = connection.getHeaderField("Location");
|
|
152
|
+
if (location == null || location.isEmpty()) {
|
|
153
|
+
return new ExchangeResult(code, readBody(connection, code));
|
|
154
|
+
}
|
|
155
|
+
URL destination = resolveRedirectUrl(new URL(currentUrl), location);
|
|
156
|
+
if (!isSafeRedirectDestination(originalUrl, destination)) {
|
|
157
|
+
throw new IOException("Refusing redirect to unsafe destination: " + destination);
|
|
158
|
+
}
|
|
159
|
+
if (code != 307 && code != 308) {
|
|
160
|
+
throw new IOException("POST form request cannot follow HTTP " + code + " redirect without losing credentials");
|
|
161
|
+
}
|
|
162
|
+
currentUrl = destination.toString();
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
return new ExchangeResult(code, readBody(connection, code));
|
|
166
|
+
} finally {
|
|
167
|
+
connection.disconnect();
|
|
168
|
+
clearConnectionRef(connectionRef, connection);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
throw new IOException("Too many HTTP redirects (max " + MAX_REDIRECT_HOPS + ")");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private ExchangeResult performGetExchange(
|
|
175
|
+
String urlString,
|
|
176
|
+
Map<String, String> headers,
|
|
177
|
+
AtomicReference<HttpURLConnection> connectionRef
|
|
178
|
+
) throws IOException {
|
|
179
|
+
URL originalUrl = new URL(urlString);
|
|
180
|
+
String currentUrl = urlString;
|
|
181
|
+
Map<String, String> currentHeaders = headers;
|
|
182
|
+
|
|
183
|
+
for (int hop = 0; hop <= MAX_REDIRECT_HOPS; hop++) {
|
|
184
|
+
HttpURLConnection connection = openGetConnection(currentUrl, currentHeaders);
|
|
185
|
+
connectionRef.set(connection);
|
|
186
|
+
try {
|
|
187
|
+
int code = connection.getResponseCode();
|
|
188
|
+
if (isRedirectStatus(code) && hop < MAX_REDIRECT_HOPS) {
|
|
189
|
+
String location = connection.getHeaderField("Location");
|
|
190
|
+
if (location == null || location.isEmpty()) {
|
|
191
|
+
return new ExchangeResult(code, readBody(connection, code));
|
|
192
|
+
}
|
|
193
|
+
URL destination = resolveRedirectUrl(new URL(currentUrl), location);
|
|
194
|
+
if (!isSafeGetRedirectDestination(originalUrl, destination)) {
|
|
195
|
+
throw new IOException("Refusing redirect to unsafe destination: " + destination);
|
|
196
|
+
}
|
|
197
|
+
currentUrl = destination.toString();
|
|
198
|
+
if (redirectChangesEffectiveOrigin(originalUrl, destination)) {
|
|
199
|
+
currentHeaders = headersWithoutAuthorization(headers);
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
return new ExchangeResult(code, readBody(connection, code));
|
|
204
|
+
} finally {
|
|
205
|
+
connection.disconnect();
|
|
206
|
+
clearConnectionRef(connectionRef, connection);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw new IOException("Too many HTTP redirects (max " + MAX_REDIRECT_HOPS + ")");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private static void clearConnectionRef(AtomicReference<HttpURLConnection> connectionRef, HttpURLConnection connection) {
|
|
213
|
+
if (connectionRef.get() == connection) {
|
|
214
|
+
connectionRef.set(null);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private static Map<String, String> headersWithoutAuthorization(Map<String, String> headers) {
|
|
219
|
+
if (headers == null || headers.isEmpty()) {
|
|
220
|
+
return headers;
|
|
221
|
+
}
|
|
222
|
+
Map<String, String> filtered = new HashMap<>();
|
|
223
|
+
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
224
|
+
if (entry.getKey() != null && entry.getKey().equalsIgnoreCase("Authorization")) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
filtered.put(entry.getKey(), entry.getValue());
|
|
228
|
+
}
|
|
229
|
+
return filtered;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static boolean isRedirectStatus(int code) {
|
|
233
|
+
return (
|
|
234
|
+
code == HttpURLConnection.HTTP_MOVED_PERM ||
|
|
235
|
+
code == HttpURLConnection.HTTP_MOVED_TEMP ||
|
|
236
|
+
code == 303 ||
|
|
237
|
+
code == 307 ||
|
|
238
|
+
code == 308
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static URL resolveRedirectUrl(URL base, String location) throws IOException {
|
|
243
|
+
return new URL(base, location);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* OAuth form posts must not follow redirects to a different host or downgrade HTTPS.
|
|
248
|
+
*/
|
|
249
|
+
static boolean isSafeRedirectDestination(URL original, URL destination) {
|
|
250
|
+
if (destination == null) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (destination.getUserInfo() != null) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
String originalHost = original.getHost();
|
|
257
|
+
String destinationHost = destination.getHost();
|
|
258
|
+
if (originalHost == null || destinationHost == null || originalHost.isEmpty() || destinationHost.isEmpty()) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
if (!originalHost.equalsIgnoreCase(destinationHost)) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if ("https".equalsIgnoreCase(original.getProtocol()) && !"https".equalsIgnoreCase(destination.getProtocol())) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* GET requests may follow cross-host redirects (OIDC discovery, tokeninfo) but must not downgrade HTTPS.
|
|
272
|
+
*/
|
|
273
|
+
static boolean isSafeGetRedirectDestination(URL original, URL destination) {
|
|
274
|
+
if (destination == null || destination.getUserInfo() != null) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
String host = destination.getHost();
|
|
278
|
+
if (host == null || host.isEmpty()) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
return !("https".equalsIgnoreCase(original.getProtocol()) && !"https".equalsIgnoreCase(destination.getProtocol()));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static int effectivePort(URL url) {
|
|
285
|
+
return url.getPort() != -1 ? url.getPort() : url.getDefaultPort();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static boolean redirectChangesEffectiveOrigin(URL original, URL destination) {
|
|
289
|
+
if (original.getHost() == null || destination.getHost() == null) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
return (
|
|
293
|
+
!original.getProtocol().equalsIgnoreCase(destination.getProtocol()) ||
|
|
294
|
+
!original.getHost().equalsIgnoreCase(destination.getHost()) ||
|
|
295
|
+
effectivePort(original) != effectivePort(destination)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private HttpURLConnection createPostFormConnection(String urlString, byte[] body, Map<String, String> headers) throws IOException {
|
|
300
|
+
HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection();
|
|
301
|
+
connection.setInstanceFollowRedirects(false);
|
|
302
|
+
connection.setConnectTimeout(connectTimeoutMs);
|
|
303
|
+
connection.setReadTimeout(readTimeoutMs);
|
|
304
|
+
connection.setRequestMethod("POST");
|
|
305
|
+
connection.setUseCaches(false);
|
|
306
|
+
if (headers != null) {
|
|
307
|
+
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
308
|
+
connection.setRequestProperty(entry.getKey(), entry.getValue());
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
connection.setDoOutput(true);
|
|
312
|
+
connection.setFixedLengthStreamingMode(body.length);
|
|
313
|
+
if (headers == null || !containsHeaderIgnoreCase(headers, "Content-Type")) {
|
|
314
|
+
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
315
|
+
}
|
|
316
|
+
return connection;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private void writePostFormBody(HttpURLConnection connection, byte[] body) throws IOException {
|
|
320
|
+
try (OutputStream out = connection.getOutputStream()) {
|
|
321
|
+
writeBodyWithTimeout(out, body, writeTimeoutMs, connection);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
private HttpURLConnection openGetConnection(String urlString, Map<String, String> headers) throws IOException {
|
|
326
|
+
HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection();
|
|
327
|
+
connection.setInstanceFollowRedirects(false);
|
|
328
|
+
connection.setConnectTimeout(connectTimeoutMs);
|
|
329
|
+
connection.setReadTimeout(readTimeoutMs);
|
|
330
|
+
connection.setRequestMethod("GET");
|
|
331
|
+
connection.setUseCaches(false);
|
|
332
|
+
if (headers != null) {
|
|
333
|
+
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
334
|
+
connection.setRequestProperty(entry.getKey(), entry.getValue());
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return connection;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* HttpURLConnection has no write timeout on Android; run the body write on a worker thread and bound wait time.
|
|
342
|
+
*/
|
|
343
|
+
static void writeBodyWithTimeout(OutputStream out, byte[] body, int writeTimeoutMs, HttpURLConnection connection) throws IOException {
|
|
344
|
+
if (writeTimeoutMs <= 0) {
|
|
345
|
+
out.write(body);
|
|
346
|
+
out.flush();
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
final IOException[] writeError = new IOException[1];
|
|
351
|
+
Thread writeThread = new Thread(
|
|
352
|
+
() -> {
|
|
353
|
+
try {
|
|
354
|
+
out.write(body);
|
|
355
|
+
out.flush();
|
|
356
|
+
} catch (IOException e) {
|
|
357
|
+
writeError[0] = e;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
"PluginHttpClient-write"
|
|
361
|
+
);
|
|
362
|
+
writeThread.start();
|
|
363
|
+
try {
|
|
364
|
+
writeThread.join(writeTimeoutMs);
|
|
365
|
+
} catch (InterruptedException e) {
|
|
366
|
+
Thread.currentThread().interrupt();
|
|
367
|
+
if (connection != null) {
|
|
368
|
+
connection.disconnect();
|
|
369
|
+
}
|
|
370
|
+
throw new IOException("Request body write interrupted", e);
|
|
371
|
+
}
|
|
372
|
+
if (writeThread.isAlive()) {
|
|
373
|
+
writeThread.interrupt();
|
|
374
|
+
if (connection != null) {
|
|
375
|
+
connection.disconnect();
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
writeThread.join(1_000);
|
|
379
|
+
} catch (InterruptedException e) {
|
|
380
|
+
Thread.currentThread().interrupt();
|
|
381
|
+
}
|
|
382
|
+
throw new SocketTimeoutException("Request body write timed out after " + writeTimeoutMs + "ms");
|
|
383
|
+
}
|
|
384
|
+
if (writeError[0] != null) {
|
|
385
|
+
throw writeError[0];
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private static boolean containsHeaderIgnoreCase(Map<String, String> headers, String name) {
|
|
390
|
+
for (String key : headers.keySet()) {
|
|
391
|
+
if (key != null && key.equalsIgnoreCase(name)) {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
static byte[] encodeFormBody(Map<String, String> formFields) throws IOException {
|
|
399
|
+
StringBuilder encoded = new StringBuilder();
|
|
400
|
+
for (Map.Entry<String, String> entry : formFields.entrySet()) {
|
|
401
|
+
if (encoded.length() > 0) {
|
|
402
|
+
encoded.append('&');
|
|
403
|
+
}
|
|
404
|
+
encoded.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.name()));
|
|
405
|
+
encoded.append('=');
|
|
406
|
+
encoded.append(URLEncoder.encode(entry.getValue() != null ? entry.getValue() : "", StandardCharsets.UTF_8.name()));
|
|
407
|
+
}
|
|
408
|
+
return encoded.toString().getBytes(StandardCharsets.UTF_8);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
private static String readBody(HttpURLConnection connection, int code) throws IOException {
|
|
412
|
+
InputStream stream = code >= 200 && code < 300 ? connection.getInputStream() : connection.getErrorStream();
|
|
413
|
+
if (stream == null) {
|
|
414
|
+
return "";
|
|
415
|
+
}
|
|
416
|
+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
|
417
|
+
StringBuilder sb = new StringBuilder();
|
|
418
|
+
char[] buffer = new char[4096];
|
|
419
|
+
int read;
|
|
420
|
+
while ((read = reader.read(buffer)) != -1) {
|
|
421
|
+
sb.append(buffer, 0, read);
|
|
422
|
+
}
|
|
423
|
+
return sb.toString();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
public static boolean isSuccessfulHttpCode(int code) {
|
|
428
|
+
return code >= 200 && code < 300;
|
|
429
|
+
}
|
|
430
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -146,16 +146,12 @@
|
|
|
146
146
|
],
|
|
147
147
|
"returns": "Promise<void>",
|
|
148
148
|
"tags": [
|
|
149
|
-
{
|
|
150
|
-
"name": "description",
|
|
151
|
-
"text": "refresh the access token\n\n**Google Offline Mode Limitation:**\nThis method is NOT supported when Google is initialized with `mode: 'offline'`.\nOffline mode only returns `serverAuthCode` for backend token exchange, so token refresh must happen on your backend.\nThe plugin logs and rejects with a message explaining that you should send `serverAuthCode` to your backend,\nrefresh the Google tokens there, or switch to `mode: 'online'` for client-side refresh.\n\n**Google Web Limitation:**\nOn Web, Google `refresh()` is not implemented, even when using `mode: 'online'`.\nCall `login()` again on Web to obtain a fresh token instead."
|
|
152
|
-
},
|
|
153
149
|
{
|
|
154
150
|
"name": "throws",
|
|
155
151
|
"text": "Error if Google provider is in offline mode, or on Web where Google `refresh()` is not implemented"
|
|
156
152
|
}
|
|
157
153
|
],
|
|
158
|
-
"docs": "Refresh the access token",
|
|
154
|
+
"docs": "Refresh the access token for the logged-in provider.\n\n**Google Android refresh behavior:**\nOn Android, when the saved ID token is still valid and either no access token is stored or Google access\ntoken validation succeeds within the timeout, `refresh()` resolves without updating either token. That\nearly return applies regardless of `skipAuthOnlyAuthorizationAfterSignIn`.\nIf validation fails or times out, `refresh()` continues even when a token remains stored; with\n`skipAuthOnlyAuthorizationAfterSignIn: true` and default OIDC scopes, a successful credential refresh\nthen clears that access token without obtaining a new one.\n\n**Google Offline Mode Limitation:**\nThis method is NOT supported when Google is initialized with `mode: 'offline'`.\nOffline mode only returns `serverAuthCode` for backend token exchange, so token refresh must happen on your backend.\nThe plugin logs and rejects with a message explaining that you should send `serverAuthCode` to your backend,\nrefresh the Google tokens there, or switch to `mode: 'online'` for client-side refresh.\n\n**Google Android `skipAuthOnlyAuthorizationAfterSignIn`:**\nWhen initialize sets `google.skipAuthOnlyAuthorizationAfterSignIn: true` and only default OIDC scopes are\nrequested, a refresh that runs past the early return skips `AuthorizationClient.authorize()`, updates the\nsaved `idToken`, and clears any saved access token; no new access token is obtained. Enabling the option\ndoes not clear a stored access token while the early return applies (validation succeeded or no token\nstored). With default `false`, refresh still skips authorize on the early return when no access token is\nstored but the ID token is valid.\n\n**Google Web Limitation:**\nOn Web, Google `refresh()` is not implemented, even when using `mode: 'online'`.\nCall `login()` again on Web to obtain a fresh token instead.",
|
|
159
155
|
"complexTypes": [
|
|
160
156
|
"LoginOptions"
|
|
161
157
|
],
|
|
@@ -437,7 +433,7 @@
|
|
|
437
433
|
"tags": [],
|
|
438
434
|
"docs": "",
|
|
439
435
|
"complexTypes": [],
|
|
440
|
-
"type": "{ iOSClientId?: string | undefined; iOSServerClientId?: string | undefined; webClientId?: string | undefined; mode?: 'online' | 'offline' | undefined; hostedDomain?: string | undefined; redirectUrl?: string | undefined; } | undefined"
|
|
436
|
+
"type": "{ iOSClientId?: string | undefined; iOSServerClientId?: string | undefined; webClientId?: string | undefined; mode?: 'online' | 'offline' | undefined; hostedDomain?: string | undefined; redirectUrl?: string | undefined; skipAuthOnlyAuthorizationAfterSignIn?: boolean | undefined; } | undefined"
|
|
441
437
|
},
|
|
442
438
|
{
|
|
443
439
|
"name": "apple",
|
|
@@ -1046,7 +1042,7 @@
|
|
|
1046
1042
|
{
|
|
1047
1043
|
"name": "accessToken",
|
|
1048
1044
|
"tags": [],
|
|
1049
|
-
"docs": "OAuth access token for Google APIs.\n\nMay be `null` on Android when
|
|
1045
|
+
"docs": "OAuth access token for Google APIs.\n\nMay be `null` on Android when AuthorizationClient does not return an access token, or when\n`skipAuthOnlyAuthorizationAfterSignIn` is enabled during initialize (opt-in). Use `idToken`\nfor user authentication; request additional Google API scopes when an access token is required.",
|
|
1050
1046
|
"complexTypes": [
|
|
1051
1047
|
"AccessToken"
|
|
1052
1048
|
],
|
|
@@ -428,6 +428,23 @@ export interface InitializeOptions {
|
|
|
428
428
|
* Google Redirect URL, should be your backend url that is configured in your google app
|
|
429
429
|
*/
|
|
430
430
|
redirectUrl?: string;
|
|
431
|
+
/**
|
|
432
|
+
* Android only. When `true`, skip `AuthorizationClient.authorize()` after Credential Manager sign-in
|
|
433
|
+
* when `mode` is `online` and only default OIDC scopes are requested. Use this on stock `BridgeActivity`
|
|
434
|
+
* apps that hit a hang during authorize; login may return `accessToken: null` while still returning
|
|
435
|
+
* `idToken` and profile. When refresh runs past its early return (saved ID token expired or missing, or
|
|
436
|
+
* access token validation failed or timed out), authentication-only scopes skip authorize, update the saved
|
|
437
|
+
* `idToken`, and clear any saved access token.
|
|
438
|
+
* Enabling this after a session still has valid saved tokens does not clear a stored access token when
|
|
439
|
+
* refresh's early return applies: saved ID token valid and either no access token stored or validation
|
|
440
|
+
* succeeds. Default `false` keeps prior behavior: authorize runs on login and refresh when needed, and
|
|
441
|
+
* `accessToken` is returned when Google provides one. With default `false`, refresh still returns without
|
|
442
|
+
* authorize when saved tokens are already valid, including when no access token is stored.
|
|
443
|
+
*
|
|
444
|
+
* @default false
|
|
445
|
+
* @since 8.8.0
|
|
446
|
+
*/
|
|
447
|
+
skipAuthOnlyAuthorizationAfterSignIn?: boolean;
|
|
431
448
|
};
|
|
432
449
|
apple?: {
|
|
433
450
|
/**
|
|
@@ -797,10 +814,9 @@ export interface GoogleLoginResponseOnline {
|
|
|
797
814
|
/**
|
|
798
815
|
* OAuth access token for Google APIs.
|
|
799
816
|
*
|
|
800
|
-
* May be `null` on Android when
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
* request additional Google API scopes when an access token is required.
|
|
817
|
+
* May be `null` on Android when AuthorizationClient does not return an access token, or when
|
|
818
|
+
* `skipAuthOnlyAuthorizationAfterSignIn` is enabled during initialize (opt-in). Use `idToken`
|
|
819
|
+
* for user authentication; request additional Google API scopes when an access token is required.
|
|
804
820
|
*/
|
|
805
821
|
accessToken: AccessToken | null;
|
|
806
822
|
/**
|
|
@@ -1363,8 +1379,15 @@ export interface SocialLoginPlugin {
|
|
|
1363
1379
|
*/
|
|
1364
1380
|
getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode>;
|
|
1365
1381
|
/**
|
|
1366
|
-
* Refresh the access token
|
|
1367
|
-
*
|
|
1382
|
+
* Refresh the access token for the logged-in provider.
|
|
1383
|
+
*
|
|
1384
|
+
* **Google Android refresh behavior:**
|
|
1385
|
+
* On Android, when the saved ID token is still valid and either no access token is stored or Google access
|
|
1386
|
+
* token validation succeeds within the timeout, `refresh()` resolves without updating either token. That
|
|
1387
|
+
* early return applies regardless of `skipAuthOnlyAuthorizationAfterSignIn`.
|
|
1388
|
+
* If validation fails or times out, `refresh()` continues even when a token remains stored; with
|
|
1389
|
+
* `skipAuthOnlyAuthorizationAfterSignIn: true` and default OIDC scopes, a successful credential refresh
|
|
1390
|
+
* then clears that access token without obtaining a new one.
|
|
1368
1391
|
*
|
|
1369
1392
|
* **Google Offline Mode Limitation:**
|
|
1370
1393
|
* This method is NOT supported when Google is initialized with `mode: 'offline'`.
|
|
@@ -1372,6 +1395,14 @@ export interface SocialLoginPlugin {
|
|
|
1372
1395
|
* The plugin logs and rejects with a message explaining that you should send `serverAuthCode` to your backend,
|
|
1373
1396
|
* refresh the Google tokens there, or switch to `mode: 'online'` for client-side refresh.
|
|
1374
1397
|
*
|
|
1398
|
+
* **Google Android `skipAuthOnlyAuthorizationAfterSignIn`:**
|
|
1399
|
+
* When initialize sets `google.skipAuthOnlyAuthorizationAfterSignIn: true` and only default OIDC scopes are
|
|
1400
|
+
* requested, a refresh that runs past the early return skips `AuthorizationClient.authorize()`, updates the
|
|
1401
|
+
* saved `idToken`, and clears any saved access token; no new access token is obtained. Enabling the option
|
|
1402
|
+
* does not clear a stored access token while the early return applies (validation succeeded or no token
|
|
1403
|
+
* stored). With default `false`, refresh still skips authorize on the early return when no access token is
|
|
1404
|
+
* stored but the ID token is valid.
|
|
1405
|
+
*
|
|
1375
1406
|
* **Google Web Limitation:**
|
|
1376
1407
|
* On Web, Google `refresh()` is not implemented, even when using `mode: 'online'`.
|
|
1377
1408
|
* Call `login()` again on Web to obtain a fresh token instead.
|