capacitor-auth-manager 3.1.1 → 3.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/AI-INTEGRATION-GUIDE.md +4 -3
- package/CHANGELOG.md +15 -0
- package/README.md +25 -25
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthLogger.java +9 -1
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleCredentialManagerSignIn.java +2 -1
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleLegacySignIn.java +1 -1
- package/dist/core.cjs.js +53 -8
- package/dist/esm/definitions.d.ts +3 -1
- package/dist/esm/providers/oauth-provider.js +4 -6
- package/dist/esm/providers/web/google-provider.d.ts +13 -6
- package/dist/esm/providers/web/google-provider.js +53 -8
- package/dist/plugin.js +53 -8
- package/dist/providers-web.cjs.js +53 -8
- package/package.json +22 -21
- package/scripts/configure.js +0 -0
package/AI-INTEGRATION-GUIDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Capacitor Auth Manager: AI integration guide
|
|
2
2
|
|
|
3
|
-
Release: **3.
|
|
3
|
+
Release: **3.2.0**. Audience: Claude Code, Codex, and developers integrating Google sign-in.
|
|
4
4
|
Use this guide from the installed package; the npm README and [documentation](https://capacitor-auth-manager-docs.aoneahsan.com) describe the same release.
|
|
5
5
|
|
|
6
6
|
<a id="table-of-contents"></a>
|
|
@@ -38,7 +38,7 @@ The root exports the `auth` singleton, `AuthProvider`, `AuthErrorCode`, `AuthErr
|
|
|
38
38
|
## 📦 Setup [#](#setup)
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
yarn add capacitor-auth-manager@3.
|
|
41
|
+
yarn add capacitor-auth-manager@3.2.0 @capacitor/core firebase
|
|
42
42
|
# Native applications only, after the platform projects exist:
|
|
43
43
|
yarn cap sync
|
|
44
44
|
```
|
|
@@ -128,6 +128,7 @@ For authenticated backend requests, get a **Firebase** ID token from `firebaseAu
|
|
|
128
128
|
|---|---|
|
|
129
129
|
| Web `webFlow: 'popup'` | `accessToken`; no `idToken` or refresh token |
|
|
130
130
|
| Web `webFlow: 'one-tap'` | `idToken`; no access token |
|
|
131
|
+
| Web `webFlow: 'button'` | `idToken` from a rendered Google button; no access token or One-Tap prompt |
|
|
131
132
|
| Web `webFlow: 'auto'` (default) | One-Tap ID token or popup access token; suppression may require another click to open a popup |
|
|
132
133
|
| Android | `idToken`; no access token/server auth code from the sign-in call |
|
|
133
134
|
| iOS | `idToken`, `accessToken`, optional `serverAuthCode` when configured |
|
|
@@ -164,7 +165,7 @@ promises; never log credentials, tokens, or client secrets. The browser validate
|
|
|
164
165
|
expiry, a configured nonce, and a configured Workspace domain, but does not verify JWT signatures.
|
|
165
166
|
Google/Firebase/server verification establishes trust. Never send an OAuth access token to an ID-token-only backend.
|
|
166
167
|
|
|
167
|
-
For a custom ID-token backend, choose the One-Tap
|
|
168
|
+
For a custom ID-token backend, choose the One-Tap, rendered-button or native ID-token path, require `credential.idToken`, verify
|
|
168
169
|
signature/issuer/audience/expiry/nonce on the server, and issue your own session. Do not decode a token and trust its claims.
|
|
169
170
|
|
|
170
171
|
<a id="acceptance"></a>
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to `capacitor-auth-manager` are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.2.0] — 2026-11-10
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Web `webFlow: 'button'` waits for an ID token from `GoogleAuthProviderWeb.renderButton()` without
|
|
13
|
+
opening One-Tap or the OAuth2 popup. The wait ends after two minutes and can be canceled by
|
|
14
|
+
`signOut()` or `dispose()`.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- The rendered-button example now uses `webFlow: 'button'`. A suppressed One-Tap prompt no longer
|
|
19
|
+
leaves that example waiting for a credential it can't receive.
|
|
20
|
+
- A One-Tap result that arrives late no longer completes a `button` sign-in, and Google Identity Services is
|
|
21
|
+
initialized once per login hint instead of on every sign-in.
|
|
22
|
+
|
|
8
23
|
## [3.1.1] — 2026-10-29
|
|
9
24
|
|
|
10
25
|
### Fixed
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ adapters ship with it, so the sign-in button is a few lines in whichever framewo
|
|
|
31
31
|
|
|
32
32
|
| | |
|
|
33
33
|
|---|---|
|
|
34
|
-
| **Version** | `3.
|
|
34
|
+
| **Version** | `3.2.0` |
|
|
35
35
|
| **License** | MIT |
|
|
36
36
|
| **Node** | `>=24.0.0` |
|
|
37
37
|
| **Platforms** | Web · iOS · Android |
|
|
@@ -110,12 +110,12 @@ Firebase-popup web flow that works and no native build to support.
|
|
|
110
110
|
|
|
111
111
|
| Platform | Supported | Notes |
|
|
112
112
|
|---|---|---|
|
|
113
|
-
| Web | ✅ | Google Identity Services. One-Tap / FedCM
|
|
113
|
+
| Web | ✅ | Google Identity Services. One-Tap / FedCM and Google's rendered button return an `idToken`; the OAuth2 popup fallback returns an `accessToken` (`webFlow`). |
|
|
114
114
|
| Android | ✅ | GoogleSignIn account chooser, falling back to Credential Manager (bottom sheet, then the Sign in with Google button) — `androidFlow`. `serverClientId` is required to receive an `idToken`. |
|
|
115
115
|
| iOS | ✅ | GoogleSignIn 10.x; iOS 15+. Returns `idToken`, `accessToken`, and `serverAuthCode` when configured. |
|
|
116
116
|
| Node / SSR | ✅ import | Importing is side-effect free since `3.0.0`; sign-in itself still needs a browser or a device. |
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
Local release checks compile a clean Capacitor 8 consumer for Android debug and minified release builds. On macOS, run the iOS simulator compile check. Test sign-in with your app's OAuth clients on deployed devices before rollout.
|
|
119
119
|
|
|
120
120
|
<a id="requirements"></a>
|
|
121
121
|
## 📋 Requirements [#](#requirements)
|
|
@@ -202,7 +202,7 @@ await signInWithCredential(getAuth(), GoogleAuthProvider.credential(result.crede
|
|
|
202
202
|
|
|
203
203
|
```ts
|
|
204
204
|
const { credential } = await auth.signIn(AuthProvider.GOOGLE);
|
|
205
|
-
if (!credential.idToken) throw new Error('This backend requires an ID token; use webFlow one-tap');
|
|
205
|
+
if (!credential.idToken) throw new Error('This backend requires an ID token; use webFlow one-tap or button');
|
|
206
206
|
await fetch('/api/session', {
|
|
207
207
|
method: 'POST',
|
|
208
208
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -285,7 +285,7 @@ Google provider options:
|
|
|
285
285
|
| `filterByAuthorizedAccounts` | Android | Show only previously authorised accounts. |
|
|
286
286
|
| `autoSelectEnabled` | Android | Allow one-tap auto-select for returning users. |
|
|
287
287
|
| `nonce` | web | Bind the request to an id-token `nonce` claim, which the package validates. |
|
|
288
|
-
| `webFlow` | web | `'auto'` (default: One-Tap, then the OAuth2 popup if One-Tap is not shown) · `'one-tap'` · `'popup'`. Also accepted per call in `signIn({ options })`. |
|
|
288
|
+
| `webFlow` | web | `'auto'` (default: One-Tap, then the OAuth2 popup if One-Tap is not shown) · `'one-tap'` · `'button'` (wait for the rendered Google button's ID token) · `'popup'`. Also accepted per call in `signIn({ options })`. |
|
|
289
289
|
| `androidFlow` | Android | `'auto'` (default: GoogleSignIn, then Credential Manager if it fails for any reason other than a cancel) · `'legacy'` · `'credential-manager'` · `'bottom-sheet'` · `'button'`. Also accepted per call. |
|
|
290
290
|
|
|
291
291
|
The same Google options can live in `capacitor.config` under the plugin block instead of in application code.
|
|
@@ -369,9 +369,9 @@ It asks for Web/iOS OAuth client IDs and creates `capacitor-auth.config.json` pl
|
|
|
369
369
|
- **Custom secure storage** — implement `StorageInterface` over Keychain or Keystore and pass it as
|
|
370
370
|
`storage` instead of the default web storage.
|
|
371
371
|
- **Nonce validation** — supply `nonce` on web and the package checks the returned id token's claim against it.
|
|
372
|
-
- **Google's own button** — when One-Tap is
|
|
373
|
-
|
|
374
|
-
|
|
372
|
+
- **Google's own button** — when One-Tap is in its cooldown window, render Google's official button
|
|
373
|
+
yourself. `renderButton` lives on the web provider class, not on the `auth` singleton, so construct it
|
|
374
|
+
directly:
|
|
375
375
|
|
|
376
376
|
```ts
|
|
377
377
|
import { GoogleAuthProviderWeb } from 'capacitor-auth-manager/providers/web';
|
|
@@ -379,12 +379,15 @@ It asks for Web/iOS OAuth client IDs and creates `capacitor-auth.config.json` pl
|
|
|
379
379
|
const google = new GoogleAuthProviderWeb({ clientId: import.meta.env.VITE_GOOGLE_WEB_CLIENT_ID });
|
|
380
380
|
// renderButton initializes the provider on demand; options default to { theme: 'outline', size: 'large' }
|
|
381
381
|
await google.renderButton(document.getElementById('google-btn')!);
|
|
382
|
-
//
|
|
383
|
-
const
|
|
382
|
+
// Start waiting before the user selects Google's button:
|
|
383
|
+
const credentialPromise = google.signIn({ options: { webFlow: 'button' } });
|
|
384
|
+
// After the user selects it:
|
|
385
|
+
const result = await credentialPromise;
|
|
384
386
|
```
|
|
385
387
|
|
|
386
|
-
The button
|
|
387
|
-
`
|
|
388
|
+
The button returns an `idToken`. A `button` sign-in doesn't open One-Tap or the OAuth2 popup, and a
|
|
389
|
+
One-Tap result that arrives late can't complete it. The wait lasts up to two minutes; `signOut()` or
|
|
390
|
+
`dispose()` cancels it. If it ends before the user selects the button, start another `button` sign-in.
|
|
388
391
|
- **Log level control** — `defaultLogger.setLevel('debug')`, or the `VITE_LOG_LEVEL` / `LOG_LEVEL` build
|
|
389
392
|
variables, without touching `console` directly.
|
|
390
393
|
- **Config in `capacitor.config`** — keep the Google block in native config instead of application code.
|
|
@@ -398,7 +401,7 @@ It asks for Web/iOS OAuth client IDs and creates `capacitor-auth.config.json` pl
|
|
|
398
401
|
| `PROVIDER_NOT_ENABLED` | that provider is not enabled yet in `3.x` | Only Google is available today — see [Roadmap](#roadmap) |
|
|
399
402
|
| `window is not defined` on the server | you are on `< 3.0.0` | Upgrade — the singleton is lazy and storage is guarded since `3.0.0` |
|
|
400
403
|
| `Cannot find module '…/core/auth-manager'` under Node | you are on `< 3.0.0` | Upgrade — every relative specifier carries its `.js` extension since `3.0.0` |
|
|
401
|
-
| `POPUP_BLOCKED` on web with `webFlow: 'one-tap'` | One-Tap is suppressed (cooldown, FedCM opt-out, third-party cookies) | Use the default `webFlow: 'auto'` (falls back to the popup) or `'popup'`, or draw Google's button
|
|
404
|
+
| `POPUP_BLOCKED` on web with `webFlow: 'one-tap'` | One-Tap is suppressed (cooldown, FedCM opt-out, third-party cookies) | Use the default `webFlow: 'auto'` (falls back to the popup) or `'popup'`, or draw Google's button and use `webFlow: 'button'` — see [Advanced Features](#advanced-features) |
|
|
402
405
|
| `USER_CANCELLED` / `POPUP_CLOSED_BY_USER` | the user closed One-Tap or the popup | Expected — show your own "try again" |
|
|
403
406
|
| Android error names `signing SHA-1=…` | Google has no Android OAuth client for that package + certificate | Register that exact SHA-1 for the app (a Play-installed build reports the Play App Signing key). No new build is needed |
|
|
404
407
|
| Play builds fail with no account picker on `3.0.0` | Credential Manager refused the request (on Android 14+ it depends on the device's credential-provider settings) | Upgrade to `3.1.0`: the default flow uses GoogleSignIn first |
|
|
@@ -413,16 +416,15 @@ Stated as plainly as the features, because each one otherwise costs an afternoon
|
|
|
413
416
|
- **Google is the only working provider.** Fourteen others exist in the source and throw
|
|
414
417
|
`PROVIDER_NOT_ENABLED` when called.
|
|
415
418
|
- **`@capacitor/core` is a required peer.** The native bridge imports it even in a web-only build.
|
|
416
|
-
- **Web returns one token per flow.** One-Tap
|
|
419
|
+
- **Web returns one token per flow.** One-Tap and the rendered Google button yield an `idToken` and no `accessToken`; the OAuth2 popup
|
|
417
420
|
yields an `accessToken` and no `idToken`. Firebase accepts either
|
|
418
|
-
(`GoogleAuthProvider.credential(idToken ?? null, accessToken)`); an ID-token-only backend must explicitly select One-Tap and reject a missing ID token.
|
|
421
|
+
(`GoogleAuthProvider.credential(idToken ?? null, accessToken)`); an ID-token-only backend must explicitly select One-Tap or the rendered button and reject a missing ID token.
|
|
419
422
|
- **Android returns an `idToken` only.** Access tokens come from the separate Google Authorization API.
|
|
420
423
|
Only iOS returns everything.
|
|
421
424
|
- **Android GoogleSignIn is deprecated by Google** and was removed in `play-services-auth` 22, so the
|
|
422
425
|
package pins 21.x. Do not force `play-services-auth` 22 in your app, or `'auto'` falls through to Credential Manager.
|
|
423
426
|
- **No id-token verification in the browser.** Signature and claim checks belong to your server, or Firebase.
|
|
424
|
-
- **
|
|
425
|
-
version on one real device before rolling it out widely.
|
|
427
|
+
- **Consumer builds check compilation.** Test sign-in on a device before rolling out a new version.
|
|
426
428
|
- **`serverAuthCode` must never be exchanged client-side.** It is returned on iOS for your backend to use.
|
|
427
429
|
|
|
428
430
|
<a id="faq"></a>
|
|
@@ -436,7 +438,7 @@ option among several.
|
|
|
436
438
|
Yes — skip `yarn cap sync`. You still need `@capacitor/core` installed, because the published bundle imports it.
|
|
437
439
|
|
|
438
440
|
**Which token does web return?**
|
|
439
|
-
One-Tap
|
|
441
|
+
One-Tap and Google's rendered button return `idToken`; popup returns `accessToken`. The default auto flow can return either. Firebase accepts both fields through `GoogleAuthProvider.credential(idToken ?? null, accessToken ?? null)`.
|
|
440
442
|
|
|
441
443
|
**Which client ID goes where?**
|
|
442
444
|
The **Web** client ID is used as `clientId` on web and as `serverClientId` on Android. The iOS client ID is
|
|
@@ -466,7 +468,7 @@ Server imports are safe. Configure/prepare/sign in in browser code or client com
|
|
|
466
468
|
<a id="changelog"></a>
|
|
467
469
|
## 🔄 Changelog [#](#changelog)
|
|
468
470
|
|
|
469
|
-
Latest release: **`3.
|
|
471
|
+
Latest release: **`3.2.0`** — web `webFlow: 'button'` waits for an ID token from `GoogleAuthProviderWeb.renderButton()` without opening One-Tap or the OAuth2 popup. See the changelog for the full history.
|
|
470
472
|
|
|
471
473
|
Full history: [CHANGELOG.md](https://github.com/aoneahsan/capacitor-auth-manager/blob/main/CHANGELOG.md).
|
|
472
474
|
|
|
@@ -482,12 +484,10 @@ Dates are deliberately absent; each item ships when it is verified rather than w
|
|
|
482
484
|
<a id="contributing"></a>
|
|
483
485
|
## 🤝 Contributing [#](#contributing)
|
|
484
486
|
|
|
485
|
-
|
|
486
|
-
[
|
|
487
|
-
setup
|
|
488
|
-
|
|
489
|
-
[SECURITY.md](https://github.com/aoneahsan/capacitor-auth-manager/blob/main/.github/SECURITY.md) rather than
|
|
490
|
-
the public tracker.
|
|
487
|
+
Start with an issue describing the change. The
|
|
488
|
+
[contribution guide](https://github.com/aoneahsan/capacitor-auth-manager/blob/main/.github/CONTRIBUTING.md)
|
|
489
|
+
covers setup and local checks. Report security issues through
|
|
490
|
+
[SECURITY.md](https://github.com/aoneahsan/capacitor-auth-manager/blob/main/.github/SECURITY.md).
|
|
491
491
|
|
|
492
492
|
<a id="support"></a>
|
|
493
493
|
## 💬 Support [#](#support)
|
|
@@ -72,6 +72,14 @@ public class AuthLogger {
|
|
|
72
72
|
public void warn(String message, Object... args) {
|
|
73
73
|
log(LogLevel.WARN, message, args);
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Writes the Google sign-in path and outcome in release builds. Callers pass only fixed path names,
|
|
78
|
+
* success, or an exception class; never an account identifier, message, credential, or token.
|
|
79
|
+
*/
|
|
80
|
+
public void googleSignInDiagnostic(String path, String outcome) {
|
|
81
|
+
Log.i(tag, formatMessage("Google sign-in path=" + path + " outcome=" + outcome));
|
|
82
|
+
}
|
|
75
83
|
|
|
76
84
|
/**
|
|
77
85
|
* Always written, like {@link #warn}: a failed sign-in must be readable in logcat on a release build,
|
|
@@ -118,4 +126,4 @@ public class AuthLogger {
|
|
|
118
126
|
private String formatMessage(String message) {
|
|
119
127
|
return "[" + PREFIX + "] " + message;
|
|
120
128
|
}
|
|
121
|
-
}
|
|
129
|
+
}
|
|
@@ -131,7 +131,7 @@ final class GoogleCredentialManagerSignIn {
|
|
|
131
131
|
&& GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL.equals(credential.getType())) {
|
|
132
132
|
GoogleIdTokenCredential google = GoogleIdTokenCredential.createFrom(((CustomCredential) credential).getData());
|
|
133
133
|
Uri photo = google.getProfilePictureUri();
|
|
134
|
-
logger.
|
|
134
|
+
logger.googleSignInDiagnostic("credential-manager", "success");
|
|
135
135
|
callback.onSuccess(new GoogleResultMapper.Profile(google.getIdToken(), google.getId(),
|
|
136
136
|
google.getDisplayName(), photo != null ? photo.toString() : null, null, null));
|
|
137
137
|
} else {
|
|
@@ -149,6 +149,7 @@ final class GoogleCredentialManagerSignIn {
|
|
|
149
149
|
|
|
150
150
|
/** Keeps Google's own class + message ({@code [28444] …}) and names the package + signing SHA-1. */
|
|
151
151
|
private AuthException mapError(GetCredentialException e) {
|
|
152
|
+
logger.googleSignInDiagnostic("credential-manager", e.getClass().getSimpleName());
|
|
152
153
|
if (e instanceof GetCredentialCancellationException) {
|
|
153
154
|
logger.info("Google sign-in cancelled by user");
|
|
154
155
|
return new AuthException(AuthErrorCodes.USER_CANCELLED, "User cancelled Google sign-in", e);
|
|
@@ -98,7 +98,7 @@ final class GoogleLegacySignIn {
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
String photo = account.getPhotoUrl() != null ? account.getPhotoUrl().toString() : null;
|
|
101
|
-
logger.
|
|
101
|
+
logger.googleSignInDiagnostic("legacy", "success");
|
|
102
102
|
callback.onSuccess(new GoogleResultMapper.Profile(account.getIdToken(), account.getEmail(),
|
|
103
103
|
account.getDisplayName(), photo, account.getId(), account.getServerAuthCode()));
|
|
104
104
|
} catch (ApiException e) {
|
package/dist/core.cjs.js
CHANGED
|
@@ -2347,12 +2347,14 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
2347
2347
|
/**
|
|
2348
2348
|
* Web Google provider — the implementation the registry loads on **web / electron**.
|
|
2349
2349
|
*
|
|
2350
|
-
*
|
|
2350
|
+
* Three Google Identity Services flows are available, selected by {@link GoogleAuthOptions.webFlow}
|
|
2351
2351
|
* (default `'auto'`):
|
|
2352
2352
|
*
|
|
2353
2353
|
* 1. **One-Tap / FedCM id-token flow** (`google.accounts.id`): returns a Google **ID token** (JWT) as
|
|
2354
2354
|
* `result.credential.idToken` — the same field the native providers populate.
|
|
2355
|
-
* 2. **
|
|
2355
|
+
* 2. **Rendered-button ID-token flow** (`google.accounts.id.renderButton`): waits for a click on
|
|
2356
|
+
* Google's button without opening One-Tap; returns `result.credential.idToken`.
|
|
2357
|
+
* 3. **OAuth2 popup flow** (`google.accounts.oauth2.initTokenClient`): a deterministic popup that works
|
|
2356
2358
|
* from any click handler and returns an **access token** as `result.credential.accessToken`; the user
|
|
2357
2359
|
* profile is read from Google's `userinfo` endpoint. `'auto'` falls back to this whenever the browser
|
|
2358
2360
|
* does not display One-Tap (cooldown, FedCM opt-out, third-party-cookie settings).
|
|
@@ -2362,8 +2364,8 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
2362
2364
|
* const { idToken, accessToken } = result.credential;
|
|
2363
2365
|
* await signInWithCredential(getAuth(), GoogleAuthProvider.credential(idToken ?? null, accessToken));
|
|
2364
2366
|
*
|
|
2365
|
-
*
|
|
2366
|
-
* {@link renderButton}
|
|
2367
|
+
* These flows need no client secret or backend. For Google's official button, call
|
|
2368
|
+
* {@link renderButton}, then {@link signIn} with `webFlow: 'button'` before it is selected.
|
|
2367
2369
|
*/
|
|
2368
2370
|
class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
2369
2371
|
constructor(config) {
|
|
@@ -2378,6 +2380,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2378
2380
|
this.pendingTimer = null;
|
|
2379
2381
|
this.requestRevision = 0;
|
|
2380
2382
|
this.pendingPopupReject = null;
|
|
2383
|
+
this.hasRenderedButton = false;
|
|
2384
|
+
this.pendingCredentialFlow = null;
|
|
2385
|
+
this.idConfigured = false;
|
|
2381
2386
|
}
|
|
2382
2387
|
get name() {
|
|
2383
2388
|
return AuthProvider.GOOGLE;
|
|
@@ -2416,6 +2421,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2416
2421
|
if (flow === 'popup') {
|
|
2417
2422
|
return await this.signInWithPopup(loginHint);
|
|
2418
2423
|
}
|
|
2424
|
+
if (flow === 'button') {
|
|
2425
|
+
return await this.signInWithButton();
|
|
2426
|
+
}
|
|
2419
2427
|
return await this.signInWithOneTap(flow === 'auto', loginHint);
|
|
2420
2428
|
}
|
|
2421
2429
|
finally {
|
|
@@ -2424,8 +2432,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2424
2432
|
}
|
|
2425
2433
|
/**
|
|
2426
2434
|
* Renders Google's official "Sign in with Google" button into `parent`. Use this when you want
|
|
2427
|
-
* Google's branded button rather than your own.
|
|
2428
|
-
*
|
|
2435
|
+
* Google's branded button rather than your own. Call {@link signIn} with `webFlow: 'button'`
|
|
2436
|
+
* before the user clicks it to receive the ID-token credential.
|
|
2429
2437
|
*/
|
|
2430
2438
|
async renderButton(parent, options = { theme: 'outline', size: 'large' }) {
|
|
2431
2439
|
if (!this.isInitialized) {
|
|
@@ -2433,6 +2441,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2433
2441
|
}
|
|
2434
2442
|
this.configureIdClient();
|
|
2435
2443
|
this.requireIdApi().renderButton(parent, options);
|
|
2444
|
+
this.hasRenderedButton = true;
|
|
2436
2445
|
}
|
|
2437
2446
|
async signOut(_options) {
|
|
2438
2447
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -2470,7 +2479,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2470
2479
|
return cached.idToken;
|
|
2471
2480
|
}
|
|
2472
2481
|
if (cached && !cached.idToken && !forceRefresh) {
|
|
2473
|
-
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap".', AuthProvider.GOOGLE);
|
|
2482
|
+
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap" or "button".', AuthProvider.GOOGLE);
|
|
2474
2483
|
}
|
|
2475
2484
|
const result = await this.signIn({
|
|
2476
2485
|
provider: AuthProvider.GOOGLE,
|
|
@@ -2524,27 +2533,46 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2524
2533
|
}
|
|
2525
2534
|
}
|
|
2526
2535
|
// --- One-Tap flow --------------------------------------------------------------------------------
|
|
2536
|
+
signInWithButton() {
|
|
2537
|
+
if (!this.hasRenderedButton) {
|
|
2538
|
+
throw new AuthError(AuthErrorCode.MISSING_CONFIGURATION, 'webFlow "button" needs a rendered Google button. Call renderButton() first.', AuthProvider.GOOGLE);
|
|
2539
|
+
}
|
|
2540
|
+
return new Promise((resolve, reject) => {
|
|
2541
|
+
this.pendingResolve = resolve;
|
|
2542
|
+
this.pendingReject = reject;
|
|
2543
|
+
this.pendingCredentialFlow = 'button';
|
|
2544
|
+
this.pendingTimer = setTimeout(() => {
|
|
2545
|
+
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'The Google button returned no credential within two minutes. Start another webFlow "button" sign-in, then select the button.', AuthProvider.GOOGLE));
|
|
2546
|
+
}, 120000);
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2527
2549
|
signInWithOneTap(fallbackToPopup, loginHint) {
|
|
2528
2550
|
this.configureIdClient(loginHint);
|
|
2529
2551
|
return new Promise((resolve, reject) => {
|
|
2530
2552
|
this.pendingResolve = resolve;
|
|
2531
2553
|
this.pendingReject = (e) => reject(e);
|
|
2554
|
+
this.pendingCredentialFlow = 'one-tap';
|
|
2532
2555
|
this.pendingTimer = setTimeout(() => {
|
|
2533
2556
|
var _a, _b, _c;
|
|
2534
2557
|
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'Google One-Tap did not return a credential. Retry from a click with webFlow "popup", or use the Google button.', AuthProvider.GOOGLE));
|
|
2535
2558
|
(_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.cancel();
|
|
2536
2559
|
}, 120000);
|
|
2537
2560
|
const fallback = (reason) => {
|
|
2561
|
+
if (this.pendingResolve !== resolve)
|
|
2562
|
+
return;
|
|
2538
2563
|
this.logger.info(`Google One-Tap not shown (${reason}); using the popup flow`);
|
|
2539
2564
|
// Drop the One-Tap resolvers so a late credential callback cannot double-resolve.
|
|
2540
2565
|
this.pendingResolve = null;
|
|
2541
2566
|
this.pendingReject = null;
|
|
2567
|
+
this.pendingCredentialFlow = null;
|
|
2542
2568
|
this.clearPendingTimer();
|
|
2543
2569
|
this.signInWithPopup(loginHint).then(resolve, reject);
|
|
2544
2570
|
};
|
|
2545
2571
|
try {
|
|
2546
2572
|
this.requireIdApi().prompt((notification) => {
|
|
2547
2573
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2574
|
+
if (this.pendingResolve !== resolve)
|
|
2575
|
+
return;
|
|
2548
2576
|
// These moment methods are deprecated under FedCM and may throw — guard every call.
|
|
2549
2577
|
try {
|
|
2550
2578
|
const notDisplayed = (_b = (_a = notification.isNotDisplayed) === null || _a === void 0 ? void 0 : _a.call(notification)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -2575,6 +2603,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2575
2603
|
});
|
|
2576
2604
|
}
|
|
2577
2605
|
catch (error) {
|
|
2606
|
+
if (this.pendingResolve !== resolve)
|
|
2607
|
+
return;
|
|
2578
2608
|
if (fallbackToPopup) {
|
|
2579
2609
|
fallback(error instanceof Error ? error.message : 'prompt failed');
|
|
2580
2610
|
}
|
|
@@ -2588,6 +2618,12 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2588
2618
|
// Ignore a late callback after cancellation, timeout, or popup fallback.
|
|
2589
2619
|
if (!this.pendingResolve)
|
|
2590
2620
|
return;
|
|
2621
|
+
// Google labels button responses separately from One-Tap. A late One-Tap result must not
|
|
2622
|
+
// satisfy a newer wait that explicitly required a click on the rendered button.
|
|
2623
|
+
if (this.pendingCredentialFlow === 'button' &&
|
|
2624
|
+
response.select_by !== 'btn' &&
|
|
2625
|
+
response.select_by !== 'btn_confirm')
|
|
2626
|
+
return;
|
|
2591
2627
|
if (response.error || !response.credential) {
|
|
2592
2628
|
this.rejectPending(new AuthError(AuthErrorCode.SIGN_IN_FAILED, response.error_description ||
|
|
2593
2629
|
response.error ||
|
|
@@ -2747,6 +2783,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2747
2783
|
const options = this.options;
|
|
2748
2784
|
const clientId = this.requireClientId();
|
|
2749
2785
|
this.currentNonce = options.nonce;
|
|
2786
|
+
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
2787
|
+
if (this.idConfigured && this.configuredIdHint === hint)
|
|
2788
|
+
return;
|
|
2750
2789
|
const config = {
|
|
2751
2790
|
client_id: clientId,
|
|
2752
2791
|
callback: (response) => this.handleCredential(response),
|
|
@@ -2759,7 +2798,6 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2759
2798
|
if (options.nonce) {
|
|
2760
2799
|
config.nonce = options.nonce;
|
|
2761
2800
|
}
|
|
2762
|
-
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
2763
2801
|
if (hint) {
|
|
2764
2802
|
config.login_hint = hint;
|
|
2765
2803
|
}
|
|
@@ -2767,6 +2805,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2767
2805
|
config.hd = options.hostedDomain;
|
|
2768
2806
|
}
|
|
2769
2807
|
this.requireIdApi().initialize(config);
|
|
2808
|
+
this.idConfigured = true;
|
|
2809
|
+
this.configuredIdHint = hint;
|
|
2770
2810
|
}
|
|
2771
2811
|
validateIdToken(idToken) {
|
|
2772
2812
|
let claims;
|
|
@@ -2844,6 +2884,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2844
2884
|
const resolve = this.pendingResolve;
|
|
2845
2885
|
this.pendingResolve = null;
|
|
2846
2886
|
this.pendingReject = null;
|
|
2887
|
+
this.pendingCredentialFlow = null;
|
|
2847
2888
|
resolve === null || resolve === void 0 ? void 0 : resolve(result);
|
|
2848
2889
|
}
|
|
2849
2890
|
rejectPending(error) {
|
|
@@ -2851,6 +2892,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2851
2892
|
const reject = this.pendingReject;
|
|
2852
2893
|
this.pendingResolve = null;
|
|
2853
2894
|
this.pendingReject = null;
|
|
2895
|
+
this.pendingCredentialFlow = null;
|
|
2854
2896
|
if (reject) {
|
|
2855
2897
|
reject(error);
|
|
2856
2898
|
}
|
|
@@ -2872,6 +2914,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
2872
2914
|
(_d = (_c = (_b = window.google) === null || _b === void 0 ? void 0 : _b.accounts) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.cancel();
|
|
2873
2915
|
}
|
|
2874
2916
|
this.lastCredential = null;
|
|
2917
|
+
this.hasRenderedButton = false;
|
|
2918
|
+
this.idConfigured = false;
|
|
2919
|
+
this.configuredIdHint = undefined;
|
|
2875
2920
|
super.dispose();
|
|
2876
2921
|
}
|
|
2877
2922
|
loadGsi() {
|
|
@@ -114,6 +114,8 @@ export interface GoogleAuthOptions {
|
|
|
114
114
|
* - `'auto'` (default): try One-Tap / FedCM first; if the browser does not display it (cooldown,
|
|
115
115
|
* FedCM opt-out, third-party-cookie settings) fall back to the OAuth2 popup.
|
|
116
116
|
* - `'one-tap'`: One-Tap only; a suppressed prompt rejects with `POPUP_BLOCKED`.
|
|
117
|
+
* - `'button'`: wait for the ID token from a button previously drawn with
|
|
118
|
+
* `GoogleAuthProviderWeb.renderButton()`; does not open One-Tap or the OAuth2 popup.
|
|
117
119
|
* - `'popup'`: the OAuth2 token popup only — deterministic, works from any click handler.
|
|
118
120
|
* One-Tap yields an `idToken`; the popup yields an `accessToken` (plus the Google profile). Both are
|
|
119
121
|
* accepted by Firebase: `GoogleAuthProvider.credential(idToken ?? null, accessToken)`.
|
|
@@ -132,7 +134,7 @@ export interface GoogleAuthOptions {
|
|
|
132
134
|
androidFlow?: GoogleAndroidFlow;
|
|
133
135
|
}
|
|
134
136
|
/** Web sign-in flow selector for the Google provider. See {@link GoogleAuthOptions.webFlow}. */
|
|
135
|
-
export type GoogleWebFlow = 'auto' | 'one-tap' | 'popup';
|
|
137
|
+
export type GoogleWebFlow = 'auto' | 'one-tap' | 'button' | 'popup';
|
|
136
138
|
/** Android sign-in flow selector for the Google provider. See {@link GoogleAuthOptions.androidFlow}. */
|
|
137
139
|
export type GoogleAndroidFlow = 'auto' | 'legacy' | 'credential-manager' | 'bottom-sheet' | 'button';
|
|
138
140
|
export interface AppleAuthOptions {
|
|
@@ -12,13 +12,11 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
12
12
|
let codeVerifier;
|
|
13
13
|
let codeChallenge;
|
|
14
14
|
if (config.pkceEnabled !== false) {
|
|
15
|
-
if (typeof crypto
|
|
16
|
-
|
|
17
|
-
codeChallenge = await this.generateCodeChallenge(codeVerifier);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
this.logger.warn(`PKCE skipped for ${this.provider}: Web Crypto 'subtle' is unavailable (insecure context). Serve over HTTPS to enable PKCE.`);
|
|
15
|
+
if (typeof crypto === 'undefined' || !crypto.subtle) {
|
|
16
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_SUPPORTED, 'OAuth sign-in requires Web Crypto for PKCE. Serve the app over HTTPS or localhost.', this.provider);
|
|
21
17
|
}
|
|
18
|
+
codeVerifier = this.generateCodeVerifier();
|
|
19
|
+
codeChallenge = await this.generateCodeChallenge(codeVerifier);
|
|
22
20
|
}
|
|
23
21
|
// Store state, nonce, and PKCE verifier for validation
|
|
24
22
|
await this.storage.set(`${this.provider}_oauth_state`, state);
|
|
@@ -81,12 +81,14 @@ declare global {
|
|
|
81
81
|
/**
|
|
82
82
|
* Web Google provider — the implementation the registry loads on **web / electron**.
|
|
83
83
|
*
|
|
84
|
-
*
|
|
84
|
+
* Three Google Identity Services flows are available, selected by {@link GoogleAuthOptions.webFlow}
|
|
85
85
|
* (default `'auto'`):
|
|
86
86
|
*
|
|
87
87
|
* 1. **One-Tap / FedCM id-token flow** (`google.accounts.id`): returns a Google **ID token** (JWT) as
|
|
88
88
|
* `result.credential.idToken` — the same field the native providers populate.
|
|
89
|
-
* 2. **
|
|
89
|
+
* 2. **Rendered-button ID-token flow** (`google.accounts.id.renderButton`): waits for a click on
|
|
90
|
+
* Google's button without opening One-Tap; returns `result.credential.idToken`.
|
|
91
|
+
* 3. **OAuth2 popup flow** (`google.accounts.oauth2.initTokenClient`): a deterministic popup that works
|
|
90
92
|
* from any click handler and returns an **access token** as `result.credential.accessToken`; the user
|
|
91
93
|
* profile is read from Google's `userinfo` endpoint. `'auto'` falls back to this whenever the browser
|
|
92
94
|
* does not display One-Tap (cooldown, FedCM opt-out, third-party-cookie settings).
|
|
@@ -96,8 +98,8 @@ declare global {
|
|
|
96
98
|
* const { idToken, accessToken } = result.credential;
|
|
97
99
|
* await signInWithCredential(getAuth(), GoogleAuthProvider.credential(idToken ?? null, accessToken));
|
|
98
100
|
*
|
|
99
|
-
*
|
|
100
|
-
* {@link renderButton}
|
|
101
|
+
* These flows need no client secret or backend. For Google's official button, call
|
|
102
|
+
* {@link renderButton}, then {@link signIn} with `webFlow: 'button'` before it is selected.
|
|
101
103
|
*/
|
|
102
104
|
export declare class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
103
105
|
private loadPromise;
|
|
@@ -111,14 +113,18 @@ export declare class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
111
113
|
private pendingTimer;
|
|
112
114
|
private requestRevision;
|
|
113
115
|
private pendingPopupReject;
|
|
116
|
+
private hasRenderedButton;
|
|
117
|
+
private pendingCredentialFlow;
|
|
118
|
+
private idConfigured;
|
|
119
|
+
private configuredIdHint?;
|
|
114
120
|
constructor(config?: unknown);
|
|
115
121
|
get name(): string;
|
|
116
122
|
initialize(): Promise<void>;
|
|
117
123
|
signIn(options?: SignInOptions): Promise<AuthResult>;
|
|
118
124
|
/**
|
|
119
125
|
* Renders Google's official "Sign in with Google" button into `parent`. Use this when you want
|
|
120
|
-
* Google's branded button rather than your own.
|
|
121
|
-
*
|
|
126
|
+
* Google's branded button rather than your own. Call {@link signIn} with `webFlow: 'button'`
|
|
127
|
+
* before the user clicks it to receive the ID-token credential.
|
|
122
128
|
*/
|
|
123
129
|
renderButton(parent: HTMLElement, options?: Record<string, unknown>): Promise<void>;
|
|
124
130
|
signOut(_options?: SignOutOptions): Promise<void>;
|
|
@@ -134,6 +140,7 @@ export declare class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
134
140
|
getIdToken(forceRefresh?: boolean): Promise<string>;
|
|
135
141
|
revokeAccess(token?: string): Promise<void>;
|
|
136
142
|
isSupported(): Promise<boolean>;
|
|
143
|
+
private signInWithButton;
|
|
137
144
|
private signInWithOneTap;
|
|
138
145
|
private handleCredential;
|
|
139
146
|
private signInWithPopup;
|
|
@@ -7,12 +7,14 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
7
7
|
/**
|
|
8
8
|
* Web Google provider — the implementation the registry loads on **web / electron**.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* Three Google Identity Services flows are available, selected by {@link GoogleAuthOptions.webFlow}
|
|
11
11
|
* (default `'auto'`):
|
|
12
12
|
*
|
|
13
13
|
* 1. **One-Tap / FedCM id-token flow** (`google.accounts.id`): returns a Google **ID token** (JWT) as
|
|
14
14
|
* `result.credential.idToken` — the same field the native providers populate.
|
|
15
|
-
* 2. **
|
|
15
|
+
* 2. **Rendered-button ID-token flow** (`google.accounts.id.renderButton`): waits for a click on
|
|
16
|
+
* Google's button without opening One-Tap; returns `result.credential.idToken`.
|
|
17
|
+
* 3. **OAuth2 popup flow** (`google.accounts.oauth2.initTokenClient`): a deterministic popup that works
|
|
16
18
|
* from any click handler and returns an **access token** as `result.credential.accessToken`; the user
|
|
17
19
|
* profile is read from Google's `userinfo` endpoint. `'auto'` falls back to this whenever the browser
|
|
18
20
|
* does not display One-Tap (cooldown, FedCM opt-out, third-party-cookie settings).
|
|
@@ -22,8 +24,8 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
22
24
|
* const { idToken, accessToken } = result.credential;
|
|
23
25
|
* await signInWithCredential(getAuth(), GoogleAuthProvider.credential(idToken ?? null, accessToken));
|
|
24
26
|
*
|
|
25
|
-
*
|
|
26
|
-
* {@link renderButton}
|
|
27
|
+
* These flows need no client secret or backend. For Google's official button, call
|
|
28
|
+
* {@link renderButton}, then {@link signIn} with `webFlow: 'button'` before it is selected.
|
|
27
29
|
*/
|
|
28
30
|
export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
29
31
|
constructor(config) {
|
|
@@ -38,6 +40,9 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
38
40
|
this.pendingTimer = null;
|
|
39
41
|
this.requestRevision = 0;
|
|
40
42
|
this.pendingPopupReject = null;
|
|
43
|
+
this.hasRenderedButton = false;
|
|
44
|
+
this.pendingCredentialFlow = null;
|
|
45
|
+
this.idConfigured = false;
|
|
41
46
|
}
|
|
42
47
|
get name() {
|
|
43
48
|
return AuthProvider.GOOGLE;
|
|
@@ -76,6 +81,9 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
76
81
|
if (flow === 'popup') {
|
|
77
82
|
return await this.signInWithPopup(loginHint);
|
|
78
83
|
}
|
|
84
|
+
if (flow === 'button') {
|
|
85
|
+
return await this.signInWithButton();
|
|
86
|
+
}
|
|
79
87
|
return await this.signInWithOneTap(flow === 'auto', loginHint);
|
|
80
88
|
}
|
|
81
89
|
finally {
|
|
@@ -84,8 +92,8 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
94
|
* Renders Google's official "Sign in with Google" button into `parent`. Use this when you want
|
|
87
|
-
* Google's branded button rather than your own.
|
|
88
|
-
*
|
|
95
|
+
* Google's branded button rather than your own. Call {@link signIn} with `webFlow: 'button'`
|
|
96
|
+
* before the user clicks it to receive the ID-token credential.
|
|
89
97
|
*/
|
|
90
98
|
async renderButton(parent, options = { theme: 'outline', size: 'large' }) {
|
|
91
99
|
if (!this.isInitialized) {
|
|
@@ -93,6 +101,7 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
93
101
|
}
|
|
94
102
|
this.configureIdClient();
|
|
95
103
|
this.requireIdApi().renderButton(parent, options);
|
|
104
|
+
this.hasRenderedButton = true;
|
|
96
105
|
}
|
|
97
106
|
async signOut(_options) {
|
|
98
107
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -130,7 +139,7 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
130
139
|
return cached.idToken;
|
|
131
140
|
}
|
|
132
141
|
if (cached && !cached.idToken && !forceRefresh) {
|
|
133
|
-
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap".', AuthProvider.GOOGLE);
|
|
142
|
+
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap" or "button".', AuthProvider.GOOGLE);
|
|
134
143
|
}
|
|
135
144
|
const result = await this.signIn({
|
|
136
145
|
provider: AuthProvider.GOOGLE,
|
|
@@ -184,27 +193,46 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
184
193
|
}
|
|
185
194
|
}
|
|
186
195
|
// --- One-Tap flow --------------------------------------------------------------------------------
|
|
196
|
+
signInWithButton() {
|
|
197
|
+
if (!this.hasRenderedButton) {
|
|
198
|
+
throw new AuthError(AuthErrorCode.MISSING_CONFIGURATION, 'webFlow "button" needs a rendered Google button. Call renderButton() first.', AuthProvider.GOOGLE);
|
|
199
|
+
}
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
this.pendingResolve = resolve;
|
|
202
|
+
this.pendingReject = reject;
|
|
203
|
+
this.pendingCredentialFlow = 'button';
|
|
204
|
+
this.pendingTimer = setTimeout(() => {
|
|
205
|
+
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'The Google button returned no credential within two minutes. Start another webFlow "button" sign-in, then select the button.', AuthProvider.GOOGLE));
|
|
206
|
+
}, 120000);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
187
209
|
signInWithOneTap(fallbackToPopup, loginHint) {
|
|
188
210
|
this.configureIdClient(loginHint);
|
|
189
211
|
return new Promise((resolve, reject) => {
|
|
190
212
|
this.pendingResolve = resolve;
|
|
191
213
|
this.pendingReject = (e) => reject(e);
|
|
214
|
+
this.pendingCredentialFlow = 'one-tap';
|
|
192
215
|
this.pendingTimer = setTimeout(() => {
|
|
193
216
|
var _a, _b, _c;
|
|
194
217
|
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'Google One-Tap did not return a credential. Retry from a click with webFlow "popup", or use the Google button.', AuthProvider.GOOGLE));
|
|
195
218
|
(_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.cancel();
|
|
196
219
|
}, 120000);
|
|
197
220
|
const fallback = (reason) => {
|
|
221
|
+
if (this.pendingResolve !== resolve)
|
|
222
|
+
return;
|
|
198
223
|
this.logger.info(`Google One-Tap not shown (${reason}); using the popup flow`);
|
|
199
224
|
// Drop the One-Tap resolvers so a late credential callback cannot double-resolve.
|
|
200
225
|
this.pendingResolve = null;
|
|
201
226
|
this.pendingReject = null;
|
|
227
|
+
this.pendingCredentialFlow = null;
|
|
202
228
|
this.clearPendingTimer();
|
|
203
229
|
this.signInWithPopup(loginHint).then(resolve, reject);
|
|
204
230
|
};
|
|
205
231
|
try {
|
|
206
232
|
this.requireIdApi().prompt((notification) => {
|
|
207
233
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
234
|
+
if (this.pendingResolve !== resolve)
|
|
235
|
+
return;
|
|
208
236
|
// These moment methods are deprecated under FedCM and may throw — guard every call.
|
|
209
237
|
try {
|
|
210
238
|
const notDisplayed = (_b = (_a = notification.isNotDisplayed) === null || _a === void 0 ? void 0 : _a.call(notification)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -235,6 +263,8 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
235
263
|
});
|
|
236
264
|
}
|
|
237
265
|
catch (error) {
|
|
266
|
+
if (this.pendingResolve !== resolve)
|
|
267
|
+
return;
|
|
238
268
|
if (fallbackToPopup) {
|
|
239
269
|
fallback(error instanceof Error ? error.message : 'prompt failed');
|
|
240
270
|
}
|
|
@@ -248,6 +278,12 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
248
278
|
// Ignore a late callback after cancellation, timeout, or popup fallback.
|
|
249
279
|
if (!this.pendingResolve)
|
|
250
280
|
return;
|
|
281
|
+
// Google labels button responses separately from One-Tap. A late One-Tap result must not
|
|
282
|
+
// satisfy a newer wait that explicitly required a click on the rendered button.
|
|
283
|
+
if (this.pendingCredentialFlow === 'button' &&
|
|
284
|
+
response.select_by !== 'btn' &&
|
|
285
|
+
response.select_by !== 'btn_confirm')
|
|
286
|
+
return;
|
|
251
287
|
if (response.error || !response.credential) {
|
|
252
288
|
this.rejectPending(new AuthError(AuthErrorCode.SIGN_IN_FAILED, response.error_description ||
|
|
253
289
|
response.error ||
|
|
@@ -407,6 +443,9 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
407
443
|
const options = this.options;
|
|
408
444
|
const clientId = this.requireClientId();
|
|
409
445
|
this.currentNonce = options.nonce;
|
|
446
|
+
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
447
|
+
if (this.idConfigured && this.configuredIdHint === hint)
|
|
448
|
+
return;
|
|
410
449
|
const config = {
|
|
411
450
|
client_id: clientId,
|
|
412
451
|
callback: (response) => this.handleCredential(response),
|
|
@@ -419,7 +458,6 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
419
458
|
if (options.nonce) {
|
|
420
459
|
config.nonce = options.nonce;
|
|
421
460
|
}
|
|
422
|
-
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
423
461
|
if (hint) {
|
|
424
462
|
config.login_hint = hint;
|
|
425
463
|
}
|
|
@@ -427,6 +465,8 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
427
465
|
config.hd = options.hostedDomain;
|
|
428
466
|
}
|
|
429
467
|
this.requireIdApi().initialize(config);
|
|
468
|
+
this.idConfigured = true;
|
|
469
|
+
this.configuredIdHint = hint;
|
|
430
470
|
}
|
|
431
471
|
validateIdToken(idToken) {
|
|
432
472
|
let claims;
|
|
@@ -504,6 +544,7 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
504
544
|
const resolve = this.pendingResolve;
|
|
505
545
|
this.pendingResolve = null;
|
|
506
546
|
this.pendingReject = null;
|
|
547
|
+
this.pendingCredentialFlow = null;
|
|
507
548
|
resolve === null || resolve === void 0 ? void 0 : resolve(result);
|
|
508
549
|
}
|
|
509
550
|
rejectPending(error) {
|
|
@@ -511,6 +552,7 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
511
552
|
const reject = this.pendingReject;
|
|
512
553
|
this.pendingResolve = null;
|
|
513
554
|
this.pendingReject = null;
|
|
555
|
+
this.pendingCredentialFlow = null;
|
|
514
556
|
if (reject) {
|
|
515
557
|
reject(error);
|
|
516
558
|
}
|
|
@@ -532,6 +574,9 @@ export class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
532
574
|
(_d = (_c = (_b = window.google) === null || _b === void 0 ? void 0 : _b.accounts) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.cancel();
|
|
533
575
|
}
|
|
534
576
|
this.lastCredential = null;
|
|
577
|
+
this.hasRenderedButton = false;
|
|
578
|
+
this.idConfigured = false;
|
|
579
|
+
this.configuredIdHint = undefined;
|
|
535
580
|
super.dispose();
|
|
536
581
|
}
|
|
537
582
|
loadGsi() {
|
package/dist/plugin.js
CHANGED
|
@@ -2406,12 +2406,14 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2406
2406
|
/**
|
|
2407
2407
|
* Web Google provider — the implementation the registry loads on **web / electron**.
|
|
2408
2408
|
*
|
|
2409
|
-
*
|
|
2409
|
+
* Three Google Identity Services flows are available, selected by {@link GoogleAuthOptions.webFlow}
|
|
2410
2410
|
* (default `'auto'`):
|
|
2411
2411
|
*
|
|
2412
2412
|
* 1. **One-Tap / FedCM id-token flow** (`google.accounts.id`): returns a Google **ID token** (JWT) as
|
|
2413
2413
|
* `result.credential.idToken` — the same field the native providers populate.
|
|
2414
|
-
* 2. **
|
|
2414
|
+
* 2. **Rendered-button ID-token flow** (`google.accounts.id.renderButton`): waits for a click on
|
|
2415
|
+
* Google's button without opening One-Tap; returns `result.credential.idToken`.
|
|
2416
|
+
* 3. **OAuth2 popup flow** (`google.accounts.oauth2.initTokenClient`): a deterministic popup that works
|
|
2415
2417
|
* from any click handler and returns an **access token** as `result.credential.accessToken`; the user
|
|
2416
2418
|
* profile is read from Google's `userinfo` endpoint. `'auto'` falls back to this whenever the browser
|
|
2417
2419
|
* does not display One-Tap (cooldown, FedCM opt-out, third-party-cookie settings).
|
|
@@ -2421,8 +2423,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2421
2423
|
* const { idToken, accessToken } = result.credential;
|
|
2422
2424
|
* await signInWithCredential(getAuth(), GoogleAuthProvider.credential(idToken ?? null, accessToken));
|
|
2423
2425
|
*
|
|
2424
|
-
*
|
|
2425
|
-
* {@link renderButton}
|
|
2426
|
+
* These flows need no client secret or backend. For Google's official button, call
|
|
2427
|
+
* {@link renderButton}, then {@link signIn} with `webFlow: 'button'` before it is selected.
|
|
2426
2428
|
*/
|
|
2427
2429
|
class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
2428
2430
|
constructor(config) {
|
|
@@ -2437,6 +2439,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2437
2439
|
this.pendingTimer = null;
|
|
2438
2440
|
this.requestRevision = 0;
|
|
2439
2441
|
this.pendingPopupReject = null;
|
|
2442
|
+
this.hasRenderedButton = false;
|
|
2443
|
+
this.pendingCredentialFlow = null;
|
|
2444
|
+
this.idConfigured = false;
|
|
2440
2445
|
}
|
|
2441
2446
|
get name() {
|
|
2442
2447
|
return exports.AuthProvider.GOOGLE;
|
|
@@ -2475,6 +2480,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2475
2480
|
if (flow === 'popup') {
|
|
2476
2481
|
return await this.signInWithPopup(loginHint);
|
|
2477
2482
|
}
|
|
2483
|
+
if (flow === 'button') {
|
|
2484
|
+
return await this.signInWithButton();
|
|
2485
|
+
}
|
|
2478
2486
|
return await this.signInWithOneTap(flow === 'auto', loginHint);
|
|
2479
2487
|
}
|
|
2480
2488
|
finally {
|
|
@@ -2483,8 +2491,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2483
2491
|
}
|
|
2484
2492
|
/**
|
|
2485
2493
|
* Renders Google's official "Sign in with Google" button into `parent`. Use this when you want
|
|
2486
|
-
* Google's branded button rather than your own.
|
|
2487
|
-
*
|
|
2494
|
+
* Google's branded button rather than your own. Call {@link signIn} with `webFlow: 'button'`
|
|
2495
|
+
* before the user clicks it to receive the ID-token credential.
|
|
2488
2496
|
*/
|
|
2489
2497
|
async renderButton(parent, options = { theme: 'outline', size: 'large' }) {
|
|
2490
2498
|
if (!this.isInitialized) {
|
|
@@ -2492,6 +2500,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2492
2500
|
}
|
|
2493
2501
|
this.configureIdClient();
|
|
2494
2502
|
this.requireIdApi().renderButton(parent, options);
|
|
2503
|
+
this.hasRenderedButton = true;
|
|
2495
2504
|
}
|
|
2496
2505
|
async signOut(_options) {
|
|
2497
2506
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -2529,7 +2538,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2529
2538
|
return cached.idToken;
|
|
2530
2539
|
}
|
|
2531
2540
|
if (cached && !cached.idToken && !forceRefresh) {
|
|
2532
|
-
throw new AuthError(exports.AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap".', exports.AuthProvider.GOOGLE);
|
|
2541
|
+
throw new AuthError(exports.AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap" or "button".', exports.AuthProvider.GOOGLE);
|
|
2533
2542
|
}
|
|
2534
2543
|
const result = await this.signIn({
|
|
2535
2544
|
provider: exports.AuthProvider.GOOGLE,
|
|
@@ -2583,27 +2592,46 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2583
2592
|
}
|
|
2584
2593
|
}
|
|
2585
2594
|
// --- One-Tap flow --------------------------------------------------------------------------------
|
|
2595
|
+
signInWithButton() {
|
|
2596
|
+
if (!this.hasRenderedButton) {
|
|
2597
|
+
throw new AuthError(exports.AuthErrorCode.MISSING_CONFIGURATION, 'webFlow "button" needs a rendered Google button. Call renderButton() first.', exports.AuthProvider.GOOGLE);
|
|
2598
|
+
}
|
|
2599
|
+
return new Promise((resolve, reject) => {
|
|
2600
|
+
this.pendingResolve = resolve;
|
|
2601
|
+
this.pendingReject = reject;
|
|
2602
|
+
this.pendingCredentialFlow = 'button';
|
|
2603
|
+
this.pendingTimer = setTimeout(() => {
|
|
2604
|
+
this.rejectPending(new AuthError(exports.AuthErrorCode.POPUP_BLOCKED, 'The Google button returned no credential within two minutes. Start another webFlow "button" sign-in, then select the button.', exports.AuthProvider.GOOGLE));
|
|
2605
|
+
}, 120000);
|
|
2606
|
+
});
|
|
2607
|
+
}
|
|
2586
2608
|
signInWithOneTap(fallbackToPopup, loginHint) {
|
|
2587
2609
|
this.configureIdClient(loginHint);
|
|
2588
2610
|
return new Promise((resolve, reject) => {
|
|
2589
2611
|
this.pendingResolve = resolve;
|
|
2590
2612
|
this.pendingReject = (e) => reject(e);
|
|
2613
|
+
this.pendingCredentialFlow = 'one-tap';
|
|
2591
2614
|
this.pendingTimer = setTimeout(() => {
|
|
2592
2615
|
var _a, _b, _c;
|
|
2593
2616
|
this.rejectPending(new AuthError(exports.AuthErrorCode.POPUP_BLOCKED, 'Google One-Tap did not return a credential. Retry from a click with webFlow "popup", or use the Google button.', exports.AuthProvider.GOOGLE));
|
|
2594
2617
|
(_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.cancel();
|
|
2595
2618
|
}, 120000);
|
|
2596
2619
|
const fallback = (reason) => {
|
|
2620
|
+
if (this.pendingResolve !== resolve)
|
|
2621
|
+
return;
|
|
2597
2622
|
this.logger.info(`Google One-Tap not shown (${reason}); using the popup flow`);
|
|
2598
2623
|
// Drop the One-Tap resolvers so a late credential callback cannot double-resolve.
|
|
2599
2624
|
this.pendingResolve = null;
|
|
2600
2625
|
this.pendingReject = null;
|
|
2626
|
+
this.pendingCredentialFlow = null;
|
|
2601
2627
|
this.clearPendingTimer();
|
|
2602
2628
|
this.signInWithPopup(loginHint).then(resolve, reject);
|
|
2603
2629
|
};
|
|
2604
2630
|
try {
|
|
2605
2631
|
this.requireIdApi().prompt((notification) => {
|
|
2606
2632
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2633
|
+
if (this.pendingResolve !== resolve)
|
|
2634
|
+
return;
|
|
2607
2635
|
// These moment methods are deprecated under FedCM and may throw — guard every call.
|
|
2608
2636
|
try {
|
|
2609
2637
|
const notDisplayed = (_b = (_a = notification.isNotDisplayed) === null || _a === void 0 ? void 0 : _a.call(notification)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -2634,6 +2662,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2634
2662
|
});
|
|
2635
2663
|
}
|
|
2636
2664
|
catch (error) {
|
|
2665
|
+
if (this.pendingResolve !== resolve)
|
|
2666
|
+
return;
|
|
2637
2667
|
if (fallbackToPopup) {
|
|
2638
2668
|
fallback(error instanceof Error ? error.message : 'prompt failed');
|
|
2639
2669
|
}
|
|
@@ -2647,6 +2677,12 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2647
2677
|
// Ignore a late callback after cancellation, timeout, or popup fallback.
|
|
2648
2678
|
if (!this.pendingResolve)
|
|
2649
2679
|
return;
|
|
2680
|
+
// Google labels button responses separately from One-Tap. A late One-Tap result must not
|
|
2681
|
+
// satisfy a newer wait that explicitly required a click on the rendered button.
|
|
2682
|
+
if (this.pendingCredentialFlow === 'button' &&
|
|
2683
|
+
response.select_by !== 'btn' &&
|
|
2684
|
+
response.select_by !== 'btn_confirm')
|
|
2685
|
+
return;
|
|
2650
2686
|
if (response.error || !response.credential) {
|
|
2651
2687
|
this.rejectPending(new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, response.error_description ||
|
|
2652
2688
|
response.error ||
|
|
@@ -2806,6 +2842,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2806
2842
|
const options = this.options;
|
|
2807
2843
|
const clientId = this.requireClientId();
|
|
2808
2844
|
this.currentNonce = options.nonce;
|
|
2845
|
+
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
2846
|
+
if (this.idConfigured && this.configuredIdHint === hint)
|
|
2847
|
+
return;
|
|
2809
2848
|
const config = {
|
|
2810
2849
|
client_id: clientId,
|
|
2811
2850
|
callback: (response) => this.handleCredential(response),
|
|
@@ -2818,7 +2857,6 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2818
2857
|
if (options.nonce) {
|
|
2819
2858
|
config.nonce = options.nonce;
|
|
2820
2859
|
}
|
|
2821
|
-
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
2822
2860
|
if (hint) {
|
|
2823
2861
|
config.login_hint = hint;
|
|
2824
2862
|
}
|
|
@@ -2826,6 +2864,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2826
2864
|
config.hd = options.hostedDomain;
|
|
2827
2865
|
}
|
|
2828
2866
|
this.requireIdApi().initialize(config);
|
|
2867
|
+
this.idConfigured = true;
|
|
2868
|
+
this.configuredIdHint = hint;
|
|
2829
2869
|
}
|
|
2830
2870
|
validateIdToken(idToken) {
|
|
2831
2871
|
let claims;
|
|
@@ -2903,6 +2943,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2903
2943
|
const resolve = this.pendingResolve;
|
|
2904
2944
|
this.pendingResolve = null;
|
|
2905
2945
|
this.pendingReject = null;
|
|
2946
|
+
this.pendingCredentialFlow = null;
|
|
2906
2947
|
resolve === null || resolve === void 0 ? void 0 : resolve(result);
|
|
2907
2948
|
}
|
|
2908
2949
|
rejectPending(error) {
|
|
@@ -2910,6 +2951,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2910
2951
|
const reject = this.pendingReject;
|
|
2911
2952
|
this.pendingResolve = null;
|
|
2912
2953
|
this.pendingReject = null;
|
|
2954
|
+
this.pendingCredentialFlow = null;
|
|
2913
2955
|
if (reject) {
|
|
2914
2956
|
reject(error);
|
|
2915
2957
|
}
|
|
@@ -2931,6 +2973,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
2931
2973
|
(_d = (_c = (_b = window.google) === null || _b === void 0 ? void 0 : _b.accounts) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.cancel();
|
|
2932
2974
|
}
|
|
2933
2975
|
this.lastCredential = null;
|
|
2976
|
+
this.hasRenderedButton = false;
|
|
2977
|
+
this.idConfigured = false;
|
|
2978
|
+
this.configuredIdHint = undefined;
|
|
2934
2979
|
super.dispose();
|
|
2935
2980
|
}
|
|
2936
2981
|
loadGsi() {
|
|
@@ -719,12 +719,14 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
719
719
|
/**
|
|
720
720
|
* Web Google provider — the implementation the registry loads on **web / electron**.
|
|
721
721
|
*
|
|
722
|
-
*
|
|
722
|
+
* Three Google Identity Services flows are available, selected by {@link GoogleAuthOptions.webFlow}
|
|
723
723
|
* (default `'auto'`):
|
|
724
724
|
*
|
|
725
725
|
* 1. **One-Tap / FedCM id-token flow** (`google.accounts.id`): returns a Google **ID token** (JWT) as
|
|
726
726
|
* `result.credential.idToken` — the same field the native providers populate.
|
|
727
|
-
* 2. **
|
|
727
|
+
* 2. **Rendered-button ID-token flow** (`google.accounts.id.renderButton`): waits for a click on
|
|
728
|
+
* Google's button without opening One-Tap; returns `result.credential.idToken`.
|
|
729
|
+
* 3. **OAuth2 popup flow** (`google.accounts.oauth2.initTokenClient`): a deterministic popup that works
|
|
728
730
|
* from any click handler and returns an **access token** as `result.credential.accessToken`; the user
|
|
729
731
|
* profile is read from Google's `userinfo` endpoint. `'auto'` falls back to this whenever the browser
|
|
730
732
|
* does not display One-Tap (cooldown, FedCM opt-out, third-party-cookie settings).
|
|
@@ -734,8 +736,8 @@ const DEFAULT_SCOPES = ['openid', 'email', 'profile'];
|
|
|
734
736
|
* const { idToken, accessToken } = result.credential;
|
|
735
737
|
* await signInWithCredential(getAuth(), GoogleAuthProvider.credential(idToken ?? null, accessToken));
|
|
736
738
|
*
|
|
737
|
-
*
|
|
738
|
-
* {@link renderButton}
|
|
739
|
+
* These flows need no client secret or backend. For Google's official button, call
|
|
740
|
+
* {@link renderButton}, then {@link signIn} with `webFlow: 'button'` before it is selected.
|
|
739
741
|
*/
|
|
740
742
|
class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
741
743
|
constructor(config) {
|
|
@@ -750,6 +752,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
750
752
|
this.pendingTimer = null;
|
|
751
753
|
this.requestRevision = 0;
|
|
752
754
|
this.pendingPopupReject = null;
|
|
755
|
+
this.hasRenderedButton = false;
|
|
756
|
+
this.pendingCredentialFlow = null;
|
|
757
|
+
this.idConfigured = false;
|
|
753
758
|
}
|
|
754
759
|
get name() {
|
|
755
760
|
return AuthProvider.GOOGLE;
|
|
@@ -788,6 +793,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
788
793
|
if (flow === 'popup') {
|
|
789
794
|
return await this.signInWithPopup(loginHint);
|
|
790
795
|
}
|
|
796
|
+
if (flow === 'button') {
|
|
797
|
+
return await this.signInWithButton();
|
|
798
|
+
}
|
|
791
799
|
return await this.signInWithOneTap(flow === 'auto', loginHint);
|
|
792
800
|
}
|
|
793
801
|
finally {
|
|
@@ -796,8 +804,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
796
804
|
}
|
|
797
805
|
/**
|
|
798
806
|
* Renders Google's official "Sign in with Google" button into `parent`. Use this when you want
|
|
799
|
-
* Google's branded button rather than your own.
|
|
800
|
-
*
|
|
807
|
+
* Google's branded button rather than your own. Call {@link signIn} with `webFlow: 'button'`
|
|
808
|
+
* before the user clicks it to receive the ID-token credential.
|
|
801
809
|
*/
|
|
802
810
|
async renderButton(parent, options = { theme: 'outline', size: 'large' }) {
|
|
803
811
|
if (!this.isInitialized) {
|
|
@@ -805,6 +813,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
805
813
|
}
|
|
806
814
|
this.configureIdClient();
|
|
807
815
|
this.requireIdApi().renderButton(parent, options);
|
|
816
|
+
this.hasRenderedButton = true;
|
|
808
817
|
}
|
|
809
818
|
async signOut(_options) {
|
|
810
819
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -842,7 +851,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
842
851
|
return cached.idToken;
|
|
843
852
|
}
|
|
844
853
|
if (cached && !cached.idToken && !forceRefresh) {
|
|
845
|
-
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap".', AuthProvider.GOOGLE);
|
|
854
|
+
throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'The popup flow issues an access token, not an ID token. Use result.credential.accessToken, or sign in with webFlow "one-tap" or "button".', AuthProvider.GOOGLE);
|
|
846
855
|
}
|
|
847
856
|
const result = await this.signIn({
|
|
848
857
|
provider: AuthProvider.GOOGLE,
|
|
@@ -896,27 +905,46 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
896
905
|
}
|
|
897
906
|
}
|
|
898
907
|
// --- One-Tap flow --------------------------------------------------------------------------------
|
|
908
|
+
signInWithButton() {
|
|
909
|
+
if (!this.hasRenderedButton) {
|
|
910
|
+
throw new AuthError(AuthErrorCode.MISSING_CONFIGURATION, 'webFlow "button" needs a rendered Google button. Call renderButton() first.', AuthProvider.GOOGLE);
|
|
911
|
+
}
|
|
912
|
+
return new Promise((resolve, reject) => {
|
|
913
|
+
this.pendingResolve = resolve;
|
|
914
|
+
this.pendingReject = reject;
|
|
915
|
+
this.pendingCredentialFlow = 'button';
|
|
916
|
+
this.pendingTimer = setTimeout(() => {
|
|
917
|
+
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'The Google button returned no credential within two minutes. Start another webFlow "button" sign-in, then select the button.', AuthProvider.GOOGLE));
|
|
918
|
+
}, 120000);
|
|
919
|
+
});
|
|
920
|
+
}
|
|
899
921
|
signInWithOneTap(fallbackToPopup, loginHint) {
|
|
900
922
|
this.configureIdClient(loginHint);
|
|
901
923
|
return new Promise((resolve, reject) => {
|
|
902
924
|
this.pendingResolve = resolve;
|
|
903
925
|
this.pendingReject = (e) => reject(e);
|
|
926
|
+
this.pendingCredentialFlow = 'one-tap';
|
|
904
927
|
this.pendingTimer = setTimeout(() => {
|
|
905
928
|
var _a, _b, _c;
|
|
906
929
|
this.rejectPending(new AuthError(AuthErrorCode.POPUP_BLOCKED, 'Google One-Tap did not return a credential. Retry from a click with webFlow "popup", or use the Google button.', AuthProvider.GOOGLE));
|
|
907
930
|
(_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.cancel();
|
|
908
931
|
}, 120000);
|
|
909
932
|
const fallback = (reason) => {
|
|
933
|
+
if (this.pendingResolve !== resolve)
|
|
934
|
+
return;
|
|
910
935
|
this.logger.info(`Google One-Tap not shown (${reason}); using the popup flow`);
|
|
911
936
|
// Drop the One-Tap resolvers so a late credential callback cannot double-resolve.
|
|
912
937
|
this.pendingResolve = null;
|
|
913
938
|
this.pendingReject = null;
|
|
939
|
+
this.pendingCredentialFlow = null;
|
|
914
940
|
this.clearPendingTimer();
|
|
915
941
|
this.signInWithPopup(loginHint).then(resolve, reject);
|
|
916
942
|
};
|
|
917
943
|
try {
|
|
918
944
|
this.requireIdApi().prompt((notification) => {
|
|
919
945
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
946
|
+
if (this.pendingResolve !== resolve)
|
|
947
|
+
return;
|
|
920
948
|
// These moment methods are deprecated under FedCM and may throw — guard every call.
|
|
921
949
|
try {
|
|
922
950
|
const notDisplayed = (_b = (_a = notification.isNotDisplayed) === null || _a === void 0 ? void 0 : _a.call(notification)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -947,6 +975,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
947
975
|
});
|
|
948
976
|
}
|
|
949
977
|
catch (error) {
|
|
978
|
+
if (this.pendingResolve !== resolve)
|
|
979
|
+
return;
|
|
950
980
|
if (fallbackToPopup) {
|
|
951
981
|
fallback(error instanceof Error ? error.message : 'prompt failed');
|
|
952
982
|
}
|
|
@@ -960,6 +990,12 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
960
990
|
// Ignore a late callback after cancellation, timeout, or popup fallback.
|
|
961
991
|
if (!this.pendingResolve)
|
|
962
992
|
return;
|
|
993
|
+
// Google labels button responses separately from One-Tap. A late One-Tap result must not
|
|
994
|
+
// satisfy a newer wait that explicitly required a click on the rendered button.
|
|
995
|
+
if (this.pendingCredentialFlow === 'button' &&
|
|
996
|
+
response.select_by !== 'btn' &&
|
|
997
|
+
response.select_by !== 'btn_confirm')
|
|
998
|
+
return;
|
|
963
999
|
if (response.error || !response.credential) {
|
|
964
1000
|
this.rejectPending(new AuthError(AuthErrorCode.SIGN_IN_FAILED, response.error_description ||
|
|
965
1001
|
response.error ||
|
|
@@ -1119,6 +1155,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1119
1155
|
const options = this.options;
|
|
1120
1156
|
const clientId = this.requireClientId();
|
|
1121
1157
|
this.currentNonce = options.nonce;
|
|
1158
|
+
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
1159
|
+
if (this.idConfigured && this.configuredIdHint === hint)
|
|
1160
|
+
return;
|
|
1122
1161
|
const config = {
|
|
1123
1162
|
client_id: clientId,
|
|
1124
1163
|
callback: (response) => this.handleCredential(response),
|
|
@@ -1131,7 +1170,6 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1131
1170
|
if (options.nonce) {
|
|
1132
1171
|
config.nonce = options.nonce;
|
|
1133
1172
|
}
|
|
1134
|
-
const hint = loginHint !== null && loginHint !== void 0 ? loginHint : options.loginHint;
|
|
1135
1173
|
if (hint) {
|
|
1136
1174
|
config.login_hint = hint;
|
|
1137
1175
|
}
|
|
@@ -1139,6 +1177,8 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1139
1177
|
config.hd = options.hostedDomain;
|
|
1140
1178
|
}
|
|
1141
1179
|
this.requireIdApi().initialize(config);
|
|
1180
|
+
this.idConfigured = true;
|
|
1181
|
+
this.configuredIdHint = hint;
|
|
1142
1182
|
}
|
|
1143
1183
|
validateIdToken(idToken) {
|
|
1144
1184
|
let claims;
|
|
@@ -1216,6 +1256,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1216
1256
|
const resolve = this.pendingResolve;
|
|
1217
1257
|
this.pendingResolve = null;
|
|
1218
1258
|
this.pendingReject = null;
|
|
1259
|
+
this.pendingCredentialFlow = null;
|
|
1219
1260
|
resolve === null || resolve === void 0 ? void 0 : resolve(result);
|
|
1220
1261
|
}
|
|
1221
1262
|
rejectPending(error) {
|
|
@@ -1223,6 +1264,7 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1223
1264
|
const reject = this.pendingReject;
|
|
1224
1265
|
this.pendingResolve = null;
|
|
1225
1266
|
this.pendingReject = null;
|
|
1267
|
+
this.pendingCredentialFlow = null;
|
|
1226
1268
|
if (reject) {
|
|
1227
1269
|
reject(error);
|
|
1228
1270
|
}
|
|
@@ -1244,6 +1286,9 @@ class GoogleAuthProviderWeb extends BaseAuthProvider {
|
|
|
1244
1286
|
(_d = (_c = (_b = window.google) === null || _b === void 0 ? void 0 : _b.accounts) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.cancel();
|
|
1245
1287
|
}
|
|
1246
1288
|
this.lastCredential = null;
|
|
1289
|
+
this.hasRenderedButton = false;
|
|
1290
|
+
this.idConfigured = false;
|
|
1291
|
+
this.configuredIdHint = undefined;
|
|
1247
1292
|
super.dispose();
|
|
1248
1293
|
}
|
|
1249
1294
|
loadGsi() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-auth-manager",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "Capacitor + web authentication. Firebase-agnostic native & web Google sign-in (idToken/accessToken) for React, Vue, Angular and vanilla JS
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "Capacitor + web authentication. Firebase-agnostic native & web Google sign-in (idToken/accessToken) for React, Vue, Angular and vanilla JS \u2014 a drop-in alternative to @codetrix-studio/capacitor-google-auth. More providers shipping one at a time.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -91,7 +91,8 @@
|
|
|
91
91
|
"lint": "eslint . --max-warnings 0",
|
|
92
92
|
"prettier": "prettier --write .",
|
|
93
93
|
"prepack": "yarn build",
|
|
94
|
-
"prepublishOnly": "yarn typecheck && yarn lint && yarn build && yarn test && yarn smoke:tarball",
|
|
94
|
+
"prepublishOnly": "yarn check:release-docs && yarn typecheck && yarn lint && yarn build && yarn test && yarn smoke:tarball",
|
|
95
|
+
"check:release-docs": "node scripts/check-release-docs.js",
|
|
95
96
|
"swiftlint": "cd ios && swiftlint lint --fix --format --path Plugin --verbose",
|
|
96
97
|
"configure": "node scripts/configure.js",
|
|
97
98
|
"smoke:tarball": "node --test test/tarball-smoke.test.js",
|
|
@@ -107,32 +108,32 @@
|
|
|
107
108
|
"capacitor-auth-configure": "./scripts/configure.js"
|
|
108
109
|
},
|
|
109
110
|
"dependencies": {
|
|
110
|
-
"tslib": "^2.
|
|
111
|
+
"tslib": "^2.9.1"
|
|
111
112
|
},
|
|
112
113
|
"devDependencies": {
|
|
113
|
-
"@angular/common": "^22.2.
|
|
114
|
-
"@angular/core": "^22.2.
|
|
115
|
-
"@angular/platform-browser": "^22.2.
|
|
116
|
-
"@angular/router": "^22.2.
|
|
117
|
-
"@capacitor/android": "^8.
|
|
118
|
-
"@capacitor/cli": "^8.
|
|
119
|
-
"@capacitor/core": "^8.
|
|
120
|
-
"@capacitor/ios": "^8.
|
|
114
|
+
"@angular/common": "^22.2.4",
|
|
115
|
+
"@angular/core": "^22.2.4",
|
|
116
|
+
"@angular/platform-browser": "^22.2.4",
|
|
117
|
+
"@angular/router": "^22.2.4",
|
|
118
|
+
"@capacitor/android": "^8.6.0",
|
|
119
|
+
"@capacitor/cli": "^8.6.0",
|
|
120
|
+
"@capacitor/core": "^8.6.0",
|
|
121
|
+
"@capacitor/ios": "^8.6.0",
|
|
121
122
|
"@capacitor/preferences": "^8.0.1",
|
|
122
123
|
"@rollup/plugin-json": "^6.1.0",
|
|
123
124
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
124
|
-
"@trapezedev/configure": "^7.1.
|
|
125
|
-
"@types/node": "^26.6.
|
|
125
|
+
"@trapezedev/configure": "^7.1.11",
|
|
126
|
+
"@types/node": "^26.6.6",
|
|
126
127
|
"@types/react": "^19.3.0",
|
|
127
|
-
"eslint": "^10.
|
|
128
|
-
"prettier": "^3.9.
|
|
129
|
-
"react": "^19.3.
|
|
130
|
-
"rimraf": "^6.1.
|
|
131
|
-
"rollup": "^4.
|
|
128
|
+
"eslint": "^10.14.0",
|
|
129
|
+
"prettier": "^3.9.10",
|
|
130
|
+
"react": "^19.3.1",
|
|
131
|
+
"rimraf": "^6.1.4",
|
|
132
|
+
"rollup": "^4.67.5",
|
|
132
133
|
"rxjs": "^7.8.2",
|
|
133
134
|
"typescript": "~6.0.3",
|
|
134
|
-
"typescript-eslint": "^8.
|
|
135
|
-
"vue": "^3.5.
|
|
135
|
+
"typescript-eslint": "^8.72.1",
|
|
136
|
+
"vue": "^3.5.44"
|
|
136
137
|
},
|
|
137
138
|
"peerDependencies": {
|
|
138
139
|
"@angular/common": "^22.0.0",
|
package/scripts/configure.js
CHANGED
|
File without changes
|