strapi-plugin-firebase-authentication 1.0.13 → 1.1.7
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 +449 -191
- package/dist/_chunks/App-C49N6om4.mjs +6271 -0
- package/dist/_chunks/App-CtjmoTFU.js +6293 -0
- package/dist/_chunks/{api-DPtT1Bpu.js → api-Bw_7tM52.js} +14 -3
- package/dist/_chunks/{api-4hcml0jk.mjs → api-DrAXGM3H.mjs} +14 -3
- package/dist/_chunks/index-BkQ4pF_p.js +859 -0
- package/dist/_chunks/index-C9AUBuP7.mjs +859 -0
- package/dist/_chunks/index-FAW4iPgh.mjs +815 -0
- package/dist/_chunks/index-yE1zATuU.js +814 -0
- package/dist/admin/index.js +6 -1
- package/dist/admin/index.mjs +7 -2
- package/dist/admin/src/components/PasswordResetButton/PasswordResetButton.d.ts +11 -0
- package/dist/admin/src/components/PasswordResetButton/index.d.ts +1 -0
- package/dist/admin/src/components/common/Header/Header.d.ts +12 -0
- package/dist/admin/src/components/common/index.d.ts +3 -0
- package/dist/admin/src/components/forms/CreateUserForm/CreateUserForm.d.ts +2 -0
- package/dist/admin/src/components/forms/EditUserForm/EditUserForm.d.ts +6 -0
- package/dist/admin/src/components/forms/index.d.ts +6 -0
- package/dist/admin/src/components/forms/shared/UserFormFields/UserFormFields.d.ts +17 -0
- package/dist/admin/src/components/forms/shared/UserFormLayout/UserFormLayout.d.ts +7 -0
- package/dist/admin/src/components/index.d.ts +5 -0
- package/dist/admin/src/components/search/SearchURLQuery/SearchURLQuery.d.ts +6 -0
- package/dist/admin/src/components/search/index.d.ts +1 -0
- package/dist/admin/src/components/{DynamicTable → table/FirebaseTable}/FirebaseTable.d.ts +3 -2
- package/dist/admin/src/components/{DynamicTable → table}/FirebaseTableRows/FirebaseTableRows.d.ts +2 -2
- package/dist/admin/src/components/table/index.d.ts +3 -0
- package/dist/admin/src/components/user-management/ResetPassword/ResetPassword.d.ts +12 -0
- package/dist/admin/src/components/user-management/index.d.ts +2 -0
- package/dist/admin/src/hooks/useBulkSelection.d.ts +14 -0
- package/dist/admin/src/hooks/useUserForm.d.ts +18 -0
- package/dist/admin/src/pages/CreateView.d.ts +1 -0
- package/dist/admin/src/pages/EditView.d.ts +1 -0
- package/dist/admin/src/pages/ListView/index.d.ts +3 -5
- package/dist/admin/src/pages/Settings/api.d.ts +20 -1
- package/dist/admin/src/pages/utils/api.d.ts +4 -1
- package/dist/admin/src/utils/hasPasswordProvider.d.ts +15 -0
- package/dist/admin/src/utils/validation.d.ts +16 -0
- package/dist/model/Request.d.ts +2 -0
- package/dist/model/User.d.ts +6 -0
- package/dist/server/index.js +6542 -901
- package/dist/server/index.mjs +6537 -913
- package/dist/server/src/config/index.d.ts +36 -1
- package/dist/server/src/constants/index.d.ts +107 -0
- package/dist/server/src/content-types/index.d.ts +82 -0
- package/dist/server/src/controllers/firebaseController.d.ts +34 -2
- package/dist/server/src/controllers/index.d.ts +15 -10
- package/dist/server/src/controllers/settingsController.d.ts +2 -1
- package/dist/server/src/controllers/userController.d.ts +1 -0
- package/dist/server/src/index.d.ts +195 -36
- package/dist/server/src/migrations/migrate-firebase-user-data.d.ts +30 -0
- package/dist/server/src/routes/admin.d.ts +1 -1
- package/dist/server/src/routes/content-api.d.ts +1 -0
- package/dist/server/src/routes/index.d.ts +2 -11
- package/dist/server/src/routes/settingsRoutes.d.ts +1 -1
- package/dist/server/src/services/autoLinkService.d.ts +29 -0
- package/dist/server/src/services/emailService.d.ts +32 -0
- package/dist/server/src/services/firebaseService.d.ts +97 -13
- package/dist/server/src/services/firebaseStrapiLinkService.d.ts +34 -0
- package/dist/server/src/services/firebaseUserDataService.d.ts +26 -0
- package/dist/server/src/services/index.d.ts +91 -16
- package/dist/server/src/services/settingsService.d.ts +55 -0
- package/dist/server/src/services/templateService.d.ts +21 -0
- package/dist/server/src/services/userService.d.ts +2 -1
- package/dist/server/src/templates/defaults/index.d.ts +2 -0
- package/dist/server/src/templates/defaults/magic-link.d.ts +2 -0
- package/dist/server/src/templates/defaults/password-reset.d.ts +2 -0
- package/dist/server/src/templates/types.d.ts +30 -0
- package/dist/server/src/utils/fetch-me.d.ts +2 -10
- package/dist/server/src/utils/get-user-by-id.d.ts +1 -5
- package/dist/server/src/utils/users.d.ts +14 -0
- package/package.json +35 -24
- package/dist/_chunks/App-B2LtHk9g.js +0 -5062
- package/dist/_chunks/App-B3HcVa5j.mjs +0 -5081
- package/dist/_chunks/index-CALp4X47.mjs +0 -110
- package/dist/_chunks/index-CrGRt-Ya.mjs +0 -191
- package/dist/_chunks/index-DMBPEFUy.js +0 -109
- package/dist/_chunks/index-DmTKNKJB.js +0 -191
- package/dist/admin/src/components/SearchURLQuery/SearchURLQuery.d.ts +0 -18
- package/dist/admin/src/components/UserManagement/ResetPassword.d.ts +0 -8
- package/dist/server/src/routes/content-internal-api.d.ts +0 -11
- /package/dist/admin/src/components/{Initializer.d.ts → common/Initializer/Initializer.d.ts} +0 -0
- /package/dist/admin/src/components/{PluginIcon.d.ts → common/PluginIcon/PluginIcon.d.ts} +0 -0
- /package/dist/admin/src/components/{DynamicTable → table/FirebaseTable}/TableHeaders.d.ts +0 -0
- /package/dist/admin/src/components/{UserManagement → user-management/DeleteAccount}/DeleteAccount.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,297 +1,555 @@
|
|
|
1
1
|
# Strapi Plugin Firebase Authentication
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this plugin with iOS and Android apps. This plugin would be enabled by default for super admins only.
|
|
3
|
+
[](https://www.npmjs.com/package/strapi-plugin-firebase-authentication)
|
|
4
|
+
[](https://www.npmjs.com/package/strapi-plugin-firebase-authentication)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
A production-ready Strapi v5 plugin that seamlessly integrates Firebase Authentication with your Strapi Headless CMS. Authenticate users via Firebase (Google, Apple, Email/Password, Phone, Magic Link) and automatically sync them with Strapi's user system.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
## Features at a Glance
|
|
10
|
+
|
|
11
|
+
- **Multiple Authentication Methods**: Google Sign-In, Apple Sign-In, Email/Password, Phone-only, Magic Link (passwordless)
|
|
12
|
+
- **Automatic User Sync**: Creates and updates Strapi users from Firebase authentication
|
|
13
|
+
- **Password Reset Flow**: Complete password reset with email verification
|
|
14
|
+
- **Phone-Only Support**: Configurable email handling for phone-based authentication
|
|
15
|
+
- **Admin Panel**: Manage Firebase users directly from Strapi admin
|
|
16
|
+
- **Secure Configuration**: AES-256 encrypted Firebase credentials
|
|
17
|
+
- **Email Service**: Three-tier fallback (Strapi Email Plugin → Firebase Extension → Console)
|
|
18
|
+
- **Flexible User Lookup**: Multiple strategies (Firebase UID, email, phone, Apple relay email)
|
|
13
19
|
|
|
14
20
|
## Table of Contents
|
|
15
21
|
|
|
16
|
-
1. [
|
|
17
|
-
2. [
|
|
18
|
-
3. [
|
|
19
|
-
4. [
|
|
20
|
-
5. [
|
|
22
|
+
1. [Quick Reference](#quick-reference)
|
|
23
|
+
2. [Installation](#installation)
|
|
24
|
+
3. [Configuration](#configuration)
|
|
25
|
+
4. [Features & Authentication Flows](#features--authentication-flows)
|
|
26
|
+
5. [API Reference](#api-reference)
|
|
27
|
+
6. [Admin Panel](#admin-panel)
|
|
28
|
+
7. [Client Integration](#client-integration)
|
|
29
|
+
8. [Email Templates](#email-templates)
|
|
30
|
+
9. [Architecture & Database](#architecture--database)
|
|
31
|
+
10. [Security](#security)
|
|
32
|
+
11. [Troubleshooting](#troubleshooting)
|
|
33
|
+
12. [Best Practices](#best-practices)
|
|
34
|
+
13. [Support](#support)
|
|
35
|
+
|
|
36
|
+
## Quick Reference
|
|
37
|
+
|
|
38
|
+
### Essential Endpoints
|
|
39
|
+
|
|
40
|
+
**Authentication:**
|
|
41
|
+
|
|
42
|
+
- `POST /api/firebase-authentication` - Exchange Firebase token for Strapi JWT
|
|
43
|
+
- `POST /api/firebase-authentication/emailLogin` - Direct email/password login
|
|
44
|
+
- `POST /api/firebase-authentication/forgotPassword` - Request password reset
|
|
45
|
+
- `POST /api/firebase-authentication/resetPassword` - Authenticated password change (requires JWT)
|
|
46
|
+
- `POST /api/firebase-authentication/requestMagicLink` - Passwordless login
|
|
47
|
+
- `GET /api/firebase-authentication/config` - Get public configuration
|
|
48
|
+
|
|
49
|
+
### Minimal Configuration
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
// config/plugins.js
|
|
53
|
+
module.exports = () => ({
|
|
54
|
+
"firebase-authentication": {
|
|
55
|
+
enabled: true,
|
|
56
|
+
config: {
|
|
57
|
+
FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# .env
|
|
65
|
+
FIREBASE_JSON_ENCRYPTION_KEY=your-secure-32-character-key-here
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Required Setup Steps
|
|
69
|
+
|
|
70
|
+
1. **Install:** `yarn add strapi-plugin-firebase-authentication`
|
|
71
|
+
2. **Configure:** Add plugin config to `config/plugins.js`
|
|
72
|
+
3. **Build:** `yarn build && yarn develop`
|
|
73
|
+
4. **Upload:** Settings → Firebase Authentication → Upload service account JSON
|
|
74
|
+
5. **Permissions:** Settings → Users & Permissions → Public → `firebase-authentication.authenticate` ✓
|
|
75
|
+
|
|
76
|
+
### Admin Access
|
|
77
|
+
|
|
78
|
+
- **Settings:** Settings → Firebase Authentication
|
|
79
|
+
- **User Management:** Plugins → Firebase Authentication
|
|
80
|
+
|
|
81
|
+
---
|
|
21
82
|
|
|
22
83
|
## Installation
|
|
23
84
|
|
|
24
|
-
|
|
85
|
+
### Prerequisites
|
|
86
|
+
|
|
87
|
+
Before installing, ensure you have:
|
|
88
|
+
|
|
89
|
+
- Strapi v5 project (this plugin is for v5 only)
|
|
90
|
+
- Firebase project with Authentication enabled ([Create one](https://console.firebase.google.com/))
|
|
91
|
+
- Node.js 18+ and npm/yarn installed
|
|
92
|
+
|
|
93
|
+
### Step 1: Install Plugin
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
yarn add strapi-plugin-firebase-authentication
|
|
97
|
+
# or
|
|
98
|
+
npm install strapi-plugin-firebase-authentication
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Verify:** Check that the plugin appears in your `package.json` dependencies.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### Step 2: Create Encryption Key
|
|
106
|
+
|
|
107
|
+
Generate a secure 32+ character encryption key for storing Firebase credentials:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Generate a random key (save this!)
|
|
111
|
+
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Common Mistake:** Using a weak or short key. The key MUST be at least 32 characters.
|
|
115
|
+
|
|
116
|
+
---
|
|
25
117
|
|
|
26
|
-
###
|
|
118
|
+
### Step 3: Configure Plugin
|
|
119
|
+
|
|
120
|
+
Create or edit `config/plugins.js`:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
module.exports = () => ({
|
|
124
|
+
"firebase-authentication": {
|
|
125
|
+
enabled: true,
|
|
126
|
+
config: {
|
|
127
|
+
FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Add to `.env` file:
|
|
27
134
|
|
|
28
135
|
```bash
|
|
29
|
-
|
|
136
|
+
FIREBASE_JSON_ENCRYPTION_KEY=your-generated-key-from-step-2
|
|
30
137
|
```
|
|
31
138
|
|
|
32
|
-
|
|
139
|
+
**Verify:** Run `echo $FIREBASE_JSON_ENCRYPTION_KEY` to confirm it's set.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### Step 4: Build and Start
|
|
33
144
|
|
|
34
145
|
```bash
|
|
35
146
|
yarn build
|
|
36
147
|
yarn develop
|
|
37
148
|
```
|
|
38
149
|
|
|
39
|
-
|
|
150
|
+
**What happens:**
|
|
151
|
+
|
|
152
|
+
- Plugin compiles (admin + server)
|
|
153
|
+
- Strapi restarts with plugin enabled
|
|
154
|
+
- "Firebase Authentication" appears in Plugins sidebar
|
|
155
|
+
|
|
156
|
+
**Verify:** Check console output for:
|
|
40
157
|
|
|
41
|
-
```
|
|
42
|
-
|
|
158
|
+
```
|
|
159
|
+
✔ Building admin panel (XX.Xs)
|
|
160
|
+
Firebase Authentication plugin initialized
|
|
43
161
|
```
|
|
44
162
|
|
|
45
|
-
|
|
163
|
+
**If build fails:** Run `yarn build --clean` to clear cache.
|
|
46
164
|
|
|
47
|
-
|
|
165
|
+
---
|
|
48
166
|
|
|
49
|
-
|
|
167
|
+
### Step 5: Download Firebase Service Account
|
|
50
168
|
|
|
51
|
-
|
|
169
|
+
1. Go to [Firebase Console](https://console.firebase.google.com/)
|
|
170
|
+
2. Select your project
|
|
171
|
+
3. Navigate to: **Project Settings** (⚙️ icon) → **Service Accounts** tab
|
|
172
|
+
4. Click **"Generate New Private Key"**
|
|
173
|
+
5. Download and save the JSON file securely (you'll upload this next)
|
|
52
174
|
|
|
53
|
-
|
|
54
|
-
plugin. If the file doesn't exist, create it manually. If you already have configurations for other plugins, add
|
|
55
|
-
the `firebase-auth` section to your existing `plugins` configuration.
|
|
175
|
+
**Important:** This JSON contains sensitive credentials. Never commit it to Git.
|
|
56
176
|
|
|
57
|
-
|
|
177
|
+
---
|
|
58
178
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
179
|
+
### Step 6: Upload to Strapi
|
|
180
|
+
|
|
181
|
+
1. Navigate to: **Settings → Firebase Authentication** (left sidebar)
|
|
182
|
+
2. Click **"Upload Configuration"** button
|
|
183
|
+
3. Select the downloaded service account JSON file
|
|
184
|
+
4. Wait for "Configuration uploaded successfully" message
|
|
185
|
+
5. **Restart Strapi:** `yarn develop` (important!)
|
|
186
|
+
|
|
187
|
+
**Verify:** You should see in console:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
Firebase Admin SDK initialized successfully
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**If initialization fails:** Check [Troubleshooting](#troubleshooting) section.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Step 7: Configure Permissions
|
|
198
|
+
|
|
199
|
+
Navigate to: **Settings → Users & Permissions → Roles → Public**
|
|
200
|
+
|
|
201
|
+
Enable these permissions:
|
|
202
|
+
|
|
203
|
+
- `firebase-authentication` → `authenticate` ✓
|
|
204
|
+
|
|
205
|
+
**Why:** This allows unauthenticated users to exchange Firebase tokens for Strapi JWTs.
|
|
206
|
+
|
|
207
|
+
**Verify:** The permission checkbox should be checked and saved.
|
|
62
208
|
|
|
63
|
-
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
### Step 8: Test Your Setup
|
|
212
|
+
|
|
213
|
+
Create a simple test to verify everything works:
|
|
214
|
+
|
|
215
|
+
**Option 1: Test with Firebase Token**
|
|
216
|
+
|
|
217
|
+
1. Get a Firebase ID token from your client app (or Firebase Console)
|
|
218
|
+
2. Send POST request to: `http://localhost:1337/api/firebase-authentication`
|
|
219
|
+
3. Body: `{ "idToken": "your-firebase-token-here" }`
|
|
220
|
+
4. Expected: `200 OK` with `{ user, jwt }` response
|
|
221
|
+
|
|
222
|
+
**Option 2: Test with Email/Password** (if configured)
|
|
223
|
+
|
|
224
|
+
1. Create a user in Firebase Console
|
|
225
|
+
2. Send POST to: `http://localhost:1337/api/firebase-authentication/emailLogin`
|
|
226
|
+
3. Body: `{ "email": "test@example.com", "password": "password123" }`
|
|
227
|
+
4. Expected: `200 OK` with `{ user, jwt }` response
|
|
228
|
+
|
|
229
|
+
**If tests fail:** Check [Troubleshooting](#troubleshooting) for common issues.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
### Common Setup Mistakes
|
|
234
|
+
|
|
235
|
+
❌ **Encryption key too short** → Must be 32+ characters
|
|
236
|
+
❌ **Forgot to restart after uploading config** → Always restart Strapi
|
|
237
|
+
❌ **Wrong Firebase project** → Ensure service account matches your client app
|
|
238
|
+
❌ **Forgot to enable permissions** → Public role needs `authenticate` permission
|
|
239
|
+
❌ **Committed service account JSON to Git** → Use `.gitignore`
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### Next Steps
|
|
244
|
+
|
|
245
|
+
After successful installation:
|
|
246
|
+
|
|
247
|
+
1. **Configure additional settings** (optional):
|
|
248
|
+
- Password requirements: **Settings → Firebase Authentication**
|
|
249
|
+
- Magic link settings (passwordless auth)
|
|
250
|
+
- Email templates for password reset
|
|
251
|
+
|
|
252
|
+
2. **Integrate with your client app** (see [Client Integration](#client-integration))
|
|
253
|
+
|
|
254
|
+
3. **Set up email service** for password reset (see [Email Templates](#email-templates))
|
|
255
|
+
|
|
256
|
+
4. **Review security best practices** (see [Best Practices](#best-practices))
|
|
257
|
+
|
|
258
|
+
## Configuration
|
|
259
|
+
|
|
260
|
+
The plugin is configured in two places: `config/plugins.js` and the Strapi admin panel.
|
|
261
|
+
|
|
262
|
+
**Minimal Configuration** (`config/plugins.js`):
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
module.exports = () => ({
|
|
266
|
+
"firebase-authentication": {
|
|
64
267
|
enabled: true,
|
|
65
|
-
config: {
|
|
268
|
+
config: {
|
|
269
|
+
FIREBASE_JSON_ENCRYPTION_KEY: process.env.FIREBASE_JSON_ENCRYPTION_KEY,
|
|
270
|
+
},
|
|
66
271
|
},
|
|
67
|
-
|
|
68
|
-
// ...
|
|
69
272
|
});
|
|
70
273
|
```
|
|
71
274
|
|
|
72
|
-
|
|
275
|
+
**Admin Panel Settings** (Settings → Firebase Authentication):
|
|
73
276
|
|
|
74
|
-
|
|
277
|
+
- Firebase Web API Key (for email/password login)
|
|
278
|
+
- Password requirements (regex + message)
|
|
279
|
+
- Password reset URL & email subject
|
|
280
|
+
- Magic link settings (enable, URL, subject, expiry)
|
|
281
|
+
- Phone-only user handling (`emailRequired: false` for phone-only apps)
|
|
75
282
|
|
|
76
|
-
|
|
283
|
+
## API Reference
|
|
77
284
|
|
|
78
|
-
|
|
285
|
+
### Public Endpoints
|
|
79
286
|
|
|
80
|
-
|
|
287
|
+
| Method | Endpoint | Purpose |
|
|
288
|
+
| ------ | ----------------------------------------------- | -------------------------------------------- |
|
|
289
|
+
| POST | `/api/firebase-authentication` | Exchange Firebase token for Strapi JWT |
|
|
290
|
+
| POST | `/api/firebase-authentication/emailLogin` | Email/password login (no SDK required) |
|
|
291
|
+
| POST | `/api/firebase-authentication/forgotPassword` | Request password reset email |
|
|
292
|
+
| POST | `/api/firebase-authentication/resetPassword` | Authenticated password change (requires JWT) |
|
|
293
|
+
| POST | `/api/firebase-authentication/requestMagicLink` | Request passwordless login email |
|
|
294
|
+
| GET | `/api/firebase-authentication/config` | Get public configuration |
|
|
81
295
|
|
|
82
|
-
|
|
296
|
+
### Password Reset Flow
|
|
83
297
|
|
|
84
|
-
|
|
298
|
+
There are two distinct password reset approaches in this plugin:
|
|
85
299
|
|
|
86
|
-
|
|
300
|
+
#### 1. Forgot Password Flow (Email-Based)
|
|
87
301
|
|
|
88
|
-
|
|
302
|
+
**For users who forgot their password:**
|
|
89
303
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
304
|
+
1. User requests reset: `POST /api/firebase-authentication/forgotPassword` with `{ "email": "user@example.com" }`
|
|
305
|
+
2. Firebase sends email with link to Firebase's hosted password reset page
|
|
306
|
+
3. User clicks link → Opens Firebase's secure hosted UI
|
|
307
|
+
4. User enters new password on Firebase's page
|
|
308
|
+
5. After success → Redirects to configured continue URL
|
|
309
|
+
6. User logs in normally with new password
|
|
93
310
|
|
|
94
|
-
|
|
311
|
+
**Configuration:** Set `passwordResetUrl` in Firebase Authentication settings (this is where users land AFTER resetting their password on Firebase's page).
|
|
95
312
|
|
|
96
|
-
|
|
313
|
+
#### 2. Authenticated Password Change
|
|
97
314
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
315
|
+
**For admin-initiated resets or users changing their own password:**
|
|
316
|
+
|
|
317
|
+
- **Endpoint:** `POST /api/firebase-authentication/resetPassword`
|
|
318
|
+
- **Requires:** Valid JWT in `Authorization` header + `{ "password": "newpassword" }` in body
|
|
319
|
+
- **Use cases:**
|
|
320
|
+
- Admin resetting a user's password via admin panel
|
|
321
|
+
- Authenticated user changing their own password
|
|
322
|
+
- **Returns:** Updated user object + fresh JWT for auto-login
|
|
323
|
+
|
|
324
|
+
**Note:** This endpoint is NOT part of the forgot password email flow. Use `forgotPassword` for email-based password reset.
|
|
101
325
|
|
|
102
|
-
|
|
326
|
+
### Admin Endpoints
|
|
103
327
|
|
|
104
|
-
|
|
328
|
+
Admin endpoints use the admin API type (no `/api` prefix) and require admin authentication.
|
|
105
329
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
330
|
+
**User Management:**
|
|
331
|
+
| Method | Endpoint | Purpose |
|
|
332
|
+
|--------|----------|---------|
|
|
333
|
+
| GET | `/firebase-authentication/users` | List/search users |
|
|
334
|
+
| POST | `/firebase-authentication/users` | Create user |
|
|
335
|
+
| GET | `/firebase-authentication/users/:id` | Get user |
|
|
336
|
+
| PUT | `/firebase-authentication/users/:id` | Update user |
|
|
337
|
+
| DELETE | `/firebase-authentication/users/:id` | Delete user |
|
|
338
|
+
| PUT | `/firebase-authentication/users/resetPassword/:id` | Reset password |
|
|
109
339
|
|
|
110
|
-
|
|
340
|
+
**Settings Management:**
|
|
341
|
+
| Method | Endpoint | Purpose |
|
|
342
|
+
|--------|----------|---------|
|
|
343
|
+
| GET | `/firebase-authentication/settings/firebase-config` | Get Firebase config |
|
|
344
|
+
| POST | `/firebase-authentication/settings/firebase-config` | Upload Firebase config |
|
|
345
|
+
| DELETE | `/firebase-authentication/settings/firebase-config` | Delete Firebase config |
|
|
346
|
+
| POST | `/firebase-authentication/settings/password-config` | Update password/magic link settings |
|
|
347
|
+
|
|
348
|
+
---
|
|
111
349
|
|
|
112
350
|
## Usage
|
|
113
351
|
|
|
114
|
-
|
|
352
|
+
**Basic Flow:**
|
|
115
353
|
|
|
116
|
-
|
|
354
|
+
1. User authenticates with Firebase Client SDK
|
|
355
|
+
2. Client gets Firebase ID token
|
|
356
|
+
3. Client sends token to Strapi: `POST /api/firebase-authentication`
|
|
357
|
+
4. Plugin returns Strapi JWT for API access
|
|
117
358
|
|
|
118
|
-
|
|
359
|
+
**Example (JavaScript):**
|
|
119
360
|
|
|
120
|
-
|
|
361
|
+
```javascript
|
|
362
|
+
// After Firebase authentication
|
|
363
|
+
const idToken = await firebaseUser.getIdToken();
|
|
364
|
+
|
|
365
|
+
// Exchange with Strapi
|
|
366
|
+
const response = await fetch("https://your-api.com/api/firebase-authentication", {
|
|
367
|
+
method: "POST",
|
|
368
|
+
headers: { "Content-Type": "application/json" },
|
|
369
|
+
body: JSON.stringify({ idToken }),
|
|
370
|
+
});
|
|
121
371
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- `email`
|
|
372
|
+
const { user, jwt } = await response.json();
|
|
373
|
+
localStorage.setItem("jwt", jwt); // Use this JWT for Strapi API calls
|
|
374
|
+
```
|
|
126
375
|
|
|
127
|
-
|
|
376
|
+
**Resources:**
|
|
128
377
|
|
|
129
|
-
|
|
378
|
+
- [Firebase Web SDK](https://firebase.google.com/docs/auth/web/start)
|
|
379
|
+
- [Firebase iOS SDK](https://firebase.google.com/docs/auth/ios/start)
|
|
380
|
+
- [Firebase Android SDK](https://firebase.google.com/docs/auth/android/start)
|
|
130
381
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## Architecture
|
|
385
|
+
|
|
386
|
+
The plugin validates Firebase ID tokens and syncs users between Firebase and Strapi. Users authenticate via Firebase on the client, then exchange their Firebase token for a Strapi JWT to access your API.
|
|
387
|
+
|
|
388
|
+
**Security:**
|
|
389
|
+
|
|
390
|
+
- Firebase service account JSON encrypted with AES-256
|
|
391
|
+
- All tokens validated server-side via Firebase Admin SDK
|
|
392
|
+
- Passwords managed by Firebase (not Strapi)
|
|
393
|
+
- User responses automatically sanitized
|
|
394
|
+
|
|
395
|
+
## Troubleshooting
|
|
396
|
+
|
|
397
|
+
### 🔴 "Firebase is not initialized"
|
|
398
|
+
|
|
399
|
+
**Solution:**
|
|
400
|
+
|
|
401
|
+
1. Verify `FIREBASE_JSON_ENCRYPTION_KEY` in `config/plugins.js` (min 32 characters)
|
|
402
|
+
2. Upload Firebase service account JSON: **Settings → Firebase Authentication**
|
|
403
|
+
3. Restart Strapi: `yarn develop`
|
|
404
|
+
4. Check startup logs for initialization errors
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
### 🔴 "Token validation failed"
|
|
409
|
+
|
|
410
|
+
**Solution:**
|
|
411
|
+
|
|
412
|
+
1. Ensure token hasn't expired (1 hour TTL) - client should obtain fresh token
|
|
413
|
+
2. Verify client and server use the same Firebase project
|
|
414
|
+
3. Confirm service account JSON matches your Firebase project ID
|
|
415
|
+
4. Check Firebase Console for service status
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
### 🔴 Email Not Sending
|
|
420
|
+
|
|
421
|
+
**Solution:**
|
|
422
|
+
|
|
423
|
+
Install and configure Strapi Email Plugin:
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
yarn add @strapi/provider-email-sendgrid
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
```javascript
|
|
430
|
+
// config/plugins.js
|
|
431
|
+
email: {
|
|
432
|
+
config: {
|
|
433
|
+
provider: 'sendgrid',
|
|
434
|
+
providerOptions: { apiKey: env('SENDGRID_API_KEY') },
|
|
435
|
+
settings: {
|
|
436
|
+
defaultFrom: 'noreply@yourapp.com'
|
|
437
|
+
}
|
|
139
438
|
}
|
|
140
439
|
}
|
|
141
440
|
```
|
|
142
441
|
|
|
143
|
-
|
|
442
|
+
Alternative: Install [Firebase Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
|
|
144
443
|
|
|
145
|
-
|
|
444
|
+
---
|
|
146
445
|
|
|
147
|
-
|
|
446
|
+
**Need more help?** Check [Firebase Console](https://console.firebase.google.com/) logs or [GitHub Issues](https://github.com/meta-cto/strapi-plugin-firebase-auth/issues)
|
|
148
447
|
|
|
149
|
-
|
|
448
|
+
## Best Practices
|
|
150
449
|
|
|
151
|
-
|
|
450
|
+
- Use Firebase SDK for authentication (not `emailLogin` for production)
|
|
451
|
+
- Store JWTs in httpOnly cookies (production) or secure storage (mobile)
|
|
452
|
+
- Configure Strapi Email Plugin (SendGrid, Mailgun, SES) for production
|
|
453
|
+
- Implement rate limiting on public endpoints
|
|
454
|
+
- Enforce HTTPS for password reset URLs
|
|
455
|
+
- Monitor Firebase quotas regularly
|
|
456
|
+
- Keep dependencies updated
|
|
152
457
|
|
|
153
|
-
|
|
154
|
-
links and their brief descriptions:
|
|
458
|
+
---
|
|
155
459
|
|
|
156
|
-
|
|
157
|
-
[Link](https://firebase.google.com/docs/android/setup)
|
|
460
|
+
## Support
|
|
158
461
|
|
|
159
|
-
|
|
160
|
-
through integrating Firebase into your Android project._
|
|
462
|
+
### Questions and Issues
|
|
161
463
|
|
|
162
|
-
|
|
163
|
-
[Link](https://firebase.google.com/docs/ios/setup)
|
|
464
|
+
If you encounter problems or have questions:
|
|
164
465
|
|
|
165
|
-
|
|
166
|
-
|
|
466
|
+
1. **Check Troubleshooting Section:** Review common errors above
|
|
467
|
+
2. **Firebase Documentation:** [firebase.google.com/docs/auth](https://firebase.google.com/docs/auth)
|
|
468
|
+
3. **Strapi Documentation:** [docs.strapi.io](https://docs.strapi.io)
|
|
469
|
+
4. **GitHub Issues:** [github.com/meta-cto/strapi-plugin-firebase-auth/issues](https://github.com/meta-cto/strapi-plugin-firebase-auth/issues)
|
|
470
|
+
- Search existing issues first
|
|
471
|
+
- Provide detailed information when creating new issues
|
|
167
472
|
|
|
168
|
-
|
|
169
|
-
[Link](https://firebase.google.com/docs/web/setup)
|
|
473
|
+
### Creating a Bug Report
|
|
170
474
|
|
|
171
|
-
|
|
172
|
-
guidance on setting up Firebase in a web project. It's an essential resource for web-based authentication using
|
|
173
|
-
Firebase._
|
|
475
|
+
When reporting issues, please include:
|
|
174
476
|
|
|
175
|
-
|
|
477
|
+
1. **Plugin version:** Check `package.json`
|
|
478
|
+
2. **Strapi version:** Run `yarn strapi version`
|
|
479
|
+
3. **Node version:** Run `node --version`
|
|
480
|
+
4. **Error message:** Full error text and stack trace
|
|
481
|
+
5. **Steps to reproduce:** Detailed steps to trigger the issue
|
|
482
|
+
6. **Configuration:** Relevant plugin configuration (redact sensitive data)
|
|
483
|
+
7. **Expected behavior:** What should happen
|
|
484
|
+
8. **Actual behavior:** What actually happens
|
|
176
485
|
|
|
177
|
-
|
|
486
|
+
### Feature Requests
|
|
178
487
|
|
|
179
|
-
|
|
180
|
-
documentation: [Android Firebase Authentication with Google](https://firebase.google.com/docs/auth/android/google-signin)
|
|
181
|
-
- After signing with Google,you need to get the GoogleAuthProvider Credential and pass it to firebaseSDK to be able to get the user token
|
|
182
|
-
- Sample Code:
|
|
488
|
+
To request new features:
|
|
183
489
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.addOnCompleteListener(this) { task ->
|
|
189
|
-
if (task.isSuccessful) {
|
|
190
|
-
val token = it.result?.token
|
|
191
|
-
// Now, you can pass the token to the Firebase plugin by exchanging the Firebase Token using the `/firebase-auth` endpoint.
|
|
192
|
-
} else {
|
|
193
|
-
// If the sign-in fails, display a message to the user.
|
|
194
|
-
Log.w(TAG, "signInWithCredential:failure", task.exception)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
```
|
|
490
|
+
1. Search existing feature requests
|
|
491
|
+
2. Create detailed proposal with use case
|
|
492
|
+
3. Explain why feature would be beneficial
|
|
493
|
+
4. Suggest implementation approach (if applicable)
|
|
198
494
|
|
|
199
|
-
|
|
495
|
+
### Community
|
|
200
496
|
|
|
201
|
-
-
|
|
202
|
-
|
|
203
|
-
-
|
|
497
|
+
- **GitHub Discussions:** Ask questions and share experiences
|
|
498
|
+
- **Discord:** Join Strapi community Discord server
|
|
499
|
+
- **Stack Overflow:** Tag questions with `strapi` and `firebase`
|
|
204
500
|
|
|
205
|
-
|
|
501
|
+
---
|
|
206
502
|
|
|
207
|
-
|
|
208
|
-
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
|
|
503
|
+
## License
|
|
209
504
|
|
|
210
|
-
|
|
211
|
-
let config = GIDConfiguration(clientID: clientID)
|
|
212
|
-
GIDSignIn.sharedInstance.configuration = config
|
|
505
|
+
This plugin is licensed under the MIT License. See `LICENSE.md` for full details.
|
|
213
506
|
|
|
214
|
-
|
|
215
|
-
GIDSignIn.sharedInstance.signIn(withPresenting: self) { [unowned self] result, error in
|
|
216
|
-
guard error == nil else {
|
|
217
|
-
// ...
|
|
218
|
-
}
|
|
507
|
+
---
|
|
219
508
|
|
|
220
|
-
|
|
221
|
-
let idToken = user.idToken?.tokenString
|
|
222
|
-
else {
|
|
223
|
-
// ...
|
|
224
|
-
}
|
|
509
|
+
## Changelog
|
|
225
510
|
|
|
226
|
-
|
|
227
|
-
accessToken: user.accessToken.tokenString)
|
|
511
|
+
See `CHANGELOG.md` for version history and release notes.
|
|
228
512
|
|
|
229
|
-
|
|
513
|
+
---
|
|
230
514
|
|
|
231
|
-
|
|
515
|
+
## Credits
|
|
232
516
|
|
|
233
|
-
|
|
234
|
-
// Now you need to pass the token to firebasePlugin using exchange the firebase Token using `/firebase-auth` endpoint
|
|
235
|
-
}
|
|
517
|
+
Developed and maintained by **Meta CTO** team.
|
|
236
518
|
|
|
519
|
+
**Contributors:**
|
|
237
520
|
|
|
238
|
-
|
|
239
|
-
|
|
521
|
+
- Firebase Admin SDK: Google
|
|
522
|
+
- Strapi Framework: Strapi Solutions SAS
|
|
523
|
+
- AES Encryption: crypto-js library
|
|
240
524
|
|
|
241
|
-
|
|
525
|
+
---
|
|
242
526
|
|
|
243
|
-
|
|
244
|
-
documentation: [Web Firebase Authentication with Google](https://firebase.google.com/docs/auth/web/google-signin)
|
|
245
|
-
- After signing with Google,you need to get the GoogleAuthProvider Credential and pass it to firebaseSDK to be able to get the user token
|
|
246
|
-
- Sample Code:
|
|
527
|
+
## Additional Resources
|
|
247
528
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
.then((result) => {
|
|
254
|
-
// This gives you a Google Access Token. You can use it to access the Google API.
|
|
255
|
-
const credential = GoogleAuthProvider.credentialFromResult(result);
|
|
256
|
-
const token = credential.accessToken;
|
|
257
|
-
// The signed-in user info.
|
|
258
|
-
const user = result.user;
|
|
259
|
-
// IdP data available using getAdditionalUserInfo(result)
|
|
260
|
-
// ...
|
|
261
|
-
})
|
|
262
|
-
.catch((error) => {
|
|
263
|
-
// Handle Errors here.
|
|
264
|
-
const errorCode = error.code;
|
|
265
|
-
const errorMessage = error.message;
|
|
266
|
-
// The email of the user's account used.
|
|
267
|
-
const email = error.customData.email;
|
|
268
|
-
// The AuthCredential type that was used.
|
|
269
|
-
const credential = GoogleAuthProvider.credentialFromError(error);
|
|
270
|
-
// ...
|
|
271
|
-
});
|
|
272
|
-
```
|
|
529
|
+
**Firebase Documentation:**
|
|
530
|
+
|
|
531
|
+
- [Firebase Authentication](https://firebase.google.com/docs/auth)
|
|
532
|
+
- [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup)
|
|
533
|
+
- Platform Guides: [Web](https://firebase.google.com/docs/web/setup) | [iOS](https://firebase.google.com/docs/ios/setup) | [Android](https://firebase.google.com/docs/android/setup)
|
|
273
534
|
|
|
274
|
-
|
|
275
|
-
pass to the Firebase plugin for user authentication using `/firebase-auth` endpoint
|
|
535
|
+
**Strapi Documentation:**
|
|
276
536
|
|
|
277
|
-
|
|
537
|
+
- [Strapi v5](https://docs.strapi.io/dev-docs/intro)
|
|
538
|
+
- [Email Providers](https://market.strapi.io/providers) (SendGrid, Mailgun, Amazon SES)
|
|
278
539
|
|
|
279
|
-
|
|
540
|
+
**Firebase Extensions:**
|
|
280
541
|
|
|
281
|
-
- [
|
|
542
|
+
- [Trigger Email Extension](https://extensions.dev/extensions/firebase/firestore-send-email)
|
|
282
543
|
|
|
283
|
-
|
|
544
|
+
---
|
|
284
545
|
|
|
285
|
-
|
|
286
|
-
To ensure a smooth user login experience with Apple authentication, it’s essential to include the appleEmail field in the user object within the Strapi dashboard.
|
|
546
|
+
**Thank you for using Strapi Plugin Firebase Authentication!** 🎉
|
|
287
547
|
|
|
288
|
-
|
|
289
|
-
- iOS: [Link](https://firebase.google.com/docs/auth/ios/apple)
|
|
290
|
-
- Web: [Link](https://firebase.google.com/docs/auth/web/apple)
|
|
548
|
+
If you find this plugin helpful, please consider:
|
|
291
549
|
|
|
292
|
-
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
550
|
+
- Starring the GitHub repository
|
|
551
|
+
- Sharing with your community
|
|
552
|
+
- Contributing improvements
|
|
553
|
+
- Reporting issues to help us improve
|
|
296
554
|
|
|
297
|
-
|
|
555
|
+
Happy coding! 🚀
|