1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! OAuth 2.0 Authorization Code with PKCE.
//!
//! Provider-agnostic: an application names its own authorization and token
//! endpoints. The bundled providers are plain consts holding those URLs, not
//! a closed enum -- a provider the framework has never heard of is configured
//! the same way as GitHub.
//!
//! # The flow
//!
//! ```no_run
//! use arcature::oauth::{GITHUB, OauthClient, OauthState, PkceVerifier};
//!
//! # async fn flow(
//! # id: String,
//! # secret: String,
//! # session_state: String,
//! # session_verifier: String,
//! # returned_state: &str,
//! # returned_code: &str,
//! # ) -> Result<(), Box<dyn std::error::Error>> {
//! // 1. Starting a sign-in. The state and the verifier go to the session;
//! // the browser is only ever handed the URL.
//! let client = OauthClient::new(GITHUB, id, Some(secret), "https://app.test/callback")?;
//! let start = client.authorize(&["read:user"])?;
//!
//! let to_session_state = start.state().as_str().to_string();
//! let to_session_verifier = start.verifier().secret().to_string();
//! let redirect_to = start.url().as_str().to_string();
//!
//! // 2. The callback, one request later, reading both back out. `exchange`
//! // compares the stored state with the returned one itself.
//! let stored = OauthState::from_stored(session_state);
//! let verifier = PkceVerifier::from_secret(session_verifier);
//! let tokens = client
//! .exchange(&stored, returned_state, returned_code, verifier)
//! .await?;
//! # let _ = (to_session_state, to_session_verifier, redirect_to, tokens);
//! # Ok(())
//! # }
//! ```
//!
//! # What this module refuses to do
//!
//! * **Plaintext transport.** Every endpoint and the redirect URI must be
//! `https`, with one exception: `http` on a loopback host, because a local
//! development redirect has no network to be intercepted on. There is no
//! flag to turn this off.
//! * **Redirects on the token endpoint.** The HTTP client is built with
//! `redirect::Policy::none()`; following a redirect from a token endpoint
//! is a server-side request forgery primitive.
//! * **Carrying a response body into an error.** See [`error`].
//!
//! # What is never logged
//!
//! The PKCE verifier, the `state`, and every token. [`PkceVerifier`],
//! [`OauthState`] and [`TokenSet`] all redact under `Debug` and none of them
//! implements `Display`, so none can reach a log line without a call that
//! names the secret out loud.
pub use OauthError;
pub use ;
pub use ;
// Re-export the certified `oauth2` crate so downstream code targets the
// Arcature-pinned version.
pub use oauth2;