Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
1.01k stars 131 forks source link

Token retrieval failed with error: invalid_scope when using DeviceFlowAuthenticator #282

Closed fnune closed 3 years ago

fnune commented 3 years ago

Hey there, I'm failing to fetch some events from my calendar. The error is Token retrieval failed with error: invalid_scope. This happens before the flow starts, before I see the Google log-in window.

It happens only when using yup_oauth2::DeviceFlowAuthenticator. When using yup_oauth2::InstalledFlorAuthenticator there are no errors and the events are listed successfully.

Here's my code. My usage seems pretty vanilla, what am I doing wrong?

use google_calendar3::Error;
use google_calendar3::{api::Scope, CalendarHub};

pub async fn fetch_events() -> () {
  let secret = yup_oauth2::read_application_secret(std::path::Path::new("./secret.json"))
    .await
    .expect("./secret.json");

  let auth = yup_oauth2::DeviceFlowAuthenticator::builder(secret)
    .build()
    .await
    .unwrap();

  let hub = CalendarHub::new(
    hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots()),
    auth,
  );

  let result = hub
    .events()
    .list("primary")
    .add_scope(Scope::EventReadonly)
    .doit()
    .await;

  match result {
    Err(e) => match e {
      Error::HttpError(_)
      | Error::Io(_)
      | Error::MissingAPIKey
      | Error::MissingToken(_)
      | Error::Cancelled
      | Error::UploadSizeLimitExceeded(_, _)
      | Error::Failure(_)
      | Error::BadRequest(_)
      | Error::FieldClash(_)
      | Error::JsonDecodeError(_, _) => println!("{}", e),
    },
    Ok(res) => println!("Success: {:?}", res),
  }
}

Thank you very much for your time and this library.

Byron commented 3 years ago

Admittedly I have absolutely no idea, the way Google flows work is beyond me unfortunately. The one who might be able to help is the maintainer of yup-oauth2 - I do recommend asking the general question there.