I have a flutter app that needs access to multiple user's calendars.
I can get access for one user working, but the access grant is only temporary and the user gets re-prompted every time. I want to develop something like the firebase google authentication and many other Oauth examples: You get prompted once to grant access and then the access is granted offline until you revoke the access grant.
How can I request access with the remembered credentials? Here is my code:
final ClientId _userAccountCredentials = new ClientId(
"XXXXX.apps.googleusercontent.com",
"");
void prompt(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
void getCalendarEventsOnline() {
clientViaUserConsent(_userAccountCredentials, scopes, prompt).then((AuthClient client) {
var calendar = calendarapi.CalendarApi(client);
var calEvents = calendar.events.list("primary");
calEvents.then((calendarapi.Events events) {
/// some logic within
});
client.close();
});
}
I tried using a service account, but impersonating a user works only for a Gsuite account
Asking each user to add the service account to their calendar is error-prone, clumsy and unacceptable for non-technical users (think your grandparents), given that many popular services can do this directly