capacitor-auth-manager 1.1.0 → 2.1.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/Readme.md +385 -640
- package/dist/core.cjs.js +4952 -0
- package/dist/core.cjs.js.map +1 -0
- package/dist/esm/capacitor-plugin.d.ts +3 -0
- package/dist/esm/capacitor-plugin.js +7 -0
- package/dist/esm/capacitor-plugin.js.map +1 -0
- package/dist/esm/core/auth-manager.d.ts +33 -0
- package/dist/esm/core/auth-manager.js +296 -0
- package/dist/esm/core/auth-manager.js.map +1 -0
- package/dist/esm/core/index.d.ts +4 -0
- package/dist/esm/core/index.js +5 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/platform.d.ts +17 -0
- package/dist/esm/core/platform.js +80 -0
- package/dist/esm/core/platform.js.map +1 -0
- package/dist/esm/core/provider-registry.d.ts +21 -0
- package/dist/esm/core/provider-registry.js +605 -0
- package/dist/esm/core/provider-registry.js.map +1 -0
- package/dist/esm/core/types.d.ts +35 -0
- package/dist/esm/core/types.js +2 -0
- package/dist/esm/core/types.js.map +1 -0
- package/dist/esm/definitions.d.ts +40 -5
- package/dist/esm/definitions.js +14 -4
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.js +8 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +3 -1
- package/dist/esm/providers/base-provider.js +8 -5
- package/dist/esm/providers/base-provider.js.map +1 -1
- package/dist/esm/providers/oauth-provider.js +18 -16
- package/dist/esm/providers/oauth-provider.js.map +1 -1
- package/dist/esm/providers/provider-factory.js +1 -1
- package/dist/esm/providers/provider-factory.js.map +1 -1
- package/dist/esm/providers/web/apple-provider.js +27 -19
- package/dist/esm/providers/web/apple-provider.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +47 -0
- package/dist/esm/providers/web/biometric-provider.js +267 -0
- package/dist/esm/providers/web/biometric-provider.js.map +1 -0
- package/dist/esm/providers/web/email-password-provider.d.ts +55 -0
- package/dist/esm/providers/web/email-password-provider.js +429 -0
- package/dist/esm/providers/web/email-password-provider.js.map +1 -0
- package/dist/esm/providers/web/facebook-provider.d.ts +29 -0
- package/dist/esm/providers/web/facebook-provider.js +249 -0
- package/dist/esm/providers/web/facebook-provider.js.map +1 -0
- package/dist/esm/providers/web/firebase-provider.d.ts +20 -0
- package/dist/esm/providers/web/firebase-provider.js +306 -0
- package/dist/esm/providers/web/firebase-provider.js.map +1 -0
- package/dist/esm/providers/web/github-provider.d.ts +25 -0
- package/dist/esm/providers/web/github-provider.js +248 -0
- package/dist/esm/providers/web/github-provider.js.map +1 -0
- package/dist/esm/providers/web/google-provider.js +18 -14
- package/dist/esm/providers/web/google-provider.js.map +1 -1
- package/dist/esm/providers/web/index.d.ts +13 -0
- package/dist/esm/providers/web/index.js +15 -0
- package/dist/esm/providers/web/index.js.map +1 -0
- package/dist/esm/providers/web/linkedin-provider.d.ts +38 -0
- package/dist/esm/providers/web/linkedin-provider.js +152 -0
- package/dist/esm/providers/web/linkedin-provider.js.map +1 -0
- package/dist/esm/providers/web/magic-link-provider.d.ts +46 -0
- package/dist/esm/providers/web/magic-link-provider.js +298 -0
- package/dist/esm/providers/web/magic-link-provider.js.map +1 -0
- package/dist/esm/providers/web/microsoft-provider.d.ts +21 -0
- package/dist/esm/providers/web/microsoft-provider.js +211 -0
- package/dist/esm/providers/web/microsoft-provider.js.map +1 -0
- package/dist/esm/providers/web/slack-provider.d.ts +40 -0
- package/dist/esm/providers/web/slack-provider.js +151 -0
- package/dist/esm/providers/web/slack-provider.js.map +1 -0
- package/dist/esm/providers/web/sms-provider.d.ts +48 -0
- package/dist/esm/providers/web/sms-provider.js +301 -0
- package/dist/esm/providers/web/sms-provider.js.map +1 -0
- package/dist/esm/providers/web/username-password-provider.d.ts +62 -0
- package/dist/esm/providers/web/username-password-provider.js +432 -0
- package/dist/esm/providers/web/username-password-provider.js.map +1 -0
- package/dist/esm/utils/auth-error.js +7 -5
- package/dist/esm/utils/auth-error.js.map +1 -1
- package/dist/esm/utils/event-emitter.js +1 -1
- package/dist/esm/utils/event-emitter.js.map +1 -1
- package/dist/esm/utils/storage.d.ts +4 -4
- package/dist/esm/utils/storage.js +13 -3
- package/dist/esm/utils/storage.js.map +1 -1
- package/dist/esm/web.js +7 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +4093 -354
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +4093 -354
- package/dist/plugin.js.map +1 -1
- package/package.json +75 -14
- package/scripts/configure.js +105 -61
package/Readme.md
CHANGED
|
@@ -1,797 +1,542 @@
|
|
|
1
1
|
# Capacitor Auth Manager
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- [GitHub Auth](./docs/providers/github.md)
|
|
15
|
-
- [And more...](./docs/providers/)
|
|
16
|
-
- [**API Reference**](./docs/api/) - Complete API documentation
|
|
17
|
-
- [**Examples**](./docs/examples/) - Sample implementations and use cases
|
|
18
|
-
- [**Migration Guide**](./docs/migration.md) - Upgrading from previous versions
|
|
19
|
-
- [**Troubleshooting**](./docs/troubleshooting.md) - Common issues and solutions
|
|
3
|
+
Universal authentication manager with 13+ providers. Framework-agnostic, works with React, Vue, Angular, and vanilla JS. Optional Capacitor support for mobile apps.
|
|
4
|
+
|
|
5
|
+
## 🚀 v2.0 - Complete Rewrite!
|
|
6
|
+
|
|
7
|
+
Version 2.0 is a complete rewrite focusing on developer experience, smaller bundle sizes, and flexibility:
|
|
8
|
+
|
|
9
|
+
- **No Provider Wrappers** - Works like Zustand, no context providers needed
|
|
10
|
+
- **Framework Agnostic** - One package for React, Vue, Angular, and vanilla JS
|
|
11
|
+
- **Optional Capacitor** - Use in regular web apps without Capacitor
|
|
12
|
+
- **Dynamic Loading** - Providers load only when used (better tree-shaking)
|
|
13
|
+
- **All 13 Providers Implemented** - Every promised provider is now available
|
|
20
14
|
|
|
21
15
|
## Features
|
|
22
16
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
17
|
+
- 🚀 **Zero Configuration** - Works out of the box with sensible defaults
|
|
18
|
+
- 🎯 **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
|
|
21
|
+
- 🔄 **Provider-less Design** - No context providers required (like Zustand)
|
|
22
|
+
- 📱 **Optional Capacitor** - Works in web apps without Capacitor
|
|
23
|
+
- 🎨 **TypeScript First** - Full type safety and IntelliSense
|
|
24
|
+
- 🔐 **Secure by Default** - Follows security best practices
|
|
25
|
+
- ⚡ **Dynamic Loading** - Providers load only when used
|
|
31
26
|
|
|
32
|
-
##
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
33
30
|
|
|
34
31
|
```bash
|
|
35
32
|
npm install capacitor-auth-manager
|
|
36
|
-
|
|
33
|
+
# or
|
|
34
|
+
yarn add capacitor-auth-manager
|
|
37
35
|
```
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
### Basic Usage (Vanilla JavaScript)
|
|
40
38
|
|
|
41
|
-
```
|
|
42
|
-
import {
|
|
39
|
+
```javascript
|
|
40
|
+
import { auth } from 'capacitor-auth-manager';
|
|
43
41
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
providers:
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
options: {
|
|
50
|
-
clientId: 'YOUR_GOOGLE_CLIENT_ID',
|
|
51
|
-
scopes: ['email', 'profile']
|
|
52
|
-
}
|
|
42
|
+
// Configure providers
|
|
43
|
+
auth.configure({
|
|
44
|
+
providers: {
|
|
45
|
+
google: {
|
|
46
|
+
clientId: 'YOUR_GOOGLE_CLIENT_ID',
|
|
53
47
|
},
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
persistence: 'local', // 'local' | 'session' | 'none'
|
|
63
|
-
autoRefreshToken: true,
|
|
64
|
-
enableLogging: true
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Sign in with Google
|
|
68
|
-
const result = await CapacitorAuthManager.signIn({
|
|
69
|
-
provider: AuthProvider.GOOGLE
|
|
48
|
+
apple: {
|
|
49
|
+
clientId: 'YOUR_APPLE_CLIENT_ID',
|
|
50
|
+
redirectUri: 'YOUR_REDIRECT_URI',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
70
53
|
});
|
|
71
54
|
|
|
72
|
-
|
|
55
|
+
// Sign in
|
|
56
|
+
const result = await auth.signIn('google');
|
|
57
|
+
console.log('Welcome', result.user.displayName);
|
|
73
58
|
|
|
74
59
|
// Listen to auth state changes
|
|
75
|
-
|
|
76
|
-
console.log('
|
|
60
|
+
auth.onAuthStateChange((state) => {
|
|
61
|
+
console.log('User:', state.user);
|
|
62
|
+
console.log('Authenticated:', state.isAuthenticated);
|
|
77
63
|
});
|
|
78
64
|
|
|
79
65
|
// Sign out
|
|
80
|
-
await
|
|
66
|
+
await auth.signOut();
|
|
81
67
|
```
|
|
82
68
|
|
|
83
|
-
|
|
69
|
+
### React Usage
|
|
84
70
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
- Sign in with Apple (if using Apple Auth)
|
|
91
|
-
- Keychain Sharing (for secure credential storage)
|
|
92
|
-
|
|
93
|
-
2. Update your `Info.plist`:
|
|
94
|
-
```xml
|
|
95
|
-
<!-- For Google Sign-In -->
|
|
96
|
-
<key>CFBundleURLTypes</key>
|
|
97
|
-
<array>
|
|
98
|
-
<dict>
|
|
99
|
-
<key>CFBundleURLSchemes</key>
|
|
100
|
-
<array>
|
|
101
|
-
<string>YOUR_REVERSED_CLIENT_ID</string>
|
|
102
|
-
</array>
|
|
103
|
-
</dict>
|
|
104
|
-
</array>
|
|
105
|
-
|
|
106
|
-
<!-- For Facebook Login -->
|
|
107
|
-
<key>FacebookAppID</key>
|
|
108
|
-
<string>YOUR_FACEBOOK_APP_ID</string>
|
|
109
|
-
<key>FacebookClientToken</key>
|
|
110
|
-
<string>YOUR_FACEBOOK_CLIENT_TOKEN</string>
|
|
111
|
-
<key>FacebookDisplayName</key>
|
|
112
|
-
<string>YOUR_APP_NAME</string>
|
|
113
|
-
|
|
114
|
-
<!-- For OAuth redirects -->
|
|
115
|
-
<key>LSApplicationQueriesSchemes</key>
|
|
116
|
-
<array>
|
|
117
|
-
<string>fbapi</string>
|
|
118
|
-
<string>fb-messenger-share-api</string>
|
|
119
|
-
<string>fbauth2</string>
|
|
120
|
-
<string>fbshareextension</string>
|
|
121
|
-
</array>
|
|
122
|
-
```
|
|
71
|
+
```tsx
|
|
72
|
+
import { useAuth } from 'capacitor-auth-manager/react';
|
|
73
|
+
|
|
74
|
+
function LoginButton() {
|
|
75
|
+
const { user, signIn, signOut, isLoading } = useAuth();
|
|
123
76
|
|
|
124
|
-
|
|
77
|
+
if (isLoading) return <div>Loading...</div>;
|
|
125
78
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
79
|
+
if (user) {
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<p>Welcome, {user.displayName}!</p>
|
|
83
|
+
<button onClick={() => signOut()}>Sign Out</button>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
133
86
|
}
|
|
87
|
+
|
|
88
|
+
return <button onClick={() => signIn('google')}>Sign In with Google</button>;
|
|
134
89
|
}
|
|
135
90
|
```
|
|
136
91
|
|
|
137
|
-
|
|
138
|
-
```xml
|
|
139
|
-
<!-- For Google Sign-In -->
|
|
140
|
-
<meta-data
|
|
141
|
-
android:name="com.google.android.gms.auth.api.signin.GoogleSignInOptions"
|
|
142
|
-
android:value="@string/default_web_client_id" />
|
|
143
|
-
|
|
144
|
-
<!-- For Facebook Login -->
|
|
145
|
-
<meta-data
|
|
146
|
-
android:name="com.facebook.sdk.ApplicationId"
|
|
147
|
-
android:value="@string/facebook_app_id"/>
|
|
148
|
-
<meta-data
|
|
149
|
-
android:name="com.facebook.sdk.ClientToken"
|
|
150
|
-
android:value="@string/facebook_client_token"/>
|
|
151
|
-
```
|
|
92
|
+
No providers or context wrappers needed! Just import and use.
|
|
152
93
|
|
|
153
|
-
|
|
94
|
+
### Vue 3 Usage
|
|
154
95
|
|
|
155
|
-
|
|
96
|
+
```vue
|
|
97
|
+
<script setup>
|
|
98
|
+
import { useAuth } from 'capacitor-auth-manager/vue';
|
|
156
99
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
- **Facebook**: Add your domain to valid OAuth redirect URIs
|
|
160
|
-
- **Microsoft**: Configure redirect URIs in Azure AD
|
|
100
|
+
const { user, signIn, signOut, isLoading } = useAuth();
|
|
101
|
+
</script>
|
|
161
102
|
|
|
162
|
-
|
|
103
|
+
<template>
|
|
104
|
+
<div v-if="isLoading">Loading...</div>
|
|
105
|
+
<div v-else-if="user">
|
|
106
|
+
<p>Welcome, {{ user.displayName }}!</p>
|
|
107
|
+
<button @click="signOut">Sign Out</button>
|
|
108
|
+
</div>
|
|
109
|
+
<button
|
|
110
|
+
v-else
|
|
111
|
+
@click="signIn('google')"
|
|
112
|
+
>
|
|
113
|
+
Sign In with Google
|
|
114
|
+
</button>
|
|
115
|
+
</template>
|
|
116
|
+
```
|
|
163
117
|
|
|
164
|
-
###
|
|
118
|
+
### Angular Usage
|
|
165
119
|
|
|
166
120
|
```typescript
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
121
|
+
import { Component } from '@angular/core';
|
|
122
|
+
import { AuthService } from 'capacitor-auth-manager/angular';
|
|
123
|
+
|
|
124
|
+
@Component({
|
|
125
|
+
selector: 'app-login',
|
|
126
|
+
template: `
|
|
127
|
+
<div *ngIf="authService.isLoading$ | async">Loading...</div>
|
|
128
|
+
<div *ngIf="authService.user$ | async as user">
|
|
129
|
+
<p>Welcome, {{ user.displayName }}!</p>
|
|
130
|
+
<button (click)="signOut()">Sign Out</button>
|
|
131
|
+
</div>
|
|
132
|
+
<button
|
|
133
|
+
*ngIf="!(authService.user$ | async)"
|
|
134
|
+
(click)="signIn('google')"
|
|
135
|
+
>
|
|
136
|
+
Sign In with Google
|
|
137
|
+
</button>
|
|
138
|
+
`,
|
|
139
|
+
})
|
|
140
|
+
export class LoginComponent {
|
|
141
|
+
constructor(public authService: AuthService) {}
|
|
142
|
+
|
|
143
|
+
signIn(provider: string) {
|
|
144
|
+
this.authService.signIn(provider).subscribe();
|
|
145
|
+
}
|
|
180
146
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
options: {
|
|
184
|
-
loginHint: 'user@example.com', // Pre-fill email
|
|
185
|
-
prompt: 'select_account' // Force account selection
|
|
147
|
+
signOut() {
|
|
148
|
+
this.authService.signOut().subscribe();
|
|
186
149
|
}
|
|
187
|
-
}
|
|
150
|
+
}
|
|
188
151
|
```
|
|
189
152
|
|
|
190
|
-
|
|
153
|
+
## Supported Providers
|
|
154
|
+
|
|
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 |
|
|
170
|
+
|
|
171
|
+
## Configuration
|
|
172
|
+
|
|
173
|
+
### Complete Configuration Example
|
|
191
174
|
|
|
192
175
|
```typescript
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
176
|
+
import { auth } from 'capacitor-auth-manager';
|
|
177
|
+
|
|
178
|
+
auth.configure({
|
|
179
|
+
// Provider configurations
|
|
180
|
+
providers: {
|
|
181
|
+
google: {
|
|
182
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
183
|
+
scopes: ['email', 'profile'],
|
|
184
|
+
},
|
|
185
|
+
apple: {
|
|
197
186
|
clientId: 'YOUR_SERVICE_ID',
|
|
198
|
-
redirectUri: 'https://
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
187
|
+
redirectUri: 'https://your-app.com/auth/callback',
|
|
188
|
+
},
|
|
189
|
+
microsoft: {
|
|
190
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
191
|
+
authority: 'https://login.microsoftonline.com/common',
|
|
192
|
+
},
|
|
193
|
+
facebook: {
|
|
194
|
+
appId: 'YOUR_APP_ID',
|
|
195
|
+
version: 'v18.0',
|
|
196
|
+
},
|
|
197
|
+
github: {
|
|
198
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
199
|
+
redirectUri: 'YOUR_REDIRECT_URI',
|
|
200
|
+
},
|
|
201
|
+
firebase: {
|
|
202
|
+
apiKey: 'YOUR_API_KEY',
|
|
203
|
+
authDomain: 'YOUR_AUTH_DOMAIN',
|
|
204
|
+
projectId: 'YOUR_PROJECT_ID',
|
|
205
|
+
},
|
|
206
|
+
'magic-link': {
|
|
207
|
+
sendLinkUrl: 'https://your-api.com/send-magic-link',
|
|
208
|
+
verifyUrl: 'https://your-api.com/verify-magic-link',
|
|
209
|
+
},
|
|
210
|
+
sms: {
|
|
211
|
+
sendCodeUrl: 'https://your-api.com/sms/send',
|
|
212
|
+
verifyCodeUrl: 'https://your-api.com/sms/verify',
|
|
213
|
+
},
|
|
214
|
+
'email-password': {
|
|
215
|
+
apiUrl: 'https://your-api.com',
|
|
216
|
+
passwordRequirements: {
|
|
217
|
+
minLength: 8,
|
|
218
|
+
requireUppercase: true,
|
|
219
|
+
requireNumbers: true,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
biometric: {
|
|
223
|
+
reason: 'Authenticate to access your account',
|
|
224
|
+
title: 'Authentication Required',
|
|
225
|
+
},
|
|
226
|
+
slack: {
|
|
227
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
228
|
+
redirectUri: 'https://your-app.com/auth/slack/callback',
|
|
229
|
+
teamId: 'OPTIONAL_TEAM_ID', // Restrict to specific workspace
|
|
230
|
+
},
|
|
231
|
+
linkedin: {
|
|
232
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
233
|
+
redirectUri: 'https://your-app.com/auth/linkedin/callback',
|
|
234
|
+
},
|
|
235
|
+
'username-password': {
|
|
236
|
+
apiUrl: 'https://your-api.com',
|
|
237
|
+
usernameRequirements: {
|
|
238
|
+
minLength: 3,
|
|
239
|
+
maxLength: 20,
|
|
240
|
+
},
|
|
241
|
+
allowSignUp: true,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
206
244
|
|
|
207
|
-
|
|
208
|
-
|
|
245
|
+
// Global options
|
|
246
|
+
persistence: 'local', // 'local' | 'session' | 'memory'
|
|
247
|
+
autoRefreshToken: true,
|
|
248
|
+
tokenRefreshBuffer: 300000, // 5 minutes before expiry
|
|
249
|
+
enableLogging: true,
|
|
250
|
+
logLevel: 'debug', // 'debug' | 'info' | 'warn' | 'error'
|
|
209
251
|
});
|
|
210
252
|
```
|
|
211
253
|
|
|
212
|
-
###
|
|
254
|
+
### Provider-Specific Setup
|
|
213
255
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
256
|
+
Each provider may require additional setup. The package provides helpful error messages when dependencies are missing.
|
|
257
|
+
|
|
258
|
+
## Framework-Specific APIs
|
|
259
|
+
|
|
260
|
+
### React Hooks
|
|
261
|
+
|
|
262
|
+
- `useAuth()` - Complete authentication functionality
|
|
263
|
+
- `useAuthState()` - Read-only authentication state
|
|
264
|
+
- `useUser()` - Just the current user
|
|
265
|
+
- `useToken()` - Access token management
|
|
266
|
+
- `useIsAuthenticated()` - Boolean authentication status
|
|
267
|
+
|
|
268
|
+
### Vue 3 Composables
|
|
269
|
+
|
|
270
|
+
- `useAuth()` - Complete authentication functionality with reactive refs
|
|
271
|
+
- `useAuthState()` - Reactive auth state
|
|
272
|
+
- `useUser()` - Reactive user ref
|
|
273
|
+
- `useToken()` - Reactive token management
|
|
228
274
|
|
|
229
|
-
###
|
|
275
|
+
### Angular Service
|
|
230
276
|
|
|
231
277
|
```typescript
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}]
|
|
244
|
-
});
|
|
278
|
+
import { AuthModule } from 'capacitor-auth-manager/angular';
|
|
279
|
+
|
|
280
|
+
// In your app module
|
|
281
|
+
imports: [
|
|
282
|
+
AuthModule.forRoot({
|
|
283
|
+
providers: {
|
|
284
|
+
/* ... */
|
|
285
|
+
},
|
|
286
|
+
}),
|
|
287
|
+
];
|
|
245
288
|
```
|
|
246
289
|
|
|
247
|
-
|
|
290
|
+
## Advanced Usage
|
|
248
291
|
|
|
249
|
-
|
|
250
|
-
await CapacitorAuthManager.initialize({
|
|
251
|
-
providers: [{
|
|
252
|
-
provider: AuthProvider.EMAIL_PASSWORD,
|
|
253
|
-
options: {
|
|
254
|
-
strengthRequirements: {
|
|
255
|
-
minLength: 8,
|
|
256
|
-
requireUppercase: true,
|
|
257
|
-
requireNumbers: true,
|
|
258
|
-
requireSpecialCharacters: true
|
|
259
|
-
},
|
|
260
|
-
allowPasswordReset: true,
|
|
261
|
-
requireEmailVerification: true
|
|
262
|
-
}
|
|
263
|
-
}]
|
|
264
|
-
});
|
|
292
|
+
### Email Magic Link
|
|
265
293
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
credentials: {
|
|
270
|
-
email: 'user@example.com',
|
|
271
|
-
password: 'SecurePassword123!'
|
|
272
|
-
}
|
|
273
|
-
});
|
|
294
|
+
```typescript
|
|
295
|
+
// Send magic link
|
|
296
|
+
await auth.signIn('magic-link', { email: 'user@example.com' });
|
|
274
297
|
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
email: 'user@example.com'
|
|
278
|
-
});
|
|
298
|
+
// The user will receive an email with a link
|
|
299
|
+
// When they click it, your app handles the callback
|
|
279
300
|
```
|
|
280
301
|
|
|
281
302
|
### SMS Authentication
|
|
282
303
|
|
|
283
304
|
```typescript
|
|
284
|
-
await CapacitorAuthManager.initialize({
|
|
285
|
-
providers: [{
|
|
286
|
-
provider: AuthProvider.SMS,
|
|
287
|
-
options: {
|
|
288
|
-
provider: 'twilio', // or 'firebase', 'custom'
|
|
289
|
-
twilioConfig: {
|
|
290
|
-
accountSid: 'YOUR_ACCOUNT_SID',
|
|
291
|
-
authToken: 'YOUR_AUTH_TOKEN',
|
|
292
|
-
fromNumber: '+1234567890'
|
|
293
|
-
},
|
|
294
|
-
codeLength: 6,
|
|
295
|
-
codeExpiration: 300000, // 5 minutes
|
|
296
|
-
maxAttempts: 3
|
|
297
|
-
}
|
|
298
|
-
}]
|
|
299
|
-
});
|
|
300
|
-
|
|
301
305
|
// Send SMS code
|
|
302
|
-
await
|
|
303
|
-
phoneNumber: '+1234567890'
|
|
304
|
-
});
|
|
306
|
+
const result = await auth.signIn('sms', { phoneNumber: '+1234567890' });
|
|
305
307
|
|
|
306
308
|
// Verify SMS code
|
|
307
|
-
|
|
309
|
+
await auth.signIn('sms', {
|
|
308
310
|
phoneNumber: '+1234567890',
|
|
309
|
-
code: '123456'
|
|
311
|
+
code: '123456',
|
|
310
312
|
});
|
|
311
313
|
```
|
|
312
314
|
|
|
313
|
-
###
|
|
314
|
-
|
|
315
|
-
Note: For biometric authentication, this plugin integrates with [capacitor-biometric-authentication](https://www.npmjs.com/package/capacitor-biometric-authentication).
|
|
315
|
+
### Email/Password
|
|
316
316
|
|
|
317
317
|
```typescript
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
title: 'Authenticate',
|
|
324
|
-
subtitle: 'Use your biometric to sign in',
|
|
325
|
-
description: 'Place your finger on the sensor',
|
|
326
|
-
negativeButtonText: 'Cancel',
|
|
327
|
-
maxAttempts: 3
|
|
328
|
-
}
|
|
329
|
-
}]
|
|
318
|
+
// Sign up
|
|
319
|
+
await auth.signUp({
|
|
320
|
+
email: 'user@example.com',
|
|
321
|
+
password: 'secure-password',
|
|
322
|
+
displayName: 'John Doe',
|
|
330
323
|
});
|
|
331
324
|
|
|
332
|
-
|
|
333
|
-
|
|
325
|
+
// Sign in
|
|
326
|
+
await auth.signIn('email-password', {
|
|
327
|
+
email: 'user@example.com',
|
|
328
|
+
password: 'secure-password',
|
|
334
329
|
});
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
## API Reference
|
|
338
330
|
|
|
339
|
-
|
|
331
|
+
// Update password
|
|
332
|
+
const provider = await auth.getProvider('email-password');
|
|
333
|
+
await provider.updatePassword('oldPassword', 'newPassword');
|
|
340
334
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
interface AuthManagerInitOptions {
|
|
346
|
-
providers: AuthProviderConfig[];
|
|
347
|
-
persistence?: 'local' | 'session' | 'none';
|
|
348
|
-
autoRefreshToken?: boolean;
|
|
349
|
-
tokenRefreshBuffer?: number; // ms before token expiry
|
|
350
|
-
enableLogging?: boolean;
|
|
351
|
-
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
352
|
-
}
|
|
335
|
+
// Send password reset
|
|
336
|
+
await provider.sendPasswordResetEmail('user@example.com');
|
|
353
337
|
```
|
|
354
338
|
|
|
355
|
-
|
|
356
|
-
Signs in a user with the specified provider.
|
|
339
|
+
### Biometric Authentication
|
|
357
340
|
|
|
358
341
|
```typescript
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
options?: SignInProviderOptions;
|
|
363
|
-
}
|
|
364
|
-
```
|
|
342
|
+
// Check availability
|
|
343
|
+
const biometric = await auth.getProvider('biometric');
|
|
344
|
+
const { available, biometryType } = await biometric.isAvailable();
|
|
365
345
|
|
|
366
|
-
|
|
367
|
-
|
|
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);
|
|
368
350
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
provider?: AuthProvider;
|
|
372
|
-
revokeToken?: boolean;
|
|
373
|
-
clearCache?: boolean;
|
|
374
|
-
redirectUrl?: string;
|
|
351
|
+
// Later: authenticate with biometrics
|
|
352
|
+
await auth.signIn('biometric');
|
|
375
353
|
}
|
|
376
354
|
```
|
|
377
355
|
|
|
378
|
-
|
|
379
|
-
Returns the currently authenticated user.
|
|
356
|
+
### Username/Password Authentication
|
|
380
357
|
|
|
381
358
|
```typescript
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
+
});
|
|
387
366
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
} else {
|
|
393
|
-
console.log('User signed out');
|
|
394
|
-
}
|
|
367
|
+
// Sign in
|
|
368
|
+
await auth.signIn('username-password', {
|
|
369
|
+
username: 'johndoe',
|
|
370
|
+
password: 'secure-password',
|
|
395
371
|
});
|
|
396
372
|
|
|
397
|
-
//
|
|
398
|
-
await
|
|
373
|
+
// Check username availability
|
|
374
|
+
const provider = await auth.getProvider('username-password');
|
|
375
|
+
const isAvailable = await provider.checkUsernameAvailability('johndoe');
|
|
399
376
|
```
|
|
400
377
|
|
|
401
|
-
|
|
402
|
-
Manually refreshes the authentication token.
|
|
378
|
+
### Slack Authentication
|
|
403
379
|
|
|
404
380
|
```typescript
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
381
|
+
// Sign in with Slack
|
|
382
|
+
await auth.signIn('slack');
|
|
383
|
+
|
|
384
|
+
// Restrict to specific workspace
|
|
385
|
+
auth.configure({
|
|
386
|
+
providers: {
|
|
387
|
+
slack: {
|
|
388
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
389
|
+
redirectUri: 'YOUR_REDIRECT_URI',
|
|
390
|
+
teamId: 'SPECIFIC_TEAM_ID', // Optional
|
|
391
|
+
},
|
|
392
|
+
},
|
|
408
393
|
});
|
|
409
394
|
```
|
|
410
395
|
|
|
411
|
-
###
|
|
412
|
-
|
|
413
|
-
#### linkAccount(options)
|
|
414
|
-
Links an additional authentication provider to the current user.
|
|
396
|
+
### LinkedIn Authentication
|
|
415
397
|
|
|
416
398
|
```typescript
|
|
417
|
-
|
|
418
|
-
|
|
399
|
+
// Sign in with LinkedIn
|
|
400
|
+
await auth.signIn('linkedin');
|
|
401
|
+
|
|
402
|
+
// Configure with scopes
|
|
403
|
+
auth.configure({
|
|
404
|
+
providers: {
|
|
405
|
+
linkedin: {
|
|
406
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
407
|
+
redirectUri: 'YOUR_REDIRECT_URI',
|
|
408
|
+
scopes: ['openid', 'profile', 'email'],
|
|
409
|
+
},
|
|
410
|
+
},
|
|
419
411
|
});
|
|
420
412
|
```
|
|
421
413
|
|
|
422
|
-
|
|
423
|
-
Unlinks an authentication provider from the current user.
|
|
414
|
+
### Multiple Sign-In Options
|
|
424
415
|
|
|
425
416
|
```typescript
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
});
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
#### updateProfile(options)
|
|
432
|
-
Updates the user's profile information.
|
|
417
|
+
// Simple provider name
|
|
418
|
+
await auth.signIn('google');
|
|
433
419
|
|
|
434
|
-
|
|
435
|
-
await
|
|
436
|
-
|
|
437
|
-
photoURL: 'https://example.com/photo.jpg'
|
|
420
|
+
// With scopes
|
|
421
|
+
await auth.signIn('google', {
|
|
422
|
+
scopes: ['https://www.googleapis.com/auth/calendar'],
|
|
438
423
|
});
|
|
439
|
-
```
|
|
440
424
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
```typescript
|
|
445
|
-
await CapacitorAuthManager.deleteAccount({
|
|
446
|
-
requireReauthentication: true
|
|
425
|
+
// With login hint
|
|
426
|
+
await auth.signIn('google', {
|
|
427
|
+
loginHint: 'user@example.com',
|
|
447
428
|
});
|
|
448
429
|
```
|
|
449
430
|
|
|
450
|
-
###
|
|
451
|
-
|
|
452
|
-
#### isSupported(options)
|
|
453
|
-
Checks if a provider is supported on the current platform.
|
|
431
|
+
### Token Management
|
|
454
432
|
|
|
455
433
|
```typescript
|
|
456
|
-
|
|
457
|
-
|
|
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
|
+
}
|
|
458
439
|
});
|
|
459
440
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
#### getIdToken(options?)
|
|
466
|
-
Gets the current ID token for the authenticated user.
|
|
441
|
+
// Manual token refresh
|
|
442
|
+
await auth.refreshToken();
|
|
467
443
|
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
});
|
|
444
|
+
// Get current token
|
|
445
|
+
const state = auth.getAuthState();
|
|
446
|
+
const token = state.credential?.accessToken;
|
|
472
447
|
```
|
|
473
448
|
|
|
474
|
-
##
|
|
449
|
+
## Examples
|
|
475
450
|
|
|
476
|
-
|
|
451
|
+
Check out the [examples](./examples) directory for complete applications:
|
|
477
452
|
|
|
478
|
-
|
|
453
|
+
- [Vanilla JavaScript](./examples/vanilla-js) - Pure JS implementation
|
|
454
|
+
- [React Example](./examples/react) - React 18+ with TypeScript
|
|
455
|
+
- [Vue 3 Example](./examples/vue) - Vue 3 Composition API
|
|
456
|
+
- [Angular Example](./examples/angular) - Angular 16+ with standalone components
|
|
479
457
|
|
|
480
|
-
|
|
481
|
-
interface AuthManagerInitOptions {
|
|
482
|
-
providers: AuthProviderConfig[]; // Required: Array of provider configurations
|
|
483
|
-
persistence?: AuthPersistence; // 'local' | 'session' | 'none' (default: 'local')
|
|
484
|
-
autoRefreshToken?: boolean; // Auto-refresh tokens before expiry (default: true)
|
|
485
|
-
tokenRefreshBuffer?: number; // Ms before expiry to refresh (default: 300000 - 5 min)
|
|
486
|
-
enableLogging?: boolean; // Enable debug logging (default: false)
|
|
487
|
-
logLevel?: LogLevel; // 'debug' | 'info' | 'warn' | 'error' (default: 'info')
|
|
488
|
-
}
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
### Provider-Specific Options
|
|
458
|
+
## Migration from v1.x
|
|
492
459
|
|
|
493
|
-
|
|
460
|
+
### Before (v1.x)
|
|
494
461
|
|
|
495
|
-
#### Google Auth Options
|
|
496
462
|
```typescript
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
serverClientId?: string; // Android: Server client ID for offline access
|
|
500
|
-
scopes?: string[]; // OAuth scopes (default: ['openid', 'email', 'profile'])
|
|
501
|
-
offlineAccess?: boolean; // Request refresh token (default: false)
|
|
502
|
-
hostedDomain?: string; // Restrict to G Suite domain
|
|
503
|
-
forceCodeForRefreshToken?: boolean; // Force auth code flow (default: false)
|
|
504
|
-
}
|
|
505
|
-
```
|
|
463
|
+
// Required Capacitor
|
|
464
|
+
import { CapacitorAuthManager } from 'capacitor-auth-manager';
|
|
506
465
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
scopes?: AppleAuthScope[]; // [EMAIL, NAME] (default: [])
|
|
513
|
-
usePopup?: boolean; // Use popup instead of redirect (default: true)
|
|
514
|
-
state?: string; // OAuth state parameter
|
|
515
|
-
nonce?: string; // OAuth nonce for security
|
|
516
|
-
}
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
#### Microsoft Auth Options
|
|
520
|
-
```typescript
|
|
521
|
-
interface MicrosoftAuthOptions {
|
|
522
|
-
clientId: string; // Required: Your Azure AD Client ID
|
|
523
|
-
redirectUri?: string; // Redirect URI (default: current URL)
|
|
524
|
-
scopes?: string[]; // OAuth scopes
|
|
525
|
-
tenantId?: string; // Azure AD tenant ID
|
|
526
|
-
prompt?: string; // 'login' | 'consent' | 'select_account'
|
|
527
|
-
loginHint?: string; // Pre-fill email
|
|
528
|
-
domainHint?: string; // 'consumers' | 'organizations'
|
|
529
|
-
responseType?: string; // OAuth response type
|
|
530
|
-
responseMode?: string; // 'query' | 'fragment'
|
|
531
|
-
codeChallenge?: string; // PKCE code challenge
|
|
532
|
-
codeChallengeMethod?: string; // PKCE method
|
|
533
|
-
state?: string; // OAuth state
|
|
534
|
-
nonce?: string; // OAuth nonce
|
|
535
|
-
}
|
|
536
|
-
```
|
|
466
|
+
await CapacitorAuthManager.initialize({
|
|
467
|
+
providers: [
|
|
468
|
+
/* ... */
|
|
469
|
+
],
|
|
470
|
+
});
|
|
537
471
|
|
|
538
|
-
|
|
539
|
-
```typescript
|
|
540
|
-
interface FacebookAuthOptions {
|
|
541
|
-
appId: string; // Required: Your Facebook App ID
|
|
542
|
-
permissions?: string[]; // Facebook permissions
|
|
543
|
-
version?: string; // API version (default: 'v12.0')
|
|
544
|
-
loginBehavior?: string; // iOS: 'browser' | 'native' | 'system'
|
|
545
|
-
limitedLogin?: boolean; // iOS 14.5+: Use limited login
|
|
546
|
-
nonce?: string; // Security nonce
|
|
547
|
-
}
|
|
472
|
+
await CapacitorAuthManager.signIn({ provider: AuthProvider.GOOGLE });
|
|
548
473
|
```
|
|
549
474
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
Additional options available when calling `signIn()`:
|
|
475
|
+
### After (v2.0)
|
|
553
476
|
|
|
554
477
|
```typescript
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
customParameters?: Record<string, string>; // Provider-specific parameters
|
|
558
|
-
loginHint?: string; // Pre-fill username/email
|
|
559
|
-
prompt?: string; // UI behavior
|
|
560
|
-
display?: string; // UI display mode
|
|
561
|
-
accessType?: string; // 'online' | 'offline'
|
|
562
|
-
includeGrantedScopes?: boolean; // Include previously granted scopes
|
|
563
|
-
state?: string; // OAuth state
|
|
564
|
-
nonce?: string; // OAuth nonce
|
|
565
|
-
pkceEnabled?: boolean; // Enable PKCE (default: true where supported)
|
|
566
|
-
}
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
### Complete Example with All Options
|
|
478
|
+
// Works without Capacitor
|
|
479
|
+
import { auth } from 'capacitor-auth-manager';
|
|
570
480
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
// Global options
|
|
574
|
-
persistence: 'local',
|
|
575
|
-
autoRefreshToken: true,
|
|
576
|
-
tokenRefreshBuffer: 300000,
|
|
577
|
-
enableLogging: true,
|
|
578
|
-
logLevel: 'debug',
|
|
579
|
-
|
|
580
|
-
// Provider configurations
|
|
581
|
-
providers: [
|
|
582
|
-
{
|
|
583
|
-
provider: AuthProvider.GOOGLE,
|
|
584
|
-
options: {
|
|
585
|
-
clientId: 'YOUR_GOOGLE_CLIENT_ID',
|
|
586
|
-
serverClientId: 'YOUR_SERVER_CLIENT_ID',
|
|
587
|
-
scopes: ['email', 'profile', 'https://www.googleapis.com/auth/calendar'],
|
|
588
|
-
offlineAccess: true,
|
|
589
|
-
hostedDomain: 'company.com',
|
|
590
|
-
forceCodeForRefreshToken: true
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
provider: AuthProvider.APPLE,
|
|
595
|
-
options: {
|
|
596
|
-
clientId: 'com.company.service',
|
|
597
|
-
redirectUri: 'https://company.com/auth/callback',
|
|
598
|
-
scopes: [AppleAuthScope.EMAIL, AppleAuthScope.NAME],
|
|
599
|
-
usePopup: true,
|
|
600
|
-
state: crypto.randomUUID(),
|
|
601
|
-
nonce: crypto.randomUUID()
|
|
602
|
-
}
|
|
603
|
-
},
|
|
604
|
-
{
|
|
605
|
-
provider: AuthProvider.MICROSOFT,
|
|
606
|
-
options: {
|
|
607
|
-
clientId: 'YOUR_AZURE_CLIENT_ID',
|
|
608
|
-
redirectUri: 'https://company.com/auth/callback',
|
|
609
|
-
scopes: ['openid', 'profile', 'email', 'User.Read'],
|
|
610
|
-
tenantId: 'YOUR_TENANT_ID',
|
|
611
|
-
prompt: 'select_account',
|
|
612
|
-
responseType: 'code',
|
|
613
|
-
responseMode: 'query',
|
|
614
|
-
codeChallenge: 'YOUR_CODE_CHALLENGE',
|
|
615
|
-
codeChallengeMethod: 'S256'
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
]
|
|
481
|
+
auth.configure({
|
|
482
|
+
providers: { google: { clientId: '...' } },
|
|
619
483
|
});
|
|
620
484
|
|
|
621
|
-
|
|
622
|
-
const result = await CapacitorAuthManager.signIn({
|
|
623
|
-
provider: AuthProvider.GOOGLE,
|
|
624
|
-
options: {
|
|
625
|
-
scopes: ['email', 'profile', 'https://www.googleapis.com/auth/drive'],
|
|
626
|
-
loginHint: 'user@company.com',
|
|
627
|
-
prompt: 'consent',
|
|
628
|
-
accessType: 'offline',
|
|
629
|
-
includeGrantedScopes: true,
|
|
630
|
-
customParameters: {
|
|
631
|
-
'approval_prompt': 'force'
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
});
|
|
485
|
+
await auth.signIn('google');
|
|
635
486
|
```
|
|
636
487
|
|
|
637
|
-
##
|
|
488
|
+
## Why v2.0?
|
|
638
489
|
|
|
639
|
-
|
|
490
|
+
1. **No Context Providers** - Works like Zustand, cleaner component trees
|
|
491
|
+
2. **Framework Agnostic** - One package, multiple frameworks
|
|
492
|
+
3. **Better Tree-shaking** - Only pay for what you use
|
|
493
|
+
4. **Optional Capacitor** - Use in any web app
|
|
494
|
+
5. **All Providers Ready** - No more "coming soon"
|
|
640
495
|
|
|
641
|
-
|
|
642
|
-
try {
|
|
643
|
-
await CapacitorAuthManager.signIn({
|
|
644
|
-
provider: AuthProvider.GOOGLE
|
|
645
|
-
});
|
|
646
|
-
} catch (error) {
|
|
647
|
-
switch (error.code) {
|
|
648
|
-
case 'auth/user-cancelled':
|
|
649
|
-
// User cancelled the sign-in flow
|
|
650
|
-
break;
|
|
651
|
-
case 'auth/network-error':
|
|
652
|
-
// Network error occurred
|
|
653
|
-
break;
|
|
654
|
-
case 'auth/invalid-credentials':
|
|
655
|
-
// Invalid credentials provided
|
|
656
|
-
break;
|
|
657
|
-
case 'auth/popup-blocked':
|
|
658
|
-
// Popup was blocked by browser
|
|
659
|
-
break;
|
|
660
|
-
default:
|
|
661
|
-
// Other error
|
|
662
|
-
console.error('Auth error:', error);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
```
|
|
496
|
+
## TypeScript Support
|
|
666
497
|
|
|
667
|
-
|
|
498
|
+
Full TypeScript support with detailed types:
|
|
668
499
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
500
|
+
```typescript
|
|
501
|
+
import type {
|
|
502
|
+
AuthUser,
|
|
503
|
+
AuthResult,
|
|
504
|
+
SignInOptions,
|
|
505
|
+
AuthState,
|
|
506
|
+
AuthProvider,
|
|
507
|
+
AuthCredential,
|
|
508
|
+
} from 'capacitor-auth-manager';
|
|
509
|
+
```
|
|
676
510
|
|
|
677
|
-
|
|
511
|
+
## Platform Notes
|
|
678
512
|
|
|
679
|
-
###
|
|
513
|
+
### Web
|
|
680
514
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
import { getAuth, signInWithPopup, GoogleAuthProvider } from 'firebase/auth';
|
|
684
|
-
const auth = getAuth();
|
|
685
|
-
const provider = new GoogleAuthProvider();
|
|
686
|
-
const result = await signInWithPopup(auth, provider);
|
|
687
|
-
|
|
688
|
-
// After (Capacitor Auth Manager)
|
|
689
|
-
import { CapacitorAuthManager, AuthProvider } from 'capacitor-auth-manager';
|
|
690
|
-
const result = await CapacitorAuthManager.signIn({
|
|
691
|
-
provider: AuthProvider.GOOGLE
|
|
692
|
-
});
|
|
693
|
-
```
|
|
515
|
+
- All providers work without additional setup
|
|
516
|
+
- Some providers (SMS, Magic Link, Email/Password) require backend services
|
|
694
517
|
|
|
695
|
-
###
|
|
518
|
+
### iOS
|
|
696
519
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
await GoogleAuth.initialize();
|
|
701
|
-
const user = await GoogleAuth.signIn();
|
|
520
|
+
- Requires Capacitor for native functionality
|
|
521
|
+
- Biometric auth requires Face ID/Touch ID capability
|
|
522
|
+
- Some providers need URL schemes configuration
|
|
702
523
|
|
|
703
|
-
|
|
704
|
-
import { CapacitorAuthManager, AuthProvider } from 'capacitor-auth-manager';
|
|
705
|
-
await CapacitorAuthManager.initialize({
|
|
706
|
-
providers: [{
|
|
707
|
-
provider: AuthProvider.GOOGLE,
|
|
708
|
-
options: { clientId: 'YOUR_CLIENT_ID' }
|
|
709
|
-
}]
|
|
710
|
-
});
|
|
711
|
-
const result = await CapacitorAuthManager.signIn({
|
|
712
|
-
provider: AuthProvider.GOOGLE
|
|
713
|
-
});
|
|
714
|
-
```
|
|
524
|
+
### Android
|
|
715
525
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
### 🚀 Getting Started
|
|
721
|
-
- [Installation Guide](./docs/getting-started/installation.md) - Step-by-step setup instructions
|
|
722
|
-
- [Quick Start](./docs/getting-started/quick-start.md) - Get up and running in minutes
|
|
723
|
-
- [Platform Setup](./docs/getting-started/platform-setup.md) - Platform-specific configuration
|
|
724
|
-
|
|
725
|
-
### 🔧 API Reference
|
|
726
|
-
- [Core API](./docs/api-reference/core-api.md) - Complete method reference
|
|
727
|
-
- [Authentication State](./docs/api-reference/auth-state.md) - Understanding auth state
|
|
728
|
-
- [Error Handling](./docs/api-reference/error-handling.md) - Handle errors gracefully
|
|
729
|
-
|
|
730
|
-
### 🏢 Provider Guides
|
|
731
|
-
- [Google Auth](./docs/providers/google.md) - Google Sign-In implementation
|
|
732
|
-
- [Apple Auth](./docs/providers/apple.md) - Sign in with Apple
|
|
733
|
-
- [Facebook Auth](./docs/providers/facebook.md) - Facebook Login
|
|
734
|
-
- [Microsoft Auth](./docs/providers/microsoft.md) - Microsoft identity platform
|
|
735
|
-
- [GitHub Auth](./docs/providers/github.md) - GitHub OAuth
|
|
736
|
-
- [Firebase Auth](./docs/providers/firebase.md) - Firebase Authentication
|
|
737
|
-
- [More providers...](./docs/providers/) - All 13+ supported providers
|
|
738
|
-
|
|
739
|
-
### 💡 Framework Examples
|
|
740
|
-
- [React Integration](./docs/examples/react.md) - Complete React implementation
|
|
741
|
-
- [Angular Example](./docs/examples/angular.md) - Angular integration
|
|
742
|
-
- [Vue Example](./docs/examples/vue.md) - Vue.js implementation
|
|
743
|
-
- [Ionic Example](./docs/examples/ionic.md) - Ionic Framework integration
|
|
744
|
-
|
|
745
|
-
### 📖 Advanced Guides
|
|
746
|
-
- [Best Practices](./docs/guides/best-practices.md) - Authentication best practices
|
|
747
|
-
- [Security Guide](./docs/guides/security.md) - Security considerations
|
|
748
|
-
- [Token Management](./docs/guides/token-management.md) - Handling tokens
|
|
749
|
-
- [Multi-Factor Auth](./docs/guides/mfa.md) - Implementing MFA
|
|
750
|
-
|
|
751
|
-
## Platform Compatibility
|
|
752
|
-
|
|
753
|
-
### Supported Platforms
|
|
754
|
-
|
|
755
|
-
| Provider | iOS | Android | Web |
|
|
756
|
-
|----------|-----|---------|-----|
|
|
757
|
-
| Google | ✅ | ✅ | ✅ |
|
|
758
|
-
| Apple | ✅ | ✅ | ✅ |
|
|
759
|
-
| Microsoft | ✅ | ✅ | ✅ |
|
|
760
|
-
| Facebook | ✅ | ✅ | ✅ |
|
|
761
|
-
| GitHub | ✅ | ✅ | ✅ |
|
|
762
|
-
| Slack | ✅ | ✅ | ✅ |
|
|
763
|
-
| LinkedIn | ✅ | ✅ | ✅ |
|
|
764
|
-
| Firebase | ✅ | ✅ | ✅ |
|
|
765
|
-
| Email Magic Link | ✅ | ✅ | ✅ |
|
|
766
|
-
| SMS | ✅ | ✅ | ✅ |
|
|
767
|
-
| Email/Phone/Username + Password | ✅ | ✅ | ✅ |
|
|
768
|
-
| Email Code | ✅ | ✅ | ✅ |
|
|
769
|
-
| Biometric | ✅ | ✅ | ❌ |
|
|
770
|
-
|
|
771
|
-
### Platform Requirements
|
|
772
|
-
|
|
773
|
-
- **iOS**: iOS 13.0+
|
|
774
|
-
- **Android**: Android 5.0 (API 21)+
|
|
775
|
-
- **Web**: Modern browsers with ES2017 support
|
|
776
|
-
|
|
777
|
-
### Capacitor Version
|
|
778
|
-
|
|
779
|
-
- Capacitor 7.0.0+
|
|
526
|
+
- Requires Capacitor for native functionality
|
|
527
|
+
- Biometric auth requires fingerprint hardware
|
|
528
|
+
- Configure `AndroidManifest.xml` for OAuth redirects
|
|
780
529
|
|
|
781
530
|
## Contributing
|
|
782
531
|
|
|
783
|
-
Contributions are welcome! Please
|
|
532
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
|
|
784
533
|
|
|
785
534
|
## License
|
|
786
535
|
|
|
787
|
-
MIT
|
|
536
|
+
MIT © [Ahsan Mahmood](https://github.com/aoneahsan)
|
|
788
537
|
|
|
789
538
|
## Support
|
|
790
539
|
|
|
791
540
|
- 📧 Email: aoneahsan@gmail.com
|
|
792
541
|
- 🐛 Issues: [GitHub Issues](https://github.com/aoneahsan/capacitor-auth-manager/issues)
|
|
793
542
|
- 💬 Discussions: [GitHub Discussions](https://github.com/aoneahsan/capacitor-auth-manager/discussions)
|
|
794
|
-
|
|
795
|
-
## Credits
|
|
796
|
-
|
|
797
|
-
Created by [Ahsan Mahmood](https://aoneahsan.com) - Open source for the community
|