diff options
| author | Teddy Wing | 2021-05-23 00:05:18 +0200 |
|---|---|---|
| committer | Teddy Wing | 2021-05-23 00:05:18 +0200 |
| commit | 1d74a82aefdbc9936ee662c57dcdd8fa8364918a (patch) | |
| tree | 93e7774a6533457d3cd2948dedcec950608131d2 /src/main.rs | |
| parent | cc90495f29cba19a8d3f4fa201d884ac543d1334 (diff) | |
| download | google-calendar-rsvp-1d74a82aefdbc9936ee662c57dcdd8fa8364918a.tar.bz2 | |
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).
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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))?; |
