Search code examples
javascriptoauth-2.0google-calendar-api

Google Calendar quickstart, user auth needed?


I have a web app that needs to allow for users to book an appointment. The app loads my calander and shows a visual representation of what timeslots are available from my calander. Each timeslot available was made into a button. When the user clicks the button, it needs to set the event for that time slot. The event details are pre-made, the client doesn't do anything but click the time they want.

Ill be adding a form to accept their email and add it to the "attendees" object so that it can update their calendar.

Using the javascript quickstart, you use

gapi.load('client:auth2', () => {
     gapi.client.init({
       apiKey: API_KEY,
       clientId: CLIENT_ID,
       discoveryDocs: DISCOVERY_DOCS,
       scope: SCOPES,
     });

To get access to my calendar. But the rest of the quickstart

.then(() => {
        gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
      });
function updateSigninStatus() {
        gapi.auth2.getAuthInstance().isSignedIn.get();
      }

Asks the user to sign into their own account using Oauth to add an event...

How do I just allow for them to add an event by clicking the timeslot button, without needing them to go through Oauth?

For visual representation of what it looks like: enter image description here


Solution

  • The reason why it's asking the user to sign in is because your code is trying to make their account add a new event. What you probably want is to use a service account to be able to create the events without need to log in. This needs to be done in the backend, as it will contain the private key (which should never be public). This is called server to server application.

    References & further reading