capacitor-auth-manager 2.4.1 → 2.4.3
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/CHANGELOG.md +64 -1
- package/CapacitorAuthManager.podspec +9 -17
- package/README.md +505 -0
- package/android/build.gradle +6 -16
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +1 -1
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +2 -5
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +10 -110
- package/ios/Plugin/CapacitorAuthManager.swift +6 -15
- package/ios/Plugin/Plugin.swift +4 -2
- package/package.json +12 -24
- package/Readme.md +0 -203
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/FacebookAuthProvider.java +0 -389
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/MicrosoftAuthProvider.java +0 -455
- package/ios/Plugin/AppleAuthProvider.swift +0 -288
- package/ios/Plugin/FacebookAuthProvider.swift +0 -297
- package/ios/Plugin/GitHubAuthProvider.swift +0 -54
- package/ios/Plugin/LinkedInAuthProvider.swift +0 -63
- package/ios/Plugin/MicrosoftAuthProvider.swift +0 -315
- package/ios/Plugin/OAuthWebProvider.swift +0 -415
- package/ios/Plugin/SlackAuthProvider.swift +0 -108
|
@@ -22,7 +22,6 @@ import androidx.credentials.exceptions.NoCredentialException;
|
|
|
22
22
|
import com.getcapacitor.JSObject;
|
|
23
23
|
import com.google.android.libraries.identity.googleid.GetGoogleIdOption;
|
|
24
24
|
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;
|
|
25
|
-
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException;
|
|
26
25
|
|
|
27
26
|
import org.json.JSONArray;
|
|
28
27
|
import org.json.JSONObject;
|
|
@@ -355,11 +354,9 @@ public class GoogleAuthProvider implements BaseAuthProvider {
|
|
|
355
354
|
callback.onResult(CapacitorAuthManager.AuthResult.error(new IllegalStateException(
|
|
356
355
|
"Unexpected credential type returned from Google sign-in: " + type)));
|
|
357
356
|
}
|
|
358
|
-
} catch (GoogleIdTokenParsingException e) {
|
|
359
|
-
logger.error("Failed to parse Google ID token credential", e);
|
|
360
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(new Exception(
|
|
361
|
-
"Failed to parse Google ID token credential: " + e.getMessage())));
|
|
362
357
|
} catch (Exception e) {
|
|
358
|
+
// Covers a malformed credential / ID-token parse failure. (googleid 1.1.1's
|
|
359
|
+
// GoogleIdTokenCredential.createFrom does not declare a checked exception.)
|
|
363
360
|
logger.error("Unexpected error handling Google credential", e);
|
|
364
361
|
callback.onResult(CapacitorAuthManager.AuthResult.error(e));
|
|
365
362
|
}
|
|
@@ -11,6 +11,13 @@ import org.json.JSONException;
|
|
|
11
11
|
import java.util.ArrayList;
|
|
12
12
|
import java.util.List;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Creates native auth providers. As of 2.4.x the plugin is Google-first: only the Google provider is
|
|
16
|
+
* built. The Facebook / Microsoft native implementations were moved to
|
|
17
|
+
* {@code android/disabled-native-providers/} (out of the compiled source set + not shipped) so the
|
|
18
|
+
* plugin no longer drags the Facebook SDK / MSAL into every consumer app. Re-add a provider's case here
|
|
19
|
+
* (and its dependency in build.gradle, and move its file back) when it is re-enabled.
|
|
20
|
+
*/
|
|
14
21
|
public class ProviderFactory {
|
|
15
22
|
private static final String TAG = "ProviderFactory";
|
|
16
23
|
|
|
@@ -31,40 +38,10 @@ public class ProviderFactory {
|
|
|
31
38
|
case "google.com":
|
|
32
39
|
return createGoogleProvider(context, activity, storage, logger, config);
|
|
33
40
|
|
|
34
|
-
case "facebook":
|
|
35
|
-
case "facebook.com":
|
|
36
|
-
return createFacebookProvider(context, activity, storage, logger, config);
|
|
37
|
-
|
|
38
|
-
case "microsoft":
|
|
39
|
-
case "microsoft.com":
|
|
40
|
-
return createMicrosoftProvider(context, activity, storage, logger, config);
|
|
41
|
-
|
|
42
|
-
case "apple":
|
|
43
|
-
case "apple.com":
|
|
44
|
-
// Apple Sign-In on Android uses web-based flow
|
|
45
|
-
logger.warn("Apple Sign-In requires web-based authentication on Android");
|
|
46
|
-
return null;
|
|
47
|
-
|
|
48
|
-
case "github":
|
|
49
|
-
case "github.com":
|
|
50
|
-
// GitHub uses OAuth web flow
|
|
51
|
-
logger.info("GitHub authentication uses OAuth web flow");
|
|
52
|
-
return null;
|
|
53
|
-
|
|
54
|
-
case "slack":
|
|
55
|
-
case "slack.com":
|
|
56
|
-
// Slack uses OAuth web flow
|
|
57
|
-
logger.info("Slack authentication uses OAuth web flow");
|
|
58
|
-
return null;
|
|
59
|
-
|
|
60
|
-
case "linkedin":
|
|
61
|
-
case "linkedin.com":
|
|
62
|
-
// LinkedIn uses OAuth web flow
|
|
63
|
-
logger.info("LinkedIn authentication uses OAuth web flow");
|
|
64
|
-
return null;
|
|
65
|
-
|
|
66
41
|
default:
|
|
67
|
-
|
|
42
|
+
// Every non-Google provider is disabled in the Google-first build. The JS layer already
|
|
43
|
+
// reports AuthErrorCode.PROVIDER_NOT_ENABLED before reaching native; this is a safety net.
|
|
44
|
+
logger.warn("Provider '" + providerType + "' is not enabled yet (Google-only build).");
|
|
68
45
|
return null;
|
|
69
46
|
}
|
|
70
47
|
}
|
|
@@ -128,81 +105,4 @@ public class ProviderFactory {
|
|
|
128
105
|
|
|
129
106
|
return provider;
|
|
130
107
|
}
|
|
131
|
-
|
|
132
|
-
private static FacebookAuthProvider createFacebookProvider(
|
|
133
|
-
Context context,
|
|
134
|
-
Activity activity,
|
|
135
|
-
AuthStorage storage,
|
|
136
|
-
AuthLogger logger,
|
|
137
|
-
JSObject config
|
|
138
|
-
) {
|
|
139
|
-
FacebookAuthProvider provider = new FacebookAuthProvider(context, activity, storage, logger);
|
|
140
|
-
|
|
141
|
-
if (config != null) {
|
|
142
|
-
String appId = config.getString("appId");
|
|
143
|
-
if (appId != null) {
|
|
144
|
-
provider.setAppId(appId);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
JSONArray permissionsArray = config.getJSONArray("permissions");
|
|
149
|
-
if (permissionsArray == null) {
|
|
150
|
-
permissionsArray = config.getJSONArray("scopes");
|
|
151
|
-
}
|
|
152
|
-
if (permissionsArray != null) {
|
|
153
|
-
List<String> permissions = new ArrayList<>();
|
|
154
|
-
for (int i = 0; i < permissionsArray.length(); i++) {
|
|
155
|
-
permissions.add(permissionsArray.getString(i));
|
|
156
|
-
}
|
|
157
|
-
provider.setPermissions(permissions);
|
|
158
|
-
}
|
|
159
|
-
} catch (JSONException e) {
|
|
160
|
-
// Use default permissions
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return provider;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private static MicrosoftAuthProvider createMicrosoftProvider(
|
|
168
|
-
Context context,
|
|
169
|
-
Activity activity,
|
|
170
|
-
AuthStorage storage,
|
|
171
|
-
AuthLogger logger,
|
|
172
|
-
JSObject config
|
|
173
|
-
) {
|
|
174
|
-
MicrosoftAuthProvider provider = new MicrosoftAuthProvider(context, activity, storage, logger);
|
|
175
|
-
|
|
176
|
-
if (config != null) {
|
|
177
|
-
String clientId = config.getString("clientId");
|
|
178
|
-
if (clientId != null) {
|
|
179
|
-
provider.setClientId(clientId);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
String authority = config.getString("authority");
|
|
183
|
-
if (authority != null) {
|
|
184
|
-
provider.setAuthority(authority);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
String redirectUri = config.getString("redirectUri");
|
|
188
|
-
if (redirectUri != null) {
|
|
189
|
-
provider.setRedirectUri(redirectUri);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
JSONArray scopesArray = config.getJSONArray("scopes");
|
|
194
|
-
if (scopesArray != null) {
|
|
195
|
-
List<String> scopes = new ArrayList<>();
|
|
196
|
-
for (int i = 0; i < scopesArray.length(); i++) {
|
|
197
|
-
scopes.add(scopesArray.getString(i));
|
|
198
|
-
}
|
|
199
|
-
provider.setScopes(scopes);
|
|
200
|
-
}
|
|
201
|
-
} catch (JSONException e) {
|
|
202
|
-
// Use default scopes
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return provider;
|
|
207
|
-
}
|
|
208
108
|
}
|
|
@@ -27,7 +27,7 @@ import Capacitor
|
|
|
27
27
|
logger.setLogLevel(options.logLevel)
|
|
28
28
|
|
|
29
29
|
// Configure storage persistence
|
|
30
|
-
storage.setPersistence(options.persistence)
|
|
30
|
+
storage.setPersistence(options.persistence.rawValue)
|
|
31
31
|
|
|
32
32
|
// Initialize providers
|
|
33
33
|
let group = DispatchGroup()
|
|
@@ -76,7 +76,7 @@ import Capacitor
|
|
|
76
76
|
provider.signIn(credentials: options.credentials, options: options.options) { result, error in
|
|
77
77
|
if let result = result {
|
|
78
78
|
self.currentProvider = options.provider
|
|
79
|
-
self.storage.setLastAuthProvider(options.provider)
|
|
79
|
+
self.storage.setLastAuthProvider(options.provider.rawValue)
|
|
80
80
|
|
|
81
81
|
// Notify listeners
|
|
82
82
|
self.notifyAuthStateChange(result.user)
|
|
@@ -374,7 +374,7 @@ import Capacitor
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
func setCustomParameters(provider: AuthProvider, parameters: JSObject, completion: @escaping (Error?) -> Void) {
|
|
377
|
-
storage.setCustomParameters(provider: provider, parameters: parameters)
|
|
377
|
+
storage.setCustomParameters(provider: provider.rawValue, parameters: parameters)
|
|
378
378
|
completion(nil)
|
|
379
379
|
}
|
|
380
380
|
|
|
@@ -399,19 +399,10 @@ import Capacitor
|
|
|
399
399
|
switch config.provider {
|
|
400
400
|
case .google:
|
|
401
401
|
return GoogleAuthProvider(config: config, storage: storage, logger: logger)
|
|
402
|
-
case .apple:
|
|
403
|
-
return AppleAuthProvider(config: config, storage: storage, logger: logger)
|
|
404
|
-
case .microsoft:
|
|
405
|
-
return MicrosoftAuthProvider(config: config, storage: storage, logger: logger)
|
|
406
|
-
case .facebook:
|
|
407
|
-
return FacebookAuthProvider(config: config, storage: storage, logger: logger)
|
|
408
|
-
case .github:
|
|
409
|
-
return GitHubAuthProvider(config: config, storage: storage, logger: logger)
|
|
410
|
-
case .slack:
|
|
411
|
-
return SlackAuthProvider(config: config, storage: storage, logger: logger)
|
|
412
|
-
case .linkedin:
|
|
413
|
-
return LinkedInAuthProvider(config: config, storage: storage, logger: logger)
|
|
414
402
|
default:
|
|
403
|
+
// Google-first build (2.4.x): non-Google native providers are disabled. Their Swift lives in
|
|
404
|
+
// ios/disabled-native-providers/ (not compiled, not shipped) so this pod no longer depends on
|
|
405
|
+
// the Facebook SDK / MSAL. The JS layer reports PROVIDER_NOT_ENABLED before reaching native.
|
|
415
406
|
throw AuthManagerError.providerNotImplemented(config.provider)
|
|
416
407
|
}
|
|
417
408
|
}
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -115,9 +115,11 @@ public class CapacitorAuthManagerPlugin: CAPPlugin {
|
|
|
115
115
|
])
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
// CAPPlugin provides a built-in removeAllListeners(_:) in Capacitor 8; override it so our auth-state
|
|
119
|
+
// listener registry is cleared too, then let the base clear Capacitor's listeners and resolve.
|
|
120
|
+
@objc override public func removeAllListeners(_ call: CAPPluginCall) {
|
|
119
121
|
implementation.removeAllListeners()
|
|
120
|
-
|
|
122
|
+
super.removeAllListeners(call)
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
@objc func isSupported(_ call: CAPPluginCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-auth-manager",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "Capacitor + web authentication. Firebase-agnostic native & web Google sign-in (idToken/accessToken) for React, Vue, Angular and vanilla JS — 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",
|
|
@@ -48,10 +48,11 @@
|
|
|
48
48
|
"android/proguard-rules.pro",
|
|
49
49
|
"dist/",
|
|
50
50
|
"ios/Plugin/",
|
|
51
|
+
"scripts/configure.js",
|
|
51
52
|
"CapacitorAuthManager.podspec",
|
|
53
|
+
"README.md",
|
|
52
54
|
"CHANGELOG.md",
|
|
53
|
-
"
|
|
54
|
-
"!**/AGENTS.md"
|
|
55
|
+
"LICENSE"
|
|
55
56
|
],
|
|
56
57
|
"author": {
|
|
57
58
|
"email": "aoneahsan@gmail.com",
|
|
@@ -66,37 +67,24 @@
|
|
|
66
67
|
"bugs": {
|
|
67
68
|
"url": "https://github.com/aoneahsan/capacitor-auth-manager/issues"
|
|
68
69
|
},
|
|
69
|
-
"homepage": "https://
|
|
70
|
+
"homepage": "https://capacitor-auth-manager-docs.aoneahsan.com",
|
|
71
|
+
"funding": "https://aoneahsan.com/payment?project-id=capacitor-auth-manager&project-identifier=capacitor-auth-manager",
|
|
70
72
|
"keywords": [
|
|
71
|
-
"
|
|
73
|
+
"capacitor",
|
|
72
74
|
"authentication",
|
|
75
|
+
"google-sign-in",
|
|
73
76
|
"oauth",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"microsoft",
|
|
77
|
-
"facebook",
|
|
78
|
-
"github",
|
|
79
|
-
"slack",
|
|
80
|
-
"linkedin",
|
|
81
|
-
"firebase",
|
|
82
|
-
"email-magic-link",
|
|
83
|
-
"sms",
|
|
84
|
-
"email-code",
|
|
85
|
-
"biometric",
|
|
77
|
+
"id-token",
|
|
78
|
+
"capacitor-plugin",
|
|
86
79
|
"react",
|
|
87
80
|
"vue",
|
|
88
|
-
"angular"
|
|
89
|
-
"capacitor",
|
|
90
|
-
"plugin",
|
|
91
|
-
"native",
|
|
92
|
-
"web",
|
|
93
|
-
"pwa",
|
|
94
|
-
"universal"
|
|
81
|
+
"angular"
|
|
95
82
|
],
|
|
96
83
|
"scripts": {
|
|
97
84
|
"build": "npm run clean && npm run tsc && rollup -c rollup.config.mjs",
|
|
98
85
|
"clean": "rimraf ./dist",
|
|
99
86
|
"tsc": "tsc -p tsconfig.build.json",
|
|
87
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
100
88
|
"watch": "tsc --watch",
|
|
101
89
|
"lint": "eslint .",
|
|
102
90
|
"prettier": "prettier --write .",
|
package/Readme.md
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
# Capacitor Auth Manager
|
|
2
|
-
|
|
3
|
-
Firebase-agnostic **Google authentication** for Capacitor + web — a drop-in alternative to
|
|
4
|
-
`@codetrix-studio/capacitor-google-auth`. One API (`signIn(AuthProvider.GOOGLE)`) returns a Google
|
|
5
|
-
credential `{ idToken, accessToken?, serverAuthCode?, user }` on **web, iOS and Android**; your app feeds
|
|
6
|
-
the `idToken` into Firebase (or anything else). Works with React, Vue, Angular, and vanilla JS.
|
|
7
|
-
|
|
8
|
-
> **Status (2.4.x): Google-first.** The package is being brought to production **one provider at a time**.
|
|
9
|
-
> Right now **Google is enabled** (web + iOS + Android). The other 14 providers' code lives in the repo but
|
|
10
|
-
> is un-registered — calling them throws `AuthErrorCode.PROVIDER_NOT_ENABLED` — and each is re-enabled and
|
|
11
|
-
> verified on device one at a time. See the [changelog](./CHANGELOG.md).
|
|
12
|
-
|
|
13
|
-
## Why this exists
|
|
14
|
-
|
|
15
|
-
For native Google sign-in in a Capacitor app you normally reach for `@codetrix-studio/capacitor-google-auth`.
|
|
16
|
-
This package does the same job (native Google ID token → your Firebase `signInWithCredential`) but is yours
|
|
17
|
-
to maintain, uses the modern **Android Credential Manager** and **GoogleSignIn** SDKs, keeps the **same call
|
|
18
|
-
on every platform**, and stays **Firebase-agnostic** (no `firebase` dependency pulled in).
|
|
19
|
-
|
|
20
|
-
## Install
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install capacitor-auth-manager
|
|
24
|
-
# then, for the native plugin:
|
|
25
|
-
npx cap sync
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
`@capacitor/core` is an optional peer — needed only for the native (iOS/Android) plugin. Framework adapters
|
|
29
|
-
(`react` / `vue` / `@angular/core`) are optional peers too; install only what you use.
|
|
30
|
-
|
|
31
|
-
## Provider support
|
|
32
|
-
|
|
33
|
-
| Provider | Web | iOS | Android | Status |
|
|
34
|
-
|---|---|---|---|---|
|
|
35
|
-
| **Google** | ✅ GIS id-token | ✅ GoogleSignIn | ✅ Credential Manager | **Enabled** |
|
|
36
|
-
| Apple, Microsoft, Facebook, GitHub, Slack, LinkedIn, Firebase, Magic-link, SMS, Email/Phone/Username+password, Email-code, Biometric | — | — | — | ⏳ coming, one at a time (`PROVIDER_NOT_ENABLED`) |
|
|
37
|
-
|
|
38
|
-
## Quick start
|
|
39
|
-
|
|
40
|
-
Configure once, then sign in. Use the exported **`AuthProvider` enum** (recommended — typo-safe; the plain
|
|
41
|
-
string `'google'` also works).
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import { auth, AuthProvider } from 'capacitor-auth-manager';
|
|
45
|
-
|
|
46
|
-
auth.configure({
|
|
47
|
-
providers: {
|
|
48
|
-
[AuthProvider.GOOGLE]: {
|
|
49
|
-
clientId: 'YOUR_WEB_OAUTH_CLIENT_ID', // web + Android serverClientId fallback
|
|
50
|
-
serverClientId: 'YOUR_WEB_OAUTH_CLIENT_ID', // REQUIRED on Android to receive an idToken
|
|
51
|
-
iosClientId: 'YOUR_IOS_OAUTH_CLIENT_ID', // iOS (or set GIDClientID in Info.plist)
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
persistence: 'local',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const result = await auth.signIn(AuthProvider.GOOGLE);
|
|
58
|
-
// The same field is populated on web, iOS and Android:
|
|
59
|
-
const idToken = result.credential.idToken;
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Hand the credential to Firebase (identical on every platform)
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
import { getAuth, GoogleAuthProvider, signInWithCredential } from 'firebase/auth';
|
|
66
|
-
|
|
67
|
-
const result = await auth.signIn(AuthProvider.GOOGLE);
|
|
68
|
-
await signInWithCredential(
|
|
69
|
-
getAuth(),
|
|
70
|
-
GoogleAuthProvider.credential(result.credential.idToken),
|
|
71
|
-
);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### React
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import { useAuth, AuthProvider } from 'capacitor-auth-manager/react';
|
|
78
|
-
|
|
79
|
-
function LoginButton() {
|
|
80
|
-
const { user, signIn, signOut } = useAuth();
|
|
81
|
-
if (user) return <button onClick={() => signOut()}>Sign out</button>;
|
|
82
|
-
return <button onClick={() => signIn(AuthProvider.GOOGLE)}>Sign in with Google</button>;
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
`useAuth()` also returns `isLoading`, `isAuthenticated`, `error`, `refreshToken`, `getIdToken`, and
|
|
87
|
-
`revokeAccess`. Vue (`capacitor-auth-manager/vue`) and Angular (`capacitor-auth-manager/angular`) expose the
|
|
88
|
-
same surface as composables / an injectable `AuthService`; both re-export `AuthProvider`.
|
|
89
|
-
|
|
90
|
-
## What you get back
|
|
91
|
-
|
|
92
|
-
`signIn` resolves to an `AuthResult`:
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
{
|
|
96
|
-
user: { uid, email, emailVerified, displayName, photoURL, providerData: [...], metadata: {...} },
|
|
97
|
-
credential: {
|
|
98
|
-
providerId: 'google.com',
|
|
99
|
-
signInMethod: 'google.com',
|
|
100
|
-
idToken?: string, // present on web, iOS, Android
|
|
101
|
-
accessToken?: string, // iOS; web/Android: see notes below
|
|
102
|
-
serverAuthCode?: string, // iOS when serverClientId + offline access; exchange on YOUR server only
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Per-platform token availability (honest):
|
|
108
|
-
|
|
109
|
-
- **Web** (Google Identity Services id-token flow): returns **`idToken`** only — no `accessToken`. If you
|
|
110
|
-
need to call Google APIs from the browser, use the GIS token client separately.
|
|
111
|
-
- **iOS** (GoogleSignIn): `idToken` + `accessToken` (+ `serverAuthCode` when `serverClientId` is set).
|
|
112
|
-
- **Android** (Credential Manager): returns **`idToken`** reliably. `accessToken` / `serverAuthCode` require
|
|
113
|
-
the separate Google Authorization API and are not returned by the sign-in call (planned).
|
|
114
|
-
|
|
115
|
-
For the Firebase `signInWithCredential` handoff, the **`idToken` is all you need** on every platform.
|
|
116
|
-
|
|
117
|
-
## Native setup
|
|
118
|
-
|
|
119
|
-
### Android
|
|
120
|
-
|
|
121
|
-
1. In Google Cloud / Firebase, create an **Android** OAuth client and add your app's **SHA-1/SHA-256**
|
|
122
|
-
signing fingerprints; create (or reuse) a **Web** OAuth client.
|
|
123
|
-
2. Pass that **Web** client id as `serverClientId` (Credential Manager needs it to return an idToken).
|
|
124
|
-
3. Add your app's `google-services.json` to the Android project as usual.
|
|
125
|
-
4. The device must have a Google account signed in (Credential Manager shows that account chooser).
|
|
126
|
-
|
|
127
|
-
No extra AndroidManifest permissions are required by this plugin.
|
|
128
|
-
|
|
129
|
-
### iOS
|
|
130
|
-
|
|
131
|
-
1. Create an **iOS** OAuth client in Google Cloud.
|
|
132
|
-
2. Add `GIDClientID` (your iOS client id) to `Info.plist`, or pass it as `iosClientId`.
|
|
133
|
-
3. Add the **reversed client id** as a URL scheme in `Info.plist` → `CFBundleURLTypes`
|
|
134
|
-
(e.g. `com.googleusercontent.apps.XXXX`).
|
|
135
|
-
4. For a `serverAuthCode`, also set `serverClientId` (your Web client id).
|
|
136
|
-
|
|
137
|
-
### Capacitor config
|
|
138
|
-
|
|
139
|
-
You can also set the Google options in `capacitor.config` under the plugin block instead of `auth.configure`.
|
|
140
|
-
|
|
141
|
-
## Migrating from `@codetrix-studio/capacitor-google-auth`
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
// before
|
|
145
|
-
await GoogleAuth.initialize({ clientId });
|
|
146
|
-
const u = await GoogleAuth.signIn();
|
|
147
|
-
await signInWithCredential(getAuth(), GoogleAuthProvider.credential(u.authentication.idToken));
|
|
148
|
-
|
|
149
|
-
// after
|
|
150
|
-
import { auth, AuthProvider } from 'capacitor-auth-manager';
|
|
151
|
-
auth.configure({ providers: { [AuthProvider.GOOGLE]: { clientId, serverClientId, iosClientId } } });
|
|
152
|
-
const res = await auth.signIn(AuthProvider.GOOGLE);
|
|
153
|
-
await signInWithCredential(getAuth(), GoogleAuthProvider.credential(res.credential.idToken));
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
The id token moves from `result.authentication.idToken` to `result.credential.idToken`. Everything else
|
|
157
|
-
(the native account chooser, the Firebase handoff) behaves the same.
|
|
158
|
-
|
|
159
|
-
## Configuration (`GoogleAuthOptions`)
|
|
160
|
-
|
|
161
|
-
| Option | Where | Purpose |
|
|
162
|
-
|---|---|---|
|
|
163
|
-
| `clientId` | web (required), Android fallback | Web OAuth client id; the id token's `aud`. |
|
|
164
|
-
| `serverClientId` | Android (required for idToken), iOS | Web OAuth client id for Credential Manager / `serverAuthCode`. |
|
|
165
|
-
| `iosClientId` | iOS | iOS OAuth client id (or set `GIDClientID` in Info.plist). |
|
|
166
|
-
| `scopes` | all | Extra OAuth scopes (default `openid email profile`). |
|
|
167
|
-
| `hostedDomain` / `loginHint` | all | Restrict to a Workspace domain / prefill an account. |
|
|
168
|
-
| `filterByAuthorizedAccounts`, `autoSelectEnabled` | Android | Credential Manager UX (returning-user / one-tap auto-select). |
|
|
169
|
-
| `nonce` | web | Bind the request to an id-token `nonce` claim (validated). |
|
|
170
|
-
|
|
171
|
-
## Security & storage
|
|
172
|
-
|
|
173
|
-
- **No secrets are persisted by default.** Short-lived id tokens are re-derived from the Google SDK's silent
|
|
174
|
-
restore rather than written to `localStorage` / `@capacitor/preferences`. Inject a `StorageInterface`
|
|
175
|
-
(ideally Keychain/Keystore-backed) if you need token persistence at rest.
|
|
176
|
-
- The web flow uses the GIS **id-token** flow specifically so **no client secret and no backend** are
|
|
177
|
-
required. A `serverAuthCode` (iOS) must be exchanged on **your** server, never in the browser.
|
|
178
|
-
- The package does not verify id-token signatures in the browser — validate the id token server-side (or via
|
|
179
|
-
Firebase) before trusting its claims.
|
|
180
|
-
|
|
181
|
-
## Caveats
|
|
182
|
-
|
|
183
|
-
- The iOS (Swift) and Android (Java) sources are written to the official SDK contracts but are **not compiled
|
|
184
|
-
in CI**. Validate a new version in **one** app (web + one Android device + one iOS device) before rolling
|
|
185
|
-
out to many apps.
|
|
186
|
-
- Web Google sign-in uses One-Tap / FedCM `prompt()`; if One-Tap is suppressed (cooldown), render Google's
|
|
187
|
-
official button via the provider's `renderButton(element)` escape hatch, or use your own Firebase popup on web.
|
|
188
|
-
|
|
189
|
-
## Contributing & support
|
|
190
|
-
|
|
191
|
-
- [Contributing](./.github/CONTRIBUTING.md) · [Security policy](./.github/SECURITY.md) ·
|
|
192
|
-
[Support](./.github/SUPPORT.md) · [Changelog](./CHANGELOG.md)
|
|
193
|
-
- Docs: https://github.com/aoneahsan/capacitor-auth-manager-docs
|
|
194
|
-
- Author: Ahsan Mahmood — aoneahsan@gmail.com — https://aoneahsan.com
|
|
195
|
-
|
|
196
|
-
## License
|
|
197
|
-
|
|
198
|
-
[MIT](./LICENSE) © 2024–2026 Ahsan Mahmood
|
|
199
|
-
|
|
200
|
-
## Links
|
|
201
|
-
|
|
202
|
-
- npm: https://www.npmjs.com/package/capacitor-auth-manager
|
|
203
|
-
- Repository: https://github.com/aoneahsan/capacitor-auth-manager
|