Search code examples
google-apigoogle-calendar-api

Access Google Calendar API without user


I'm working on a webapp (SPA and backend) that must constantly access the user's Google calendar. The app will work 24/7, running the background service and modifying the user's calendar without the user's involvement. As far as I understand there are two ways of implementing such service:

  1. Use a service account. That will require the user to share his calendar with a service account, which is not an option in my case.
  2. Use server code to authenticate the user in my app using OAuth2. That way, the user will be initially forwarded to the Google login page, where he can give my app all required permissions. Next, my server code will retrieve access_token and refresh_token. Refresh_token will be stored in the database and periodically used to renew access_token. That way, my server can access the user's Google calendar indefinitely.

Am I missing something, and are there are other options to access Google Calendar without a user?


Solution

  • Use a service account. That will require the user to share his calendar with a service account, which is not an option in my case.

    To be clear service accounts only work with google workspace domain accounts if domain wide delegation has been configured.

    Use server code to authenticate the user in my app using OAuth2. That way, the user will be initially forwarded to the Google login page, where he can give my app all required permissions. Next, my server code will retrieve access_token and refresh_token. Refresh_token will be stored in the database and periodically used to renew access_token. That way, my server can access the user's Google calendar indefinitely.

    Yes this is the way to go.