capacitor-auth-manager 2.1.0 → 2.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.
Files changed (148) hide show
  1. package/CapacitorAuthManager.podspec +1 -1
  2. package/Readme.md +223 -103
  3. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +28 -0
  4. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +109 -15
  5. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/FacebookAuthProvider.java +389 -0
  6. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +353 -0
  7. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/MicrosoftAuthProvider.java +455 -0
  8. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +180 -0
  9. package/dist/angular.cjs.js +7017 -0
  10. package/dist/angular.cjs.js.map +1 -0
  11. package/dist/core.cjs.js +2155 -444
  12. package/dist/core.cjs.js.map +1 -1
  13. package/dist/esm/angular/auth.guard.d.ts +18 -0
  14. package/dist/esm/angular/auth.guard.js +82 -0
  15. package/dist/esm/angular/auth.guard.js.map +1 -0
  16. package/dist/esm/angular/auth.module.d.ts +18 -0
  17. package/dist/esm/angular/auth.module.js +56 -0
  18. package/dist/esm/angular/auth.module.js.map +1 -0
  19. package/dist/esm/angular/auth.service.d.ts +108 -0
  20. package/dist/esm/angular/auth.service.js +224 -0
  21. package/dist/esm/angular/auth.service.js.map +1 -0
  22. package/dist/esm/angular/index.d.ts +3 -0
  23. package/dist/esm/angular/index.js +4 -0
  24. package/dist/esm/angular/index.js.map +1 -0
  25. package/dist/esm/core/auth-manager.d.ts +61 -1
  26. package/dist/esm/core/auth-manager.js +285 -24
  27. package/dist/esm/core/auth-manager.js.map +1 -1
  28. package/dist/esm/core/platform.d.ts +7 -0
  29. package/dist/esm/core/platform.js +30 -10
  30. package/dist/esm/core/platform.js.map +1 -1
  31. package/dist/esm/core/provider-manifests.d.ts +9 -0
  32. package/dist/esm/core/provider-manifests.js +471 -0
  33. package/dist/esm/core/provider-manifests.js.map +1 -0
  34. package/dist/esm/core/provider-registry.d.ts +19 -1
  35. package/dist/esm/core/provider-registry.js +72 -480
  36. package/dist/esm/core/provider-registry.js.map +1 -1
  37. package/dist/esm/core/types.d.ts +18 -7
  38. package/dist/esm/definitions.d.ts +42 -1
  39. package/dist/esm/definitions.js +28 -0
  40. package/dist/esm/definitions.js.map +1 -1
  41. package/dist/esm/index.d.ts +4 -0
  42. package/dist/esm/index.js +6 -0
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/providers/base-provider.d.ts +3 -3
  45. package/dist/esm/providers/base-provider.js +26 -1
  46. package/dist/esm/providers/base-provider.js.map +1 -1
  47. package/dist/esm/providers/oauth-provider.d.ts +23 -2
  48. package/dist/esm/providers/oauth-provider.js +134 -17
  49. package/dist/esm/providers/oauth-provider.js.map +1 -1
  50. package/dist/esm/providers/provider-factory.d.ts +3 -1
  51. package/dist/esm/providers/provider-factory.js +29 -41
  52. package/dist/esm/providers/provider-factory.js.map +1 -1
  53. package/dist/esm/providers/web/apple-provider.d.ts +2 -1
  54. package/dist/esm/providers/web/apple-provider.js +25 -9
  55. package/dist/esm/providers/web/apple-provider.js.map +1 -1
  56. package/dist/esm/providers/web/biometric-provider.d.ts +14 -0
  57. package/dist/esm/providers/web/biometric-provider.js +116 -18
  58. package/dist/esm/providers/web/biometric-provider.js.map +1 -1
  59. package/dist/esm/providers/web/email-code-provider.d.ts +48 -0
  60. package/dist/esm/providers/web/email-code-provider.js +295 -0
  61. package/dist/esm/providers/web/email-code-provider.js.map +1 -0
  62. package/dist/esm/providers/web/email-password-provider.js +29 -28
  63. package/dist/esm/providers/web/email-password-provider.js.map +1 -1
  64. package/dist/esm/providers/web/facebook-provider.d.ts +52 -1
  65. package/dist/esm/providers/web/facebook-provider.js +2 -2
  66. package/dist/esm/providers/web/facebook-provider.js.map +1 -1
  67. package/dist/esm/providers/web/firebase-provider.d.ts +5 -3
  68. package/dist/esm/providers/web/firebase-provider.js +74 -42
  69. package/dist/esm/providers/web/firebase-provider.js.map +1 -1
  70. package/dist/esm/providers/web/github-provider.d.ts +9 -0
  71. package/dist/esm/providers/web/github-provider.js +91 -14
  72. package/dist/esm/providers/web/github-provider.js.map +1 -1
  73. package/dist/esm/providers/web/index.d.ts +2 -0
  74. package/dist/esm/providers/web/index.js +2 -0
  75. package/dist/esm/providers/web/index.js.map +1 -1
  76. package/dist/esm/providers/web/linkedin-provider.d.ts +2 -3
  77. package/dist/esm/providers/web/linkedin-provider.js +40 -14
  78. package/dist/esm/providers/web/linkedin-provider.js.map +1 -1
  79. package/dist/esm/providers/web/magic-link-provider.d.ts +3 -3
  80. package/dist/esm/providers/web/magic-link-provider.js +40 -26
  81. package/dist/esm/providers/web/magic-link-provider.js.map +1 -1
  82. package/dist/esm/providers/web/microsoft-provider.d.ts +2 -0
  83. package/dist/esm/providers/web/microsoft-provider.js +45 -20
  84. package/dist/esm/providers/web/microsoft-provider.js.map +1 -1
  85. package/dist/esm/providers/web/phone-password-provider.d.ts +66 -0
  86. package/dist/esm/providers/web/phone-password-provider.js +438 -0
  87. package/dist/esm/providers/web/phone-password-provider.js.map +1 -0
  88. package/dist/esm/providers/web/slack-provider.d.ts +2 -3
  89. package/dist/esm/providers/web/slack-provider.js +38 -14
  90. package/dist/esm/providers/web/slack-provider.js.map +1 -1
  91. package/dist/esm/providers/web/sms-provider.d.ts +3 -3
  92. package/dist/esm/providers/web/sms-provider.js +25 -18
  93. package/dist/esm/providers/web/sms-provider.js.map +1 -1
  94. package/dist/esm/providers/web/username-password-provider.js +23 -22
  95. package/dist/esm/providers/web/username-password-provider.js.map +1 -1
  96. package/dist/esm/react/hooks.d.ts +110 -0
  97. package/dist/esm/react/hooks.js +307 -0
  98. package/dist/esm/react/hooks.js.map +1 -0
  99. package/dist/esm/react/index.d.ts +2 -0
  100. package/dist/esm/react/index.js +3 -0
  101. package/dist/esm/react/index.js.map +1 -0
  102. package/dist/esm/react/types.d.ts +30 -0
  103. package/dist/esm/react/types.js +2 -0
  104. package/dist/esm/react/types.js.map +1 -0
  105. package/dist/esm/utils/auth-error.d.ts +7 -0
  106. package/dist/esm/utils/auth-error.js +31 -5
  107. package/dist/esm/utils/auth-error.js.map +1 -1
  108. package/dist/esm/utils/event-emitter.d.ts +7 -0
  109. package/dist/esm/utils/event-emitter.js +8 -2
  110. package/dist/esm/utils/event-emitter.js.map +1 -1
  111. package/dist/esm/utils/logger.d.ts +28 -1
  112. package/dist/esm/utils/logger.js +115 -1
  113. package/dist/esm/utils/logger.js.map +1 -1
  114. package/dist/esm/utils/pending-verification-store.d.ts +59 -0
  115. package/dist/esm/utils/pending-verification-store.js +103 -0
  116. package/dist/esm/utils/pending-verification-store.js.map +1 -0
  117. package/dist/esm/utils/storage.d.ts +29 -1
  118. package/dist/esm/utils/storage.js +64 -5
  119. package/dist/esm/utils/storage.js.map +1 -1
  120. package/dist/esm/vue/composables.d.ts +124 -0
  121. package/dist/esm/vue/composables.js +290 -0
  122. package/dist/esm/vue/composables.js.map +1 -0
  123. package/dist/esm/vue/index.d.ts +1 -0
  124. package/dist/esm/vue/index.js +2 -0
  125. package/dist/esm/vue/index.js.map +1 -0
  126. package/dist/esm/web.d.ts +32 -7
  127. package/dist/esm/web.js +247 -52
  128. package/dist/esm/web.js.map +1 -1
  129. package/dist/plugin.cjs.js +2606 -670
  130. package/dist/plugin.cjs.js.map +1 -1
  131. package/dist/plugin.js +2606 -670
  132. package/dist/plugin.js.map +1 -1
  133. package/dist/react.cjs.js +6972 -0
  134. package/dist/react.cjs.js.map +1 -0
  135. package/dist/vue.cjs.js +6955 -0
  136. package/dist/vue.cjs.js.map +1 -0
  137. package/ios/Plugin/AppleAuthProvider.swift +288 -0
  138. package/ios/Plugin/AuthStorage.swift +49 -1
  139. package/ios/Plugin/CapacitorAuthManager.swift +45 -23
  140. package/ios/Plugin/FacebookAuthProvider.swift +297 -0
  141. package/ios/Plugin/GitHubAuthProvider.swift +54 -0
  142. package/ios/Plugin/GoogleAuthProvider.swift +265 -0
  143. package/ios/Plugin/LinkedInAuthProvider.swift +63 -0
  144. package/ios/Plugin/MicrosoftAuthProvider.swift +315 -0
  145. package/ios/Plugin/Models.swift +4 -1
  146. package/ios/Plugin/OAuthWebProvider.swift +415 -0
  147. package/ios/Plugin/SlackAuthProvider.swift +108 -0
  148. package/package.json +60 -39
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '13.0'
14
+ s.ios.deployment_target = '14.0'
15
15
  s.swift_version = '5.9'
