You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -43,6 +43,8 @@ For more details, see the [SendGrid Categories documentation](https://docs.sendg
43
43
44
44
This section will help you set up OAuth2 authentication for the extension, using GCP (Gmail) as an example.
45
45
46
+
The extension is agnostic with respect to OAuth2 provider. You just need to provide it with valid Client ID, Client Secret, and Refresh Token parameters.
47
+
46
48
##### Step 1: Create OAuth Credentials in Google Cloud Platform
47
49
48
50
1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
@@ -51,7 +53,7 @@ This section will help you set up OAuth2 authentication for the extension, using
51
53
4. Click Create Credentials and select **OAuth client ID**
52
54
5. Set the application type to **Web application**
53
55
6. Give your OAuth client a name (e.g., "Firestore Send Email Extension")
54
-
7. Under **Authorized redirect URIs**, add the URI where you'll receive the OAuth callback, for example `http://localhost:8080/oauth/callback`.
56
+
7. Under **Authorized redirect URIs**, add the URI where you'll receive the OAuth callback, for example,`http://localhost:8080/oauth/callback`.
55
57
56
58
**Note**: The redirect URI in your OAuth client settings MUST match exactly the callback URL in your code.
57
59
@@ -68,141 +70,89 @@ This section will help you set up OAuth2 authentication for the extension, using
68
70
69
71
##### Step 3: Generate a Refresh Token
70
72
71
-
You'll need to create a simple web application to generate a refreshtoken. In this subsection we illustrate how to do so with Node.js.
73
+
You can use a standalone helper script (`oauth2-refresh-token-helper.js`) that generates a refresh token without requiring any npm installations.
72
74
73
-
Here's how to set it up:
75
+
**Prerequisites:**
76
+
- You must have Node.js installed on your machine
74
77
75
-
1. Create a new Node.js project:
78
+
**Download the script:**
79
+
1. Download the script using curl, wget, or directly from your browser:
- A root route that redirects users to Google's OAuth consent page
91
-
- A callback route that receives the authorization code and exchanges it for tokens
92
-
(See the sample application included below)
88
+
You can also [view the script on GitHub](https://github.com/firebase/extensions/blob/master/firestore-send-email/scripts/oauth2-refresh-token-helper.js) and download it manually.
89
+
90
+
> **Note**: If you're working in a Node.js environment where you can use npm packages, consider using the official google-auth-library instead:
91
+
>
92
+
> 1. Install the library: `npm install google-auth-library`
> This approach integrates better with other Google services and handles token refresh automatically when using the library for API calls.
114
+
115
+
2. Run the script with Node.js:
93
116
94
-
4.**Important**: The redirect URI in your code (e.g., `http://localhost:8080/oauth/callback`) **MUST** match exactly what you configured in the Google Cloud Console OAuth client settings.
95
-
96
-
5. In your application code:
97
-
- Use the `generateAuthUrl()` method with `access_type: "offline"` and `prompt: "consent"` to request a refresh token
98
-
- Set the appropriate scope, such as `["https://mail.google.com/"]` for Gmail access
99
-
- Create a callback handler that exchanges the authorization code for tokens using `oAuth2Client.getToken(code)`
100
-
101
-
6. Run the application and access it in your browser:
102
117
```bash
103
-
node index.js
118
+
node oauth2-refresh-token-helper.js
104
119
```
105
120
106
-
7. Complete the OAuth flow:
107
-
- Navigate to your application URL (e.g., `http://localhost:8080`)
108
-
- Click the login button and authorize the application
109
-
- After successful authorization, you'll receive a JSON response containing your tokens
110
-
- Copy the `refresh_token` value for use in the extension configuration
6.**Important**: The redirect URI in the script (`http://localhost:8080/oauth/callback` by default) **MUST** match exactly what you configured in the Google Cloud Console OAuth client settings.
191
150
192
-
// Routes
193
-
app.get("/", rootHandler);
194
-
app.get("/oauth/callback", callbackHandler);
195
-
196
-
// Start server
197
-
constPORT=8080;
198
-
app.listen(PORT, () => {
199
-
console.log(`Server running at http://localhost:${PORT}`);
200
-
});
201
-
```
151
+
7. The script automatically requests the appropriate scope for Gmail access (`https://mail.google.com/`) and sets the authorization parameters to always receive a refresh token (`access_type: "offline"` and `prompt: "consent"`).
202
152
203
153
##### Step 4: Configure the Firestore Send Email Extension
204
154
205
-
When installing the extension, select "OAuth2" as the Authentication Type and provide the following parameters:
155
+
When installing the extension, select "OAuth2" as the **Authentication Type** and provide the following parameters:
-**OAuth2 SMTP Port**: `465` (for SMTPS) or `587` (for STARTTLS)
@@ -221,15 +171,15 @@ Leave `Use secure OAuth2 connection?` as the default value `true`.
221
171
-**Testing Status**: If your OAuth consent screen is in "Testing" status, refresh tokens expire after 7 days unless User Type is set to "Internal"
222
172
-**Solution**: Either publish your app or ensure User Type is set to "Internal" in the OAuth consent screen settings
223
173
224
-
###### Scope Issues
174
+
###### No Refresh Token Received
225
175
226
-
-**Problem**: If you see authentication errors, you might not have the correct scopes
227
-
-**Solution**: Ensure you've added `https://mail.google.com/` as a scope in both the OAuth consent screen and in the OAuth URL generation code
176
+
-**Problem**: If you don't receive a refresh token during the OAuth flow
177
+
-**Solution**: Make sure you've revoked previous access or forced consent by going to [Google Account Security](https://myaccount.google.com/security) > Third-party apps with account access
228
178
229
-
###### Access Denied
179
+
###### Scope Issues
230
180
231
-
-**Problem**: "Access denied" errors when sending emails
232
-
-**Solution**: Make sure the Gmail account has allowed less secure app access or that you've correctly set up OAuth2
181
+
-**Problem**: If you see authentication errors, you might not have the correct scopes
182
+
-**Solution**: Ensure you've added `https://mail.google.com/` as a scope in the OAuth consent screen
0 commit comments