pub async fn oauth_init(
http_client: &Client,
oauth_client: &OAuthClient,
login_hint: Option<&str>,
par_url: &str,
oauth_request_state: &OAuthRequestState,
) -> Result<ParResponse>
Expand description
Initiates an OAuth authorization flow using Pushed Authorization Request (PAR).
This function starts the OAuth flow by sending a PAR request to the authorization server. PAR allows the client to push the authorization request parameters to the authorization server before redirecting the user, providing enhanced security.
§Arguments
http_client
- The HTTP client to use for making requestsoauth_client
- OAuth client configuration with credentialshandle
- Optional user handle to pre-fill in the login formauthorization_server
- Authorization server metadataoauth_request_state
- OAuth request state including PKCE challenge and state
§Returns
Returns a ParResponse
containing the request URI to redirect the user to,
or an error if the PAR request fails.
§Example
use atproto_oauth_aip::workflow::{oauth_init, OAuthClient};
use atproto_oauth::workflow::OAuthRequestState;
let oauth_client = OAuthClient {
redirect_uri: "https://example.com/callback".to_string(),
client_id: "client123".to_string(),
client_secret: "secret456".to_string(),
};
let oauth_request_state = OAuthRequestState {
state: "random-state".to_string(),
nonce: "random-nonce".to_string(),
code_challenge: "code-challenge".to_string(),
scope: "atproto transition:generic".to_string(),
};
let par_response = oauth_init(
&http_client,
&oauth_client,
Some("alice.bsky.social"),
authorization_server,
&oauth_request_state,
).await?;