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
I am currently working on an application that uses Supabase to manage Google OAuth authentication, and I am facing an issue related to the permissions (scopes) required to send emails via the Gmail API. Here is a summary of my issue and related questions:
Problem Context:
I have set up Google OAuth authentication using Supabase and successfully obtain an access token.
However, the generated token does not include the required scope to use https://www.googleapis.com/auth/gmail.send, leading to an error when attempting to send emails via the Gmail API.
Despite explicitly adding this scope in the options (see code below), the obtained token does not have the required permissions.
Questions:
Is it possible with Supabase to specify additional scopes (e.g., https://www.googleapis.com/auth/gmail.send) when configuring an OAuth provider?
If yes, could you provide an example or detailed instructions to set this up?
If this is not directly possible with Supabase, is there any recommended alternative approach to handle this use case while staying compatible with Supabase?
Current Code:
Below is a snippet of my current implementation for requesting authentication:
exportasyncfunctionrequestGmailLogin(){try{constresponse=awaitfetch("http://localhost:8080/api/auth/google-login",{method: "POST",headers: {"Content-Type": "application/json",},body: JSON.stringify({provider: "google",options: {redirectTo: "http://localhost:3000/auth/callback/google",queryParams: {access_type: "offline",prompt: "consent",scope: "email profile https://www.googleapis.com/auth/gmail.send",},},}),});if(!response.ok){thrownewError("Failed to login with Google.");}returnawaitresponse.json();}catch(error){console.error("Error during Google login:",error);throwerror;}}
And for sending emails:
constsendEmail=async(recipientEmail: string,subject: string,message: string)=>{if(!userToken||!userId){console.error("User token or user ID is not available");return;}constrawEmail=`From: [email protected]To: ${recipientEmail}Subject: ${subject}${message} `;constencodedEmail=btoa(rawEmail).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");try{constresponse=awaitfetch(`https://www.googleapis.com/gmail/v1/users/${userId}/messages/send`,{method: "POST",headers: {"Content-Type": "application/json",Authorization: `Bearer ${userToken}`,},body: JSON.stringify({raw: encodedEmail}),});if(!response.ok){consterrorData=awaitresponse.json();console.error("Error sending email:",errorData);thrownewError("Failed to send email.");}console.log("Email sent successfully!");}catch(error){console.error("Error during email sending:",error);}};
Error Encountered:
Here is the error I receive when attempting to send an email using the Gmail API:
Request had invalid authentication credentials. Expected OAuth 2 access token with proper scopes.
I would greatly appreciate it if you could provide clarification on these points. Any documentation or guidance would also be very helpful.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am currently working on an application that uses Supabase to manage Google OAuth authentication, and I am facing an issue related to the permissions (scopes) required to send emails via the Gmail API. Here is a summary of my issue and related questions:
Problem Context:
https://www.googleapis.com/auth/gmail.send
, leading to an error when attempting to send emails via the Gmail API.Questions:
https://www.googleapis.com/auth/gmail.send
) when configuring an OAuth provider?Current Code:
Below is a snippet of my current implementation for requesting authentication:
And for sending emails:
Here is the error I receive when attempting to send an email using the Gmail API:
I would greatly appreciate it if you could provide clarification on these points. Any documentation or guidance would also be very helpful.
Thank you in advance for your support!
Best regards,
Ezles
Beta Was this translation helpful? Give feedback.
All reactions