graph-rs-sdk: example app crashed while fetching access token using access code: `Error("missing field `access_token`", line: 1, column: 409)`

Hello! Thanks for making this great project!

I’m building and running this example: https://github.com/sreeise/graph-rs/blob/master/examples/oauth/main.rs#L37

Dependencies:

[package]
edition = "2021"
name = "ms-graph-demo"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3"
graph-rs-sdk = "1.0.0"
lazy_static = "1.4.0"
reqwest = "0.11.16"
serde = {version = "1", features = ["derive"]}
serde_json = "1"

tokio = {version = "1.27.0", features = ["full"]}
warp = "0.3.4"

crash stack:
     Running `target/debug/ms-graph-demo`
AccessCode {
    code: "M.R3_BL2.2.[redacted]",
}
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReqwestError(reqwest::Error { kind: Decode, source: Error("missing field `access_token`", line: 1, column: 409) })', src/auth_code_grant.rs:44:60
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/result.rs:1790:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/result.rs:1112:23
   4: ms_graph_demo::auth_code_grant::set_and_req_access_code::{{closure}}
             at ./src/auth_code_grant.rs:44:24
   5: ms_graph_demo::auth_code_grant::handle_redirect::{{closure}}
             at ./src/auth_code_grant.rs:62:49
   6: <F as futures_core::future::TryFuture>::try_poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.28/src/future.rs:82:9
   7: <warp::filter::and_then::State<T,F> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.4/src/filter/and_then.rs:99:44
   8: <warp::filter::and_then::AndThenFuture<T,F> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.4/src/filter/and_then.rs:74:9
   9: <F as futures_core::future::TryFuture>::try_poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.28/src/future.rs:82:9
  10: <warp::filter::service::FilteredFuture<F> as core::future::future::Future>::poll::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.4/src/filter/service.rs:128:40
  11: scoped_tls::ScopedKey<T>::set
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.1/src/lib.rs:137:9
  12: warp::route::set
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.4/src/route.rs:16:5
  13: <warp::filter::service::FilteredFuture<F> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.4/src/filter/service.rs:128:15
  14: <hyper::proto::h1::dispatch::Server<S,hyper::body::body::Body> as hyper::proto::h1::dispatch::Dispatch>::poll_msg
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:491:35
  15: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_write
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:297:43
  16: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:161:21
  17: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_inner
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:137:16
  18: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_catch
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:120:28
  19: <hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/proto/h1/dispatch.rs:424:9
  20: <hyper::server::conn::ProtoServer<T,B,S,E> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/server/conn.rs:969:47
  21: <hyper::server::conn::upgrades::UpgradeableConnection<I,S,E> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/server/conn.rs:1029:30
  22: <hyper::server::server::new_svc::NewSvcTask<I,N,S,E,W> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.25/src/server/server.rs:751:36
  23: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/core.rs:223:17
  24: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/loom/std/unsafe_cell.rs:14:9
  25: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/core.rs:212:13
  26: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:476:19
  27: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panic/unwind_safe.rs:271:9
  28: std::panicking::try::do_call
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:483:40
  29: ___rust_try
  30: std::panicking::try
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:447:19
  31: std::panic::catch_unwind
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs:140:14
  32: tokio::runtime::task::harness::poll_future
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:464:18
  33: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:198:27
  34: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:152:15
  35: tokio::runtime::task::raw::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/raw.rs:255:5
  36: tokio::runtime::task::raw::RawTask::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/raw.rs:200:18
  37: tokio::runtime::task::LocalNotified<S>::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/mod.rs:394:9
  38: tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:487:21
  39: tokio::runtime::coop::with_budget
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/coop.rs:107:5
  40: tokio::runtime::coop::budget
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/coop.rs:73:5
  41: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:463:9
  42: tokio::runtime::scheduler::multi_thread::worker::Context::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:426:24
  43: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:406:17
  44: tokio::macros::scoped_tls::ScopedKey<T>::set
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/macros/scoped_tls.rs:61:9
  45: tokio::runtime::scheduler::multi_thread::worker::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:403:5
  46: tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/scheduler/multi_thread/worker.rs:365:45
  47: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/blocking/task.rs:42:21
  48: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/core.rs:223:17
  49: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/loom/std/unsafe_cell.rs:14:9
  50: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/core.rs:212:13
  51: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:476:19
  52: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panic/unwind_safe.rs:271:9
  53: std::panicking::try::do_call
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:483:40
  54: ___rust_try
  55: std::panicking::try
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:447:19
  56: std::panic::catch_unwind
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs:140:14
  57: tokio::runtime::task::harness::poll_future
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:464:18
  58: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:198:27
  59: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/harness.rs:152:15
  60: tokio::runtime::task::raw::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/raw.rs:255:5
  61: tokio::runtime::task::raw::RawTask::poll
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/raw.rs:200:18
  62: tokio::runtime::task::UnownedTask<S>::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/task/mod.rs:431:9
  63: tokio::runtime::blocking::pool::Task::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/blocking/pool.rs:159:9
  64: tokio::runtime::blocking::pool::Inner::run
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/blocking/pool.rs:513:17
  65: tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}
             at /Users/[user]/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/blocking/pool.rs:471:13
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Edit: I printed out the error:

Error: ReqwestError(
    reqwest::Error {
        kind: Decode,
        source: Error("missing field `access_token`", line: 1, column: 409),
    },
)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Thank you for the help! I really appreciate it! Now it is another error:

"{\"error\":\"invalid_request\",\"error_description\":\"AADSTS90023: Public clients can't send a client secret.\\r\\nTrace ID: 1ad28830-8052-4903-9d2c-d6c342362506\\r\\nCorrelation ID: 231c3a9\\r\\nTimestamp: 2023-04-07 Z\",\"error_codes\":[90023],\"timestamp\":\"2023-04-07 Z\",\"trace_id\":\"1ad\",\"correlation_id\":\"231c42cd443a9\"}"

Let me dig into it

Fixed it by removing client secret!

Thank you so much!

"{\"token_type\":\"Bearer\",\"scope\":\"Files.Read Files.Read.All Files.ReadWrite Files.ReadWrite.All User.Read User.ReadWrite\",\"expires_in\":3600,\"ext_expires_in\":3600,\"access_token\":\"E..."...

No problem! Im so glad you got it figured out. Thats awesome!

Oh, I found the position to add breakpoint! Thanks!

image

šŸ˜† Im glad you found it. That also helps me cause it proves to me that we need to fix how the OAuth crate is returning those responses cause its obviously ignoring any Response errors. That should really just be returning the Response itself.

If you want to be sure your credentials and permissions are valid you can try them with Postman. Follow this procedure https://learn.microsoft.com/en-us/graph/use-postman If you get an error while retreiving the access_token the full error description will be in the console.