pub struct PendingAuthorization { /* private fields */ }Expand description
The secrets needed to complete an authorization request.
Created by super::authorize::AuthorizationUrl::start. Hold this for the
duration of the flow — in session storage for a web backend, in memory for a
native or client-side app — then finish with
PendingAuthorization::complete.
Keeping the verifier and state together here means the CSRF check and the verifier cannot be forgotten: the only way to reach the token exchange is through a method that performs both.
§Example
use lichess_api::client::LichessApi;
use lichess_api::model::oauth::authorize::AuthorizationUrl;
let (url, pending) = AuthorizationUrl::generated("example.com", "http://example.com/")
.scope("preference:read")
.start()?;
// Send the user to `url`. They come back to your `redirect_uri`, which
// carries the authorization result in its query string.
let redirect_url = url::Url::parse("http://example.com/?code=...&state=...").unwrap();
// No token yet, so the client is unauthenticated here.
let api = LichessApi::new(reqwest::Client::new(), None);
let token = pending.complete(&api, &redirect_url).await?;
// Subsequent requests act on behalf of the user.
let api = LichessApi::new(reqwest::Client::new(), Some(token.access_token));Implementations§
Source§impl PendingAuthorization
impl PendingAuthorization
pub fn new( verifier: impl Into<String>, state: impl Into<String>, client_id: impl Into<String>, redirect_uri: impl Into<String>, ) -> Self
Sourcepub fn exchange_form(self, redirect_url: &Url) -> Result<TokenExchangeForm>
pub fn exchange_form(self, redirect_url: &Url) -> Result<TokenExchangeForm>
Parse an authorization result and produce the token exchange form.
redirect_url is the full URL the user was redirected back to,
including its query string. Returns an error if the authorization was
denied, if the state does not match, or if the URL is missing the
authorization code.
Use this when you want to inspect or send the exchange yourself;
PendingAuthorization::complete does this and performs the exchange.
Sourcepub async fn complete(
self,
api: &LichessApi<Client>,
redirect_url: &Url,
) -> Result<AccessToken>
pub async fn complete( self, api: &LichessApi<Client>, redirect_url: &Url, ) -> Result<AccessToken>
Complete the flow: verify the authorization result and exchange the code for an access token.
redirect_url is the full URL the user was redirected back to.
The client need not be authenticated — this is what produces the token —
so LichessApi::new(client, None) is fine here.
Trait Implementations§
Source§impl Clone for PendingAuthorization
impl Clone for PendingAuthorization
Source§fn clone(&self) -> PendingAuthorization
fn clone(&self) -> PendingAuthorization
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more