// This file is auto-generated by oagen. Do not edit.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;
pub struct OAuthApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct GetOAuthAuthorizationRequestParams {
/// Required.
pub response_type: String,
/// Required.
pub client_id: String,
/// Required.
pub redirect_uri: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<String>,
/// Required.
pub state: String,
/// Required.
pub code_challenge: String,
/// Required.
pub code_challenge_method: String,
}
impl GetOAuthAuthorizationRequestParams {
/// Construct a new `GetOAuthAuthorizationRequestParams` with the required fields set.
#[allow(deprecated)]
pub fn new(
response_type: impl Into<String>,
client_id: impl Into<String>,
redirect_uri: impl Into<String>,
state: impl Into<String>,
code_challenge: impl Into<String>,
code_challenge_method: impl Into<String>,
) -> Self {
Self {
response_type: response_type.into(),
client_id: client_id.into(),
redirect_uri: redirect_uri.into(),
scope: Default::default(),
state: state.into(),
code_challenge: code_challenge.into(),
code_challenge_method: code_challenge_method.into(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ApproveOAuthAuthorizationParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkApproveOAuthAuthorizationRequestApplicationXWwwFormUrlencoded,
}
impl ApproveOAuthAuthorizationParams {
/// Construct a new `ApproveOAuthAuthorizationParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkApproveOAuthAuthorizationRequestApplicationXWwwFormUrlencoded) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct DenyOAuthAuthorizationParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkDenyOAuthAuthorizationRequestApplicationXWwwFormUrlencoded,
}
impl DenyOAuthAuthorizationParams {
/// Construct a new `DenyOAuthAuthorizationParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkDenyOAuthAuthorizationRequestApplicationXWwwFormUrlencoded) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ExchangeOAuthTokenParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: ExchangeOAuthTokenParamsBodyOneOf,
}
impl ExchangeOAuthTokenParams {
/// Construct a new `ExchangeOAuthTokenParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: ExchangeOAuthTokenParamsBodyOneOf) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct RevokeOAuthTokenParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkRevokeOAuthTokenRequestApplicationXWwwFormUrlencoded,
}
impl RevokeOAuthTokenParams {
/// Construct a new `RevokeOAuthTokenParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkRevokeOAuthTokenRequestApplicationXWwwFormUrlencoded) -> Self {
Self { body }
}
}
impl<'a> OAuthApi<'a> {
/// Read OAuth server metadata
///
/// Discover the official CLI authorization, token and revocation endpoints and supported scopes. The CLI uses public client authentication without a secret.
pub async fn get_oauth_authorization_server_metadata(
&self,
) -> Result<SdkGetOAuthAuthorizationServerMetadataResponseValue200ApplicationJson, Error> {
self.get_oauth_authorization_server_metadata_with_options(None)
.await
}
/// Variant of [`Self::get_oauth_authorization_server_metadata`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_oauth_authorization_server_metadata_with_options(
&self,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetOAuthAuthorizationServerMetadataResponseValue200ApplicationJson, Error> {
self.get_oauth_authorization_server_metadata_raw(options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_oauth_authorization_server_metadata_raw(
&self,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkGetOAuthAuthorizationServerMetadataResponseValue200ApplicationJson>,
Error,
> {
let path = "/.well-known/oauth-authorization-server".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getOAuthAuthorizationServerMetadata".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
&(),
options,
"GET /.well-known/oauth-authorization-server",
)
.await
}
/// Review CLI authorization
///
/// Open in the user's browser to authorize the official CLI using existing store permissions. Only the configured public CLI registration is supported. PKCE S256 and non-empty state are required. The callback may vary only the port of the registered numeric loopback URL; localhost, wildcard hosts, fragments and non-loopback HTTP are rejected. Unsupported clients receive invalid_client and unsupported scopes receive invalid_scope.
pub async fn get_oauth_authorization_request(
&self,
params: GetOAuthAuthorizationRequestParams,
) -> Result<String, Error> {
self.get_oauth_authorization_request_with_options(params, None)
.await
}
/// Variant of [`Self::get_oauth_authorization_request`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_oauth_authorization_request_with_options(
&self,
params: GetOAuthAuthorizationRequestParams,
options: Option<&crate::RequestOptions>,
) -> Result<String, Error> {
self.get_oauth_authorization_request_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_oauth_authorization_request_raw(
&self,
params: GetOAuthAuthorizationRequestParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<String>, Error> {
let path = "/oauth/authorize".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getOAuthAuthorizationRequest".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /oauth/authorize",
)
.await
}
/// Approve CLI access
///
/// Submit the official CLI consent form in the same logged-in browser session. The admin grant covers every store you can access now or later, including when you currently have no stores. It also permits store creation. Local agents connected through the CLI share this connection. Approval never adds store role permissions. Current client eligibility, membership and permissions are rechecked, including for stale consent.
pub async fn approve_oauth_authorization(
&self,
params: ApproveOAuthAuthorizationParams,
) -> Result<(), Error> {
self.approve_oauth_authorization_with_options(params, None)
.await
}
/// Variant of [`Self::approve_oauth_authorization`] that accepts per-request [`crate::RequestOptions`].
pub async fn approve_oauth_authorization_with_options(
&self,
params: ApproveOAuthAuthorizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
self.approve_oauth_authorization_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn approve_oauth_authorization_raw(
&self,
params: ApproveOAuthAuthorizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<()>, Error> {
let path = "/oauth/authorize".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("approveOAuthAuthorization".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /oauth/authorize",
)
.await
}
/// Deny CLI access
///
/// Submit the denial form from the same browser session. The callback receives access_denied and the original state.
pub async fn deny_oauth_authorization(
&self,
params: DenyOAuthAuthorizationParams,
) -> Result<(), Error> {
self.deny_oauth_authorization_with_options(params, None)
.await
}
/// Variant of [`Self::deny_oauth_authorization`] that accepts per-request [`crate::RequestOptions`].
pub async fn deny_oauth_authorization_with_options(
&self,
params: DenyOAuthAuthorizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
self.deny_oauth_authorization_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn deny_oauth_authorization_raw(
&self,
params: DenyOAuthAuthorizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<()>, Error> {
let path = "/oauth/authorize".to_string();
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("denyOAuthAuthorization".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"DELETE /oauth/authorize",
)
.await
}
/// Exchange or refresh OAuth tokens
///
/// Exchange an official CLI authorization code with the original redirect URI and PKCE verifier, or rotate a refresh token. Send the configured client_id without a secret. Client eligibility and current grant validity are rechecked. Access tokens last 60 minutes; refresh token families last 90 days. Atomically replace rotated refresh tokens. Reuse may revoke the family; reauthorize after invalid_grant. Fix registration or scope configuration for invalid_client or invalid_scope instead of repeating login.
pub async fn exchange_oauth_token(
&self,
params: ExchangeOAuthTokenParams,
) -> Result<SdkExchangeOAuthTokenResponseValue200ApplicationJson, Error> {
self.exchange_oauth_token_with_options(params, None).await
}
/// Variant of [`Self::exchange_oauth_token`] that accepts per-request [`crate::RequestOptions`].
pub async fn exchange_oauth_token_with_options(
&self,
params: ExchangeOAuthTokenParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkExchangeOAuthTokenResponseValue200ApplicationJson, Error> {
self.exchange_oauth_token_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn exchange_oauth_token_raw(
&self,
params: ExchangeOAuthTokenParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkExchangeOAuthTokenResponseValue200ApplicationJson>, Error>
{
let path = "/oauth/token".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("exchangeOAuthToken".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /oauth/token",
)
.await
}
/// Revoke an OAuth token
///
/// Revoke the matching personal CLI installation and all its token families. Send the configured public client_id without a secret. Unknown tokens also succeed without disclosing whether a token existed.
pub async fn revoke_oauth_token(
&self,
params: RevokeOAuthTokenParams,
) -> Result<Vec<serde_json::Value>, Error> {
self.revoke_oauth_token_with_options(params, None).await
}
/// Variant of [`Self::revoke_oauth_token`] that accepts per-request [`crate::RequestOptions`].
pub async fn revoke_oauth_token_with_options(
&self,
params: RevokeOAuthTokenParams,
options: Option<&crate::RequestOptions>,
) -> Result<Vec<serde_json::Value>, Error> {
self.revoke_oauth_token_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn revoke_oauth_token_raw(
&self,
params: RevokeOAuthTokenParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<Vec<serde_json::Value>>, Error> {
let path = "/oauth/revoke".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("revokeOAuthToken".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /oauth/revoke",
)
.await
}
}