16
16
  s.dependency 'Capacitor'
17
17
 
package/Readme.md CHANGED
@@ -1,29 +1,85 @@
1
1
  # Capacitor Auth Manager
2
2
 
3
- Universal authentication manager with 13+ providers. Framework-agnostic, works with React, Vue, Angular, and vanilla JS. Optional Capacitor support for mobile apps.
3
+ Universal authentication manager with 15 web providers. Framework-agnostic, works with React, Vue, Angular, and vanilla JS. Optional Capacitor support for mobile apps.
4
4
 
5
- ## 🚀 v2.0 - Complete Rewrite!
5
+ ## Current State
6
6
 
7
- Version 2.0 is a complete rewrite focusing on developer experience, smaller bundle sizes, and flexibility:
7
+ - Current package version: `2.2.0`
8
+ - Verified on: `2026-05-26`
9
+ - Tests: `79/79` passing via `npm run test:run`
10
+ - Build: `npm run build` succeeds
11
+ - Current package shape:
12
+ - core auth manager API (the `auth` singleton)
13
+ - 15 web provider modules under `src/providers/web/`
14
+ - React hooks export
15
+ - Vue composables export
16
+ - Angular service/module/guard export
17
+ - optional Capacitor plugin surfaces for native integrations
18
+
19
+ ## Supported Environments
20
+
21
+ | Peer | Supported range |
22
+ |------|-----------------|
23
+ | `@capacitor/core` | `^7` or `^8` (optional — only needed for the native plugin / `CapacitorPreferencesStorage`) |
24
+ | `@angular/core` | up to `^21` (only for the Angular adapter) |
25
+ | `react` | `16.8`–`19` (only for the React adapter) |
26
+ | `vue` | `^3` (only for the Vue adapter) |
27
+ | iOS deployment target | 14 |
28
+
29
+ `@capacitor/preferences` is an **optional** peer — install it only if you inject `CapacitorPreferencesStorage` for native token storage.
30
+
31
+ ## What's New in 2.2.0
32
+
33
+ 2.2.0 is a backward-compatible minor release. No public method signatures were removed. Highlights:
34
+
35
+ - **PKCE on the authorization-code OAuth flow.** Manual OAuth flows (Slack, LinkedIn) now send a SHA-256 (`S256`) code challenge/verifier per RFC 7636. OIDC `nonce` and the ID-token `exp` claim are validated. The library does **not** verify ID-token signatures in the browser — re-validate ID tokens server-side before trusting their claims.
36
+ - **Pluggable secure storage.** `configure()` accepts a `storage` option (any `StorageInterface`). A new exported `CapacitorPreferencesStorage` backs storage with `@capacitor/preferences` (an optional peer) so native tokens live in native key-value storage instead of the webview's `localStorage`. Default web storage is still `localStorage`, which is readable by any XSS/third-party script — inject secure storage on native. (Capacitor Preferences is not hardware-encrypted; use a Keychain/Keystore-backed adapter for secrecy at rest.)
37
+ - **Real biometric web fallback encryption.** Stored biometric material now uses AES-GCM with a non-extractable IndexedDB key instead of base64 encoding.
38
+ - **Account-management methods on the singleton and all adapters.** `linkAccount`, `unlinkAccount`, `revokeAccess`, `getIdToken`, `updateProfile`, `deleteAccount`, plus `isProviderConfigured()` / `getConfiguredProviders()` are now available on the `auth` singleton and surfaced through the React/Vue/Angular adapters.
39
+ - **GitHub sign-in completes via a backend proxy.** A new `tokenExchangeProxy` config field points at a developer-supplied endpoint that exchanges the GitHub `code` for a token. GitHub cannot do secure token exchange purely in-browser; without the proxy you get a clear `MISSING_CONFIG` error.
40
+ - **Slack and LinkedIn fetch real user profiles** (Slack `openid.connect.userInfo`, LinkedIn `/v2/userinfo`) instead of placeholder identities.
41
+ - **Firebase sign-in method** is derived from your standard options/credentials, with a new `defaultMethod` config field as the fallback.
42
+ - **All errors use the `AuthErrorCode` enum.** Standalone providers no longer throw bare string codes — switch on `error.code` reliably.
43
+ - **Centralized logger.** A shared `defaultLogger` is exported; adjust verbosity via `VITE_LOG_LEVEL` / `LOG_LEVEL` (build-time) or `defaultLogger.setLevel('debug')` (runtime). Default level is `warn`.
44
+
45
+ One exported type was tightened (non-breaking widening to a precise type): `AuthManagerConfig.providers` is now `Record<string, ProviderOptions>` instead of `any`. See [MIGRATION.md](./docs/MIGRATION.md) for the full 2.1.0 → 2.2.0 notes.
46
+
47
+ ## Why This Package Exists
48
+
49
+ Capacitor Auth Manager standardizes authentication across web and mobile projects so teams do not have to rebuild auth orchestration, state handling, provider configuration, and framework glue for every new product.
50
+
51
+ ## Highlights
8
52
 
