Skip to content

Instantly share code, notes, and snippets.

@opejovic
Last active February 3, 2023 21:03
Show Gist options
  • Save opejovic/9a9a84690f71975fa9b556fd2a2f32dd to your computer and use it in GitHub Desktop.
Save opejovic/9a9a84690f71975fa9b556fd2a2f32dd to your computer and use it in GitHub Desktop.

Access Google API: oauth, calendar and gmail

Create a project

image

image

Enable the Google Calendar API and Gmail API

Now, within that project, you will need to enable APIs and services. image

This will take your to their API Library. Simply search for "Calendar" and choose the Google Calendar API. image image

Now Enable the Google Gmail API image

Create your API credentials

Whilst we've enable the Google Calendar API, we now need to obtain a client ID and a client secret to add to our application.

image

Create your API credentials

The important thing here is to ask for user data since we will be asking our user to connect to their Google Account through OAuth authentication.

image image

image image image image

image image

Now we need to give the name of our application but most importantly, we need to whitelist the redirect URI that we want the user to be redirected to after the OAuth process. You can run valet share to get a random ngrok URL. (This will have to be updated whenever you rerun the valet share / ngrok, if you are on the free plan). If you are using the Google API on a live server, use its real domain instead.

Now that we have our domain, we just need to decide the route that we will use for our OAuth callback. We will be using /oauth/google. Therefore the full URL is https://${NGROK_URL}.ngrok.io/oauth/google image

image

Click on you app name.

image

Here are your GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables. As you can see we've also successfully whitelisted our GOOGLE_REDIRECT_URI environment variables which, in our case, is https://602b-62-4-44-207.ngrok.io/oauth/google. You can always come back to this page later to update the redirect URI in case your domain name changes.

image

Add a test user (this will be the email of the agent you will use to test with - you can add up to 100 test users) and proceed to summary, where you should be done. image


Your OAuth consent screen has been configured and your app has a publishing status of “Testing”. This means it can be used by a limited set of test users, which you can set up on the OAuth consent screen page. If you want to make your app generally available to all users, you will need to set the publishing status to “In production”. You will also need to submit your app for verification (https://support.google.com/cloud/answer/9110914), which can take up to 4-6 weeks (depending on which OAuth scopes your app uses).


Env variable APP_URL needs to be changed to either a dev link (the ngrok tunel), or production url of the site, if app is in production.

While publishing status is set to "Testing", only test users are able to access the app. Allowed user cap prior to app verification is 100, and is counted over the entire lifetime of the app.

https://support.google.com/cloud/answer/7454865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment