From 1d74a82aefdbc9936ee662c57dcdd8fa8364918a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 23 May 2021 00:05:18 +0200 Subject: Request Event read-write authorisation scope Previously there were two OAuth authorisation prompts, one for each API call, because each call has different default scopes. Since we always need Event read-write access, set this as our scope for both API calls so that we request only what the application as a whole needs, and so we don't ask for authorisation twice (which requires visiting a URL with one's Google account). --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a8d3e73..5298c30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use anyhow::{self, Context}; use base64; use chrono::DateTime; -use google_calendar3::api::{Event, EventAttendee}; +use google_calendar3::api::{Event, EventAttendee, Scope}; use google_calendar3::CalendarHub; use hyper; use hyper_rustls; @@ -171,6 +171,10 @@ async fn rsvp(event_id: &str, response: &EventResponseStatus) -> anyhow::Result< let get_response = hub.events() .get("primary", event_id) + + // Request read-write access to events so that we don't ask for + // authorization a second time on the subsequent Event.patch call. + .add_scope(Scope::Event) .doit() .await .with_context(|| format!("unable to get event '{}'", event_id))?; @@ -196,6 +200,9 @@ async fn rsvp(event_id: &str, response: &EventResponseStatus) -> anyhow::Result< let rsvp_response = hub.events() .patch(event, "primary", event_id) + + // The default scope is Scope::Full. + .add_scope(Scope::Event) .doit() .await .with_context(|| format!("unable to update event '{}'", event_id))?; -- cgit v1.2.3