9
53
  - **No Provider Wrappers** - Works like Zustand, no context providers needed
10
54
  - **Framework Agnostic** - One package for React, Vue, Angular, and vanilla JS
11
55
  - **Optional Capacitor** - Use in regular web apps without Capacitor
12
56
  - **Dynamic Loading** - Providers load only when used (better tree-shaking)
13
- - **All 13 Providers Implemented** - Every promised provider is now available
57
+ - **Broad Provider Coverage** - Major OAuth, credential, passwordless, and biometric flows live behind one API
14
58
 
15
59
  ## Features
16
60
 
17
- - 🚀 **Zero Configuration** - Works out of the box with sensible defaults
18
61
  - 🎯 **Framework Agnostic** - Use with React, Vue, Angular, or vanilla JavaScript
19
- - 📦 **Tiny Bundle Size** - Only includes what you use with tree-shaking
20
- - 🔌 **13+ Auth Providers** - Google, Apple, Microsoft, Facebook, GitHub, and more
62
+ - 📦 **Tree-shakeable** - Only includes the providers you use
63
+ - 🔌 **15 Auth Providers** - Google, Apple, Microsoft, Facebook, GitHub, Slack, LinkedIn, Firebase, and password/passwordless/biometric flows
21
64
  - 🔄 **Provider-less Design** - No context providers required (like Zustand)
