Tasked with adding a cloud function to an existing Flutter app. The goal of the cloud function will be to run every so often and see if user accounts have upcoming events in their Google Calendars.
Users create accounts and sign in using Google Sign-in plugin, then stored in firebase.
I have added the scope I need to the GoogleSignIn object
static GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/calendar.events.readonly',
],
);
Sign In Process
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
//update user table in firebase
At this point the Google Sign In process returns an access token which I have stored in firebase for later use in the cloud function.
I have the client id & client secret from the web application / cloud function api project in Google Developer Console.
Now, I'm unsure how to use the googleapis / calendar node project to use this access token to get in to that users calendar.
All the examples seem to want me to create another oauth2 client with the scopes again to retrieve a token, but obviously the user won't be doing this because his will all be happening in the background when the user is not using the app.
Do I need to make a service account which then can access these calendars on behalf of the users? Can this even be done? I am struggling trying to find the answer through Google Documentation.