Google Calendar API with Supabase

Hey, I’m looking to allow my app to read/write to google calendar.

I have setup google auth correctly and can login via google.
I am using supabase. Not all users will necessarily signup with google, but I want them to be able to later allow access to their calendar.

However, I’m not sure where to get my google API bearer token?
I thought it will be just available under the authenticated user in weweb.

If anyone has any experience in this sort of integration, I would be keen to hear how you’ve set it up.

Thanks!

I think you’ll need to set up a separate workflow for this, Supabase Auth might not even have the privileges to connect to Google Calendar, as it uses only certain data to “authenticate” the user. Check out Google Documentation for APIs for more clues on how to do this.

@AJAW Might be worth checking out a service like Nylas instead. I use it heavily and it makes things like this so much easier.

1 Like

Lantzzzzzzzzz

Welcome to the fold

Nylas is dope.

If you can’t set scopes during the initial google oauth call, you can’t access the calendar.

@jaredgibb :wave:

Season 3 Reaction

You can set the scopes for the oAuth in the Google Cloud Console, but I’m not sure how Google Handles it afterwards. I was just setting it up the other day.

When you make the initial auth request you need to dictate the scopes in the request to the oauth server

You can request more scopes later if need be.

Thanks all, I did something like this to get me started.

const redirectUrl = '***************************'
const clientID = '**************'

const path =  `https://accounts.google.com/o/oauth2/auth?client_id=${clientID}&redirect_uri=${redirectUrl}&scope=https://www.googleapis.com/auth/calendar&response_type=code&access_type=offline&prompt=consent`

  window.open(path)

I get back a a code in the url,
Then I exchange it for a access token like so:

I get an access token and refresh token, I store those under my user.
These tokens are used to call the calendar endpoints

image