22
65
  - 📱 **Optional Capacitor** - Works in web apps without Capacitor
23
66
  - 🎨 **TypeScript First** - Full type safety and IntelliSense
24
- - 🔐 **Secure by Default** - Follows security best practices
67
+ - 🔐 **PKCE + pluggable storage** - S256 PKCE on manual OAuth flows; inject secure storage on native
25
68
  - ⚡ **Dynamic Loading** - Providers load only when used
26
69
 
70
+ ## Verification Snapshot
71
+
72
+ ```bash
73
+ npm run test:run
74
+ npm run build
75
+ ```
76
+
77
+ Build remediation completed:
78
+
79
+ - Rollup now runs from `rollup.config.mjs`, eliminating the Node ESM reparsing warning
80
+ - `capacitor-biometric-authentication` is declared as an explicit optional dependency
81
+ - TypeScript helper imports now use `tslib`, eliminating the Angular rewritten-`this` warnings
82
+
27
83
  ## Quick Start
28
84
 
29
85
  ### Installation
@@ -152,21 +208,35 @@ export class LoginComponent {
152
208
 
153
209
  ## Supported Providers
154
210
 
155
- | Provider | Web | iOS | Android | Status |
156
- | ----------------- | --- | --- | ------- | -------------- |
157
- | Google | ✅ | ✅ | ✅ | ✅ Implemented |
158
- | Apple | ✅ | ✅ | ❌ | ✅ Implemented |
159
- | Microsoft | ✅ | ✅ | ✅ | ✅ Implemented |
160
- | Facebook | ✅ | ✅ | ✅ | ✅ Implemented |
161
- | GitHub | ✅ | ❌ | ❌ | ✅ Implemented |
162
- | Firebase | ✅ | ✅ | ✅ | ✅ Implemented |
163
- | Email Magic Link | ✅ | ✅ | ✅ | ✅ Implemented |
164
- | SMS | ✅ | ✅ | ✅ | ✅ Implemented |
165
- | Email/Password | ✅ | ✅ | ✅ | ✅ Implemented |
166
- | Biometric | ❌ | ✅ | ✅ | ✅ Implemented |
167
- | Slack | ✅ | ❌ | ❌ | ✅ Implemented |
168
- | LinkedIn | ✅ | ❌ | ❌ | ✅ Implemented |
169
- | Username/Password | ✅ | ✅ | ✅ | ✅ Implemented |
211
+ All 15 providers ship a web implementation (the primary path). The "Backend" column is the one to plan around — it states whether a provider completes sign-in in the browser or needs server-side support.
212
+
213
+ | Provider | Web | Backend required? |
214
+ | ------------------- | --- | -------------------------------------------------- |
215
+ | Google | ✅ | No (Google Identity Services manages PKCE) |
216
+ | Apple | ✅ | No for sign-in; re-validate the ID token server-side |
217
+ | Microsoft | ✅ | No (MSAL Browser, must be loaded on the page) |
218
+ | Facebook | ✅ | No (Facebook JS SDK) |
219
+ | GitHub | ✅ | **Yes** — set `tokenExchangeProxy`; no in-browser exchange |
220
+ | Slack | ✅ | Optional — manual code flow + real profile fetch |
221
+ | LinkedIn | ✅ | Optional — manual code flow + real profile fetch |
222
+ | Firebase | ✅ | No (Firebase JS SDK) |
223
+ | Email + Password | ✅ | Yes — credential verify/persist endpoint |
224
+ | Phone + Password | ✅ | Yes — credential verify endpoint |
225
+ | Username + Password | ✅ | Yes — credential verify (+ optional uniqueness) |
226
+ | Email Code (OTP) | ✅ | Yes — send/verify endpoint |
227
+ | SMS (OTP) | ✅ | Yes — Twilio / Firebase / custom backend |
228
+ | Magic Link | ✅ | Yes — send/verify endpoints |
229
+ | Biometric | ✅ | No — device-local; AES-GCM web fallback |
230
+
231
+ The implementation is strongest on the web/provider orchestration layer. The native Capacitor plugin (iOS/Android) is a secondary surface — validate any native flow against the platform code before relying on it. See [docs/api-reference/CAPABILITY_MATRIX.md](./docs/api-reference/CAPABILITY_MATRIX.md) for native status and full per-provider caveats.
232
+
233
+ ## Package Architecture
234
+
235
+ - `src/core/` contains the auth manager, provider registry, platform helpers, and shared types.
236
+ - `src/providers/web/` contains the provider implementations.
237
+ - `src/react/`, `src/vue/`, and `src/angular/` expose framework-specific adapters on top of the same core auth manager.
238
+ - `src/__tests__/` currently covers exported APIs, shared definitions, and selected provider/error flows with Vitest.
239
+ - `docs/` contains setup, API reference, migration, and production-readiness notes.
170
240
 
171
241
  ## Configuration
172
242
 
@@ -176,7 +246,7 @@ export class LoginComponent {
176
246
  import { auth } from 'capacitor-auth-manager';
177
247
 
178
248
  auth.configure({
179
- // Provider configurations
249
+ // Provider configurations (field names match the typed *AuthOptions interfaces)
180
250
  providers: {
181
251
  google: {
182
252
  clientId: 'YOUR_CLIENT_ID',
@@ -188,6 +258,7 @@ auth.configure({
188
258
  },
189
259
  microsoft: {
190
260
  clientId: 'YOUR_CLIENT_ID',
261
+ redirectUri: 'https://your-app.com/auth/callback',
191
262
  authority: 'https://login.microsoftonline.com/common',
192
263
  },
193
264
  facebook: {
@@ -197,51 +268,63 @@ auth.configure({
197
268
  github: {
198
269
  clientId: 'YOUR_CLIENT_ID',
199
270
  redirectUri: 'YOUR_REDIRECT_URI',
271
+ // Required: GitHub cannot exchange the code in-browser. This endpoint receives
272
+ // { code, redirectUri, state } and returns GitHub's token JSON.
273
+ tokenExchangeProxy: 'https://your-api.com/auth/github/token',
200
274
  },
201
275
  firebase: {
202
276
  apiKey: 'YOUR_API_KEY',
203
277
  authDomain: 'YOUR_AUTH_DOMAIN',
204
278
  projectId: 'YOUR_PROJECT_ID',
279
+ appId: 'YOUR_APP_ID',
280
+ defaultMethod: 'google', // fallback sub-method when none is specified
205
281
  },
206
282
  'magic-link': {
207
- sendLinkUrl: 'https://your-api.com/send-magic-link',
208
- verifyUrl: 'https://your-api.com/verify-magic-link',
283
+ endpoint: 'https://your-api.com/magic-link',
284
+ redirectUrl: 'https://your-app.com/auth/callback',
209
285
  },
210
286
  sms: {
211
- sendCodeUrl: 'https://your-api.com/sms/send',
212
- verifyCodeUrl: 'https://your-api.com/sms/verify',
287
+ provider: 'twilio',
288
+ twilioConfig: {
289
+ accountSid: 'YOUR_SID',
290
+ authToken: 'YOUR_TOKEN',
291
+ fromNumber: '+1234567890',
292
+ },
213
293
  },
214
294
  'email-password': {
215
- apiUrl: 'https://your-api.com',
216
- passwordRequirements: {
295
+ strengthRequirements: {
217
296
  minLength: 8,
218
297
  requireUppercase: true,
219
298
  requireNumbers: true,
220
299
  },
300
+ requireEmailVerification: true,
221
301
  },
222
302
  biometric: {
223
- reason: 'Authenticate to access your account',
224
303
  title: 'Authentication Required',
304
+ description: 'Authenticate to access your account',
225
305
  },
226
306
  slack: {
227
307
  clientId: 'YOUR_CLIENT_ID',
228
308
  redirectUri: 'https://your-app.com/auth/slack/callback',
229
- teamId: 'OPTIONAL_TEAM_ID', // Restrict to specific workspace
309
+ teamId: 'OPTIONAL_TEAM_ID', // Restrict to a specific workspace
230
310
  },
231
311
  linkedin: {
232
312
  clientId: 'YOUR_CLIENT_ID',
233
313
  redirectUri: 'https://your-app.com/auth/linkedin/callback',
314
+ scopes: ['openid', 'profile', 'email'],
234
315
  },
235
316
  'username-password': {
236
- apiUrl: 'https://your-api.com',
237
317
  usernameRequirements: {
238
318
  minLength: 3,
239
319
  maxLength: 20,
240
320
  },
241
- allowSignUp: true,
242
321
  },
243
322
  },
244
323
 
324
+ // Optional secure storage on native (requires the optional @capacitor/preferences peer).
325
+ // Default web storage is localStorage, which is readable by any XSS/3rd-party script.
326
+ // storage: new CapacitorPreferencesStorage(),
327
+
245
328
  // Global options
246
329
  persistence: 'local', // 'local' | 'session' | 'memory'
247
330
  autoRefreshToken: true,
@@ -255,8 +338,16 @@ auth.configure({
255
338
 
256
339
  Each provider may require additional setup. The package provides helpful error messages when dependencies are missing.
257
340
 
341
+ ## Portfolio Info File
342
+
343
+ For resume, portfolio, and social-content source material, use the root project file:
344
+
345
+ - `CAPACITOR-AUTH-MANAGER_portfolio-info_2026-03-25.md`
346
+
258
347
  ## Framework-Specific APIs
259
348
 
349
+ All three adapters surface the same account-management methods added in 2.2.0 (`linkAccount`, `unlinkAccount`, `revokeAccess`, `getIdToken`, `updateProfile`, `deleteAccount`).
350
+
260
351
  ### React Hooks
261
352
 
262
353
  - `useAuth()` - Complete authentication functionality
@@ -292,87 +383,67 @@ imports: [
292
383
  ### Email Magic Link
293
384
 
294
385
  ```typescript
295
- // Send magic link
296
- await auth.signIn('magic-link', { email: 'user@example.com' });
386
+ import { auth } from 'capacitor-auth-manager';
297
387
 
298
- // The user will receive an email with a link
299
- // When they click it, your app handles the callback
388
+ // Send the magic link. The user receives an email; verification completes on the
389
+ // link-click page load (pending metadata is persisted so it survives the redirect).
390
+ await auth.signIn({
391
+ provider: 'magic-link',
392
+ credentials: { email: 'user@example.com' },
393
+ });
300
394
  ```
301
395
 
302
396
  ### SMS Authentication
303
397
 
304
398
  ```typescript
305
- // Send SMS code
306
- const result = await auth.signIn('sms', { phoneNumber: '+1234567890' });
399
+ import { auth } from 'capacitor-auth-manager';
400
+
401
+ // Send the SMS code
402
+ await auth.signIn({
403
+ provider: 'sms',
404
+ credentials: { phoneNumber: '+1234567890' },
405
+ });
307
406
 
308
- // Verify SMS code
309
- await auth.signIn('sms', {
310
- phoneNumber: '+1234567890',
311
- code: '123456',
407
+ // Verify the SMS code
408
+ await auth.signIn({
409
+ provider: 'sms',
410
+ credentials: { phoneNumber: '+1234567890', code: '123456' },
312
411
  });
313
412
  ```
314
413
 
315
414
  ### Email/Password
316
415
 
416
+ Credentials are passed under `credentials` in the object form of `signIn`. The email/password provider requires a backend to verify and persist credentials.
417
+
317
418
  ```typescript
318
- // Sign up
319
- await auth.signUp({
320
- email: 'user@example.com',
321
- password: 'secure-password',
322
- displayName: 'John Doe',
323
- });
419
+ import { auth } from 'capacitor-auth-manager';
324
420
 
325
- // Sign in
326
- await auth.signIn('email-password', {
327
- email: 'user@example.com',
328
- password: 'secure-password',
421
+ await auth.signIn({
422
+ provider: 'email-password',
423
+ credentials: { email: 'user@example.com', password: 'secure-password' },
329
424
  });
330
-
331
- // Update password
332
- const provider = await auth.getProvider('email-password');
333
- await provider.updatePassword('oldPassword', 'newPassword');
334
-
335
- // Send password reset
336
- await provider.sendPasswordResetEmail('user@example.com');
337
425
  ```
338
426
 
339
427
  ### Biometric Authentication
340
428
 
341
- ```typescript
342
- // Check availability
343
- const biometric = await auth.getProvider('biometric');
344
- const { available, biometryType } = await biometric.isAvailable();
429
+ The web fallback stores credential material encrypted with AES-GCM (non-extractable IndexedDB key). On native, biometric verification runs through the optional native plugin.
345
430
 
346
- if (available) {
347
- // Store credentials after initial sign in
348
- const result = await auth.signIn('google');
349
- await biometric.storeUserCredentials(result.user, result.credential);
431
+ ```typescript
432
+ import { auth } from 'capacitor-auth-manager';
350
433
 
351
- // Later: authenticate with biometrics
352
- await auth.signIn('biometric');
353
- }
434
+ // Sign in with biometrics (after the provider is configured and credentials are stored)
435
+ await auth.signIn('biometric');
354
436
  ```
355
437
 
356
438
  ### Username/Password Authentication
357
439
 
358
440
  ```typescript
359
- // Sign up with username
360
- await auth.signUp({
361
- username: 'johndoe',
362
- password: 'secure-password',
363
- email: 'john@example.com', // optional
364
- displayName: 'John Doe', // optional
365
- });
441
+ import { auth } from 'capacitor-auth-manager';
366
442
 
367
- // Sign in
368
- await auth.signIn('username-password', {
369
- username: 'johndoe',
370
- password: 'secure-password',
443
+ await auth.signIn({
444
+ provider: 'username-password',
445
+ credentials: { username: 'johndoe', password: 'secure-password' },
371
446
  });
372
-
373
- // Check username availability
374
- const provider = await auth.getProvider('username-password');
375
- const isAvailable = await provider.checkUsernameAvailability('johndoe');
376
447
  ```
377
448
 
378
449
  ### Slack Authentication
@@ -413,37 +484,71 @@ auth.configure({
413
484
 
414
485
  ### Multiple Sign-In Options
415
486
 
487
+ `signIn` accepts either a provider id string or a `SignInOptions` object. Provider-specific options go under `options`.
488
+
416
489
  ```typescript
417
490
  // Simple provider name
418
491
  await auth.signIn('google');
419
492
 
420
493
  // With scopes
421
- await auth.signIn('google', {
422
- scopes: ['https://www.googleapis.com/auth/calendar'],
494
+ await auth.signIn({
495
+ provider: 'google',
496
+ options: { scopes: ['https://www.googleapis.com/auth/calendar'] },
423
497
  });
424
498
 
425
499
  // With login hint
426
- await auth.signIn('google', {
427
- loginHint: 'user@example.com',
500
+ await auth.signIn({
501
+ provider: 'google',
502
+ options: { loginHint: 'user@example.com' },
428
503
  });
429
504
  ```
430
505
 
431
506
  ### Token Management
432
507
 
433
- ```typescript
434
- // Listen to token state
435
- auth.onAuthStateChange((state) => {
436
- if (state.credential?.expiresAt) {
437
- console.log('Token expires at:', new Date(state.credential.expiresAt));
438
- }
439
- });
508
+ `AuthState` exposes `{ user, isLoading, isAuthenticated, provider }` — it does not carry raw tokens. Read an ID token via `getIdToken()` and refresh via `refreshToken()`.
440
509
 
441
- // Manual token refresh
510
+ ```typescript
511
+ // Manual token refresh (provider-dependent)
442
512
  await auth.refreshToken();
443
513
 
444
- // Get current token
514
+ // Get a fresh ID token for server-side verification (provider-dependent).
515
+ // Note: the library does NOT verify ID-token signatures client-side — verify on your server.
516
+ const idToken = await auth.getIdToken({ forceRefresh: true });
517
+
518
+ // Inspect current state
445
519
  const state = auth.getAuthState();
446
- const token = state.credential?.accessToken;
520
+ console.log(state.isAuthenticated, state.provider, state.user?.email);
521
+ ```
522
+
523
+ ### Account Management (2.2.0)
524
+
525
+ These delegate to the active provider; an unsupported provider throws `AuthErrorCode.OPERATION_NOT_ALLOWED`.
526
+
527
+ ```typescript
528
+ import { auth } from 'capacitor-auth-manager';
529
+
530
+ await auth.linkAccount({ provider: 'facebook' });
531
+ await auth.unlinkAccount({ provider: 'facebook' });
532
+ await auth.updateProfile({ displayName: 'New Name' });
533
+ await auth.revokeAccess();
534
+ await auth.deleteAccount();
535
+
536
+ // Inspect configuration
537
+ auth.isProviderConfigured('google'); // boolean
538
+ auth.getConfiguredProviders(); // string[]
539
+ ```
540
+
541
+ ### Secure Storage on Native (2.2.0)
542
+
543
+ Default web storage is `localStorage` (readable by XSS). On native, inject `CapacitorPreferencesStorage` (requires the optional `@capacitor/preferences` peer) so tokens live in native key-value storage. Capacitor Preferences is not hardware-encrypted — for secrecy at rest, supply a Keychain/Keystore-backed `StorageInterface`.
544
+
545
+ ```typescript
546
+ import { auth, CapacitorPreferencesStorage } from 'capacitor-auth-manager';
547
+
548
+ auth.configure({
549
+ storage: new CapacitorPreferencesStorage(),
550
+ providers: { google: { clientId: 'YOUR_CLIENT_ID' } },
551
+ });
447
552
  ```
448
553
 
449
554
  ## Examples
@@ -505,6 +610,21 @@ import type {
505
610
  AuthState,
506
611
  AuthProvider,
507
612
  AuthCredential,
613
+ AuthManagerConfig, // providers is Record<string, ProviderOptions> as of 2.2.0
614
+ ProviderOptions,
615
+ StorageInterface, // for custom secure-storage adapters
616
+ } from 'capacitor-auth-manager';
617
+
618
+ // Runtime exports include the auth singleton, storage backends, the logger, and helpers:
619
+ import {
620
+ auth,
621
+ WebStorage,
622
+ CapacitorPreferencesStorage,
623
+ defaultLogger,
624
+ AuthError,
625
+ isAuthError,
626
+ AuthProvider as AuthProviderEnum,
627
+ AuthErrorCode,
508
628
  } from 'capacitor-auth-manager';
509
629
  ```
510
630
 
@@ -517,13 +637,13 @@ import type {
517
637
 
518
638
  ### iOS
519
639
 
520
- - Requires Capacitor for native functionality
640
+ - Requires Capacitor (`@capacitor/core` `^7` or `^8`) for native functionality; deployment target 14
521
641
  - Biometric auth requires Face ID/Touch ID capability
522
642
  - Some providers need URL schemes configuration
523
643
 
524
644
  ### Android
525
645
 
526
- - Requires Capacitor for native functionality
646
+ - Requires Capacitor (`@capacitor/core` `^7` or `^8`) for native functionality
527
647
  - Biometric auth requires fingerprint hardware
528
648
  - Configure `AndroidManifest.xml` for OAuth redirects
529
649
 
@@ -121,4 +121,32 @@ public class AuthStorage {
121
121
  }
122
122
  return null;
123
123
  }
124
+
125
+ // Credential storage methods
126
+
127
+ public void saveCredential(String provider, JSObject credential) {
128
+ if (credential != null) {
129
+ set("credential_" + provider, credential.toString());
130
+ }
131
+ }
132
+
133
+ public JSObject getCredential(String provider) {
134
+ String jsonString = get("credential_" + provider);
135
+ if (jsonString != null) {
136
+ try {
137
+ return JSObject.fromJSONObject(new JSONObject(jsonString));
138
+ } catch (JSONException e) {
139
+ return null;
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+
145
+ public void deleteCredential(String provider) {
146
+ remove("credential_" + provider);
147
+ }
148
+
149
+ public boolean hasCredential(String provider) {
150
+ return getCredential(provider) != null;
151
+ }
124
152
  }