use anyhow::Result;
use crate::Client;
#[derive(Clone, Debug)]
pub struct Oauth2AuthorizeParams<'a> {
pub client_id: uuid::Uuid,
pub code_challenge: &'a str,
pub code_challenge_method: crate::types::Oauth2CodeChallengeMethod,
pub redirect_uri: &'a str,
pub response_type: crate::types::Oauth2AuthorizationResponseType,
pub scope: Option<String>,
pub state: &'a str,
}
impl<'a> Oauth2AuthorizeParams<'a> {
pub fn new(
client_id: uuid::Uuid,
code_challenge: &'a str,
code_challenge_method: crate::types::Oauth2CodeChallengeMethod,
redirect_uri: &'a str,
response_type: crate::types::Oauth2AuthorizationResponseType,
state: &'a str,
) -> Self {
Self {
client_id,
code_challenge,
code_challenge_method,
redirect_uri,
response_type,
scope: Default::default(),
state,
}
}
}
#[derive(Clone, Debug)]
pub struct Oauth2 {
pub client: Client,
}
impl Oauth2 {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}
#[doc = "Get a pending OAuth 2.0 authorization request for the consent page.\n\n**Parameters:**\n\n- `request_id: uuid::Uuid`: The pending authorization request ID. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_get_oauth_2_authorization_request() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AuthorizationRequestResponse = client\n .oauth2()\n .get_oauth_2_authorization_request(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_oauth_2_authorization_request<'a>(
&'a self,
request_id: uuid::Uuid,
) -> Result<crate::types::Oauth2AuthorizationRequestResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"oauth2/authorization-requests/{request_id}"
.replace("{request_id}", &format!("{}", request_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Approve a pending OAuth 2.0 authorization request.\n\n**Parameters:**\n\n- `request_id: uuid::Uuid`: The pending authorization request ID. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_approve_oauth_2_authorization_request() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AuthorizationDecisionResponse = client\n .oauth2()\n .approve_oauth_2_authorization_request(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn approve_oauth_2_authorization_request<'a>(
&'a self,
request_id: uuid::Uuid,
) -> Result<crate::types::Oauth2AuthorizationDecisionResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"oauth2/authorization-requests/{request_id}/approve"
.replace("{request_id}", &format!("{}", request_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Deny a pending OAuth 2.0 authorization request.\n\n**Parameters:**\n\n- `request_id: uuid::Uuid`: The pending authorization request ID. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_deny_oauth_2_authorization_request() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AuthorizationDecisionResponse = client\n .oauth2()\n .deny_oauth_2_authorization_request(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn deny_oauth_2_authorization_request<'a>(
&'a self,
request_id: uuid::Uuid,
) -> Result<crate::types::Oauth2AuthorizationDecisionResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"oauth2/authorization-requests/{request_id}/deny"
.replace("{request_id}", &format!("{}", request_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Start an OAuth 2.0 authorization code flow with PKCE.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth app client ID. (required)\n- `code_challenge: &'astr`: The PKCE code challenge. (required)\n- `code_challenge_method: crate::types::Oauth2CodeChallengeMethod`: The PKCE challenge method. (required)\n- `redirect_uri: &'astr`: The redirect URI for the client. (required)\n- `response_type: crate::types::Oauth2AuthorizationResponseType`: The OAuth response type. (required)\n- `scope: Option<String>`: The requested OAuth scopes.\n- `state: &'astr`: Opaque client state to round-trip back to the client. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_oauth_2_authorize() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_authorize(kittycad::oauth2::Oauth2AuthorizeParams {\n client_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n code_challenge: \"some-string\",\n code_challenge_method: kittycad::types::Oauth2CodeChallengeMethod::S256,\n redirect_uri: \"https://example.com/foo/bar\",\n response_type: kittycad::types::Oauth2AuthorizationResponseType::Code,\n scope: Some(\"some-string\".to_string()),\n state: \"some-string\",\n })\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_authorize<'a>(
&'a self,
params: Oauth2AuthorizeParams<'a>,
) -> Result<(), crate::types::error::Error> {
let Oauth2AuthorizeParams {
client_id,
code_challenge,
code_challenge_method,
redirect_uri,
response_type,
scope,
state,
} = params;
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "oauth2/authorize"),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![
("client_id", format!("{}", client_id)),
("code_challenge", code_challenge.to_string()),
(
"code_challenge_method",
format!("{}", code_challenge_method),
),
("redirect_uri", redirect_uri.to_string()),
("response_type", format!("{}", response_type)),
("state", state.to_string()),
];
if let Some(p) = scope {
query_params.push(("scope", p));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Start an OAuth 2.0 Device Authorization Grant.\n\nThis endpoint is designed to be \
accessed from an *unauthenticated* API client. It generates and records a \
`device_code` and `user_code` which must be verified and confirmed prior to a token \
being granted.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_oauth2_device_auth_request() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.device_auth_request(&kittycad::types::DeviceAuthRequestForm {\n \
client_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n \
})\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn device_auth_request<'a>(
&'a self,
body: &crate::types::DeviceAuthRequestForm,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "oauth2/device/auth"),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Confirm an OAuth 2.0 Device Authorization Grant.\n\nThis endpoint is designed to be \
accessed by the user agent (browser), not the client requesting the token. So we do \
not actually return the token here; it will be returned in response to the poll on \
`/oauth2/device/token`.\n\n```rust,no_run\nasync fn \
example_oauth2_device_auth_confirm() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.device_auth_confirm(&kittycad::types::DeviceAuthConfirmParams {\n \
user_code: \"some-string\".to_string(),\n })\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn device_auth_confirm<'a>(
&'a self,
body: &crate::types::DeviceAuthConfirmParams,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "oauth2/device/confirm"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Request a device access token.\n\nThis endpoint should be polled by the client until the user code is verified and the grant is confirmed.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_device_access_token() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .device_access_token(&kittycad::types::DeviceAccessTokenRequestForm {\n client_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n device_code: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n grant_type: kittycad::types::Oauth2GrantType::UrnIetfParamsOauthGrantTypeDeviceCode,\n })\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn device_access_token<'a>(
&'a self,
body: &crate::types::DeviceAccessTokenRequestForm,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "oauth2/device/token"),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Verify an OAuth 2.0 Device Authorization Grant.\n\nThis endpoint should be accessed \
in a full user agent (e.g., a browser). If the user is not logged in, we redirect \
them to the login page and use the `callback_url` parameter to get them to the UI \
verification form upon logging in. If they are logged in, we redirect them to the UI \
verification form on the website.\n\n**Parameters:**\n\n- `app_name: Option<String>`: \
The originating app's name\n- `user_code: &'astr`: The user code. \
(required)\n\n```rust,no_run\nasync fn example_oauth2_device_auth_verify() -> \
anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n \
client\n .oauth2()\n \
.device_auth_verify(Some(\"some-string\".to_string()), \"some-string\")\n \
.await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn device_auth_verify<'a>(
&'a self,
app_name: Option<String>,
user_code: &'a str,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "oauth2/device/verify"),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![("user_code", user_code.to_string())];
if let Some(p) = app_name {
query_params.push(("app_name", p));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Listen for callbacks for the OAuth 2.0 provider.\n\n**Parameters:**\n\n- `code: Option<String>`: The authorization code.\n- `id_token: Option<String>`: For Apple only, a JSON web token containing the user’s identity information.\n- `provider: crate::types::AccountProvider`: The provider. (required)\n- `state: Option<String>`: The state that we had passed in through the user consent URL.\n- `user: Option<String>`: For Apple only, a JSON string containing the data requested in the scope property. The returned data is in the following format: `{ \"name\": { \"firstName\": string, \"lastName\": string }, \"email\": string }`\n\n```rust,no_run\nasync fn example_oauth2_oauth_2_provider_callback() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_provider_callback(\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n kittycad::types::AccountProvider::Github,\n Some(\"some-string\".to_string()),\n Some(\"some-string\".to_string()),\n )\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_callback<'a>(
&'a self,
code: Option<String>,
id_token: Option<String>,
provider: crate::types::AccountProvider,
state: Option<String>,
user: Option<String>,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"oauth2/provider/{provider}/callback"
.replace("{provider}", &format!("{}", provider))
),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = code {
query_params.push(("code", p));
}
if let Some(p) = id_token {
query_params.push(("id_token", p));
}
if let Some(p) = state {
query_params.push(("state", p));
}
if let Some(p) = user {
query_params.push(("user", p));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Listen for callbacks for the OAuth 2.0 provider.\n\nThis specific endpoint listens \
for posts of form data.\n\n**Parameters:**\n\n- `provider: \
crate::types::AccountProvider`: The provider. (required)\n\n```rust,no_run\nasync fn \
example_oauth2_oauth_2_provider_callback_post() -> anyhow::Result<()> {\n let \
client = kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.oauth_2_provider_callback_post(\n \
kittycad::types::AccountProvider::Github,\n &kittycad::types::AuthCallback \
{\n code: Some(\"some-string\".to_string()),\n \
id_token: Some(\"some-string\".to_string()),\n state: \
Some(\"some-string\".to_string()),\n user: \
Some(\"some-string\".to_string()),\n },\n )\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_callback_post<'a>(
&'a self,
provider: crate::types::AccountProvider,
body: &crate::types::AuthCallback,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!(
"{}/{}",
self.client.base_url,
"oauth2/provider/{provider}/callback"
.replace("{provider}", &format!("{}", provider))
),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Get the consent URL and other information for the OAuth 2.0 \
provider.\n\n**Parameters:**\n\n- `callback_url: Option<String>`: The URL to redirect \
back to after we have authenticated.\n- `provider: crate::types::AccountProvider`: \
The provider. (required)\n\n```rust,no_run\nasync fn \
example_oauth2_oauth_2_provider_consent() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2ClientInfo \
= client\n .oauth2()\n .oauth_2_provider_consent(\n \
Some(\"some-string\".to_string()),\n \
kittycad::types::AccountProvider::Github,\n )\n .await?;\n \
println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_provider_consent<'a>(
&'a self,
callback_url: Option<String>,
provider: crate::types::AccountProvider,
) -> Result<crate::types::Oauth2ClientInfo, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"oauth2/provider/{provider}/consent"
.replace("{provider}", &format!("{}", provider))
),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = callback_url {
query_params.push(("callback_url", p));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Exchange an authorization code or refresh token for an OAuth 2.0 access token.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_oauth_2_token() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_token(&kittycad::types::Oauth2TokenRequestForm {\n client_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n code: Some(\"some-string\".to_string()),\n code_verifier: Some(\"some-string\".to_string()),\n grant_type: kittycad::types::Oauth2TokenGrantType::RefreshToken,\n redirect_uri: Some(\"https://example.com/foo/bar\".to_string()),\n refresh_token: Some(\"some-string\".to_string()),\n })\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_token<'a>(
&'a self,
body: &crate::types::Oauth2TokenRequestForm,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "oauth2/token"),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Revoke an OAuth2 token.\n\nThis endpoint is designed to be accessed from an *unauthenticated* API client.\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_oauth_2_token_revoke() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .oauth_2_token_revoke(&kittycad::types::TokenRevokeRequestForm {\n client_id: uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n client_secret: Some(\"some-string\".to_string()),\n token: \"some-string\".to_string(),\n })\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn oauth_2_token_revoke<'a>(
&'a self,
body: &crate::types::TokenRevokeRequestForm,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "oauth2/token/revoke"),
);
req = req.bearer_auth(&self.client.token);
req = req.form(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Verify OAuth account linking and complete the authentication.\n\nThis endpoint is called when a user clicks the verification link sent to their email after attempting to log in with OAuth when an existing account with the same email was found. This endpoint validates the token, links the OAuth account to the user, and creates a session.\n\n**Parameters:**\n\n- `callback_url: Option<String>`: Optional callback URL to redirect to after verification\n- `token: &'astr`: The verification token from the email (required)\n\n```rust,no_run\nasync fn example_oauth2_verify_oauth_account_linking() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n client\n .oauth2()\n .verify_oauth_account_linking(Some(\"some-string\".to_string()), \"some-string\")\n .await?;\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn verify_oauth_account_linking<'a>(
&'a self,
callback_url: Option<String>,
token: &'a str,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url, "oauth2/verify-account-linking"
),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![("token", token.to_string())];
if let Some(p) = callback_url {
query_params.push(("callback_url", p));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List org OAuth apps.\n\nThis endpoint requires authentication by an org member. It lists the organization's active public OAuth apps.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_org_oauth_2_apps_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_org_oauth_2_apps_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_org_oauth_2_apps<'a>(
&'a self,
limit: Option<u32>,
page_token: Option<String>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> Result<crate::types::Oauth2AppResponseResultsPage, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "org/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = page_token {
query_params.push(("page_token", p));
}
if let Some(p) = sort_by {
query_params.push(("sort_by", format!("{}", p)));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List org OAuth apps.\n\nThis endpoint requires authentication by an org member. It lists the organization's active public OAuth apps.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_org_oauth_2_apps_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_org_oauth_2_apps_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_org_oauth_2_apps_stream<'a>(
&'a self,
limit: Option<u32>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> impl futures::Stream<
Item = Result<crate::types::Oauth2AppResponse, crate::types::error::Error>,
> + Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};
use crate::types::paginate::Pagination;
let pagination_url_path = ("org/oauth2/apps").to_string();
let mut pagination_query_params: Vec<(&str, String)> = Vec::new();
if let Some(p) = limit.as_ref() {
pagination_query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = sort_by.as_ref() {
pagination_query_params.push(("sort_by", format!("{}", p)));
}
self.list_org_oauth_2_apps(limit, None, sort_by)
.map_ok(move |result| {
let items = futures::stream::iter(result.items().into_iter().map(Ok));
let next_pages = futures::stream::try_unfold(
(None, result),
move |(prev_page_token, new_result)| {
let pagination_url_path = pagination_url_path.clone();
let pagination_query_params = pagination_query_params.clone();
async move {
if new_result.has_more_pages()
&& !new_result.items().is_empty()
&& prev_page_token != new_result.next_page_token()
{
async {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
pagination_url_path.clone()
),
);
req = req.bearer_auth(&self.client.token);
let query_params = pagination_query_params.clone();
req = req.query(&query_params);
let mut request = req.build()?;
request =
new_result.next_page_with_param(request, "page_token")?;
let resp = self.client.client.execute(request).await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(
text.to_string(),
err,
),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
.map_ok(|result: crate::types::Oauth2AppResponseResultsPage| {
Some((
futures::stream::iter(result.items().into_iter().map(Ok)),
(new_result.next_page_token(), result),
))
})
.await
} else {
Ok(None)
}
}
},
)
.try_flatten();
items.chain(next_pages)
})
.try_flatten_stream()
.boxed()
}
#[doc = "Create an org OAuth app.\n\nThis endpoint requires authentication by an org admin. It creates an active public OAuth app owned by the authenticated organization.\n\n```rust,no_run\nasync fn example_oauth2_create_org_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .create_org_oauth_2_app(&kittycad::types::CreateOAuth2AppRequest {\n grant_types: Some(vec![kittycad::types::Oauth2AppGrantType::RefreshToken]),\n mode: Some(kittycad::types::Oauth2AppMode::Production),\n name: \"some-string\".to_string(),\n redirect_uris: Some(vec![\"https://example.com/foo/bar\".to_string()]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_org_oauth_2_app<'a>(
&'a self,
body: &crate::types::CreateOAuth2AppRequest,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "org/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Get an org OAuth app.\n\nThis endpoint requires authentication by an org member. It returns the organization's active public OAuth app by client ID.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth client identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_get_org_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .get_org_oauth_2_app(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_org_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"org/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Update an org OAuth app.\n\nThis endpoint requires authentication by an org admin. It updates the configuration of the organization's active public OAuth app.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth client identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_update_org_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .update_org_oauth_2_app(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n &kittycad::types::UpdateOAuth2AppRequest {\n grant_types: Some(vec![kittycad::types::Oauth2AppGrantType::RefreshToken]),\n mode: Some(kittycad::types::Oauth2AppMode::Production),\n name: Some(\"some-string\".to_string()),\n redirect_uris: Some(vec![\"https://example.com/foo/bar\".to_string()]),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn update_org_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
body: &crate::types::UpdateOAuth2AppRequest,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::PUT,
format!(
"{}/{}",
self.client.base_url,
"org/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Delete an org OAuth app.\n\nThis endpoint requires authentication by an org admin. It \
deactivates the organization's active public OAuth app.\n\n**Parameters:**\n\n- \
`client_id: uuid::Uuid`: The OAuth client identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_oauth2_delete_org_oauth_2_app() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.delete_org_oauth_2_app(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn delete_org_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!(
"{}/{}",
self.client.base_url,
"org/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List OAuth 2.0 apps owned by an organization.\n\nThis endpoint requires Zoo admin authentication. It returns the target organization's active OAuth apps for admin dashboard inspection.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The organization ID. (required)\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_list_oauth_2_apps_for_any_org() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponseResultsPage = client\n .oauth2()\n .list_oauth_2_apps_for_any_org(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n Some(4 as u32),\n Some(\"some-string\".to_string()),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n\n\n/// - OR -\n\n/// Get a stream of results.\n///\n/// This allows you to paginate through all the items.\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_oauth_2_apps_for_any_org_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_oauth_2_apps_for_any_org_stream(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_oauth_2_apps_for_any_org<'a>(
&'a self,
id: uuid::Uuid,
limit: Option<u32>,
page_token: Option<String>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> Result<crate::types::Oauth2AppResponseResultsPage, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"orgs/{id}/oauth2/apps".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = page_token {
query_params.push(("page_token", p));
}
if let Some(p) = sort_by {
query_params.push(("sort_by", format!("{}", p)));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List OAuth 2.0 apps owned by an organization.\n\nThis endpoint requires Zoo admin authentication. It returns the target organization's active OAuth apps for admin dashboard inspection.\n\n**Parameters:**\n\n- `id: uuid::Uuid`: The organization ID. (required)\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_list_oauth_2_apps_for_any_org() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponseResultsPage = client\n .oauth2()\n .list_oauth_2_apps_for_any_org(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n Some(4 as u32),\n Some(\"some-string\".to_string()),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n\n\n/// - OR -\n\n/// Get a stream of results.\n///\n/// This allows you to paginate through all the items.\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_oauth_2_apps_for_any_org_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_oauth_2_apps_for_any_org_stream(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_oauth_2_apps_for_any_org_stream<'a>(
&'a self,
id: uuid::Uuid,
limit: Option<u32>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> impl futures::Stream<
Item = Result<crate::types::Oauth2AppResponse, crate::types::error::Error>,
> + Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};
use crate::types::paginate::Pagination;
let pagination_url_path =
("orgs/{id}/oauth2/apps".replace("{id}", &format!("{}", id))).to_string();
let mut pagination_query_params: Vec<(&str, String)> = Vec::new();
if let Some(p) = limit.as_ref() {
pagination_query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = sort_by.as_ref() {
pagination_query_params.push(("sort_by", format!("{}", p)));
}
self.list_oauth_2_apps_for_any_org(id, limit, None, sort_by)
.map_ok(move |result| {
let items = futures::stream::iter(result.items().into_iter().map(Ok));
let next_pages = futures::stream::try_unfold(
(None, result),
move |(prev_page_token, new_result)| {
let pagination_url_path = pagination_url_path.clone();
let pagination_query_params = pagination_query_params.clone();
async move {
if new_result.has_more_pages()
&& !new_result.items().is_empty()
&& prev_page_token != new_result.next_page_token()
{
async {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
pagination_url_path.clone()
),
);
req = req.bearer_auth(&self.client.token);
let query_params = pagination_query_params.clone();
req = req.query(&query_params);
let mut request = req.build()?;
request =
new_result.next_page_with_param(request, "page_token")?;
let resp = self.client.client.execute(request).await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(
text.to_string(),
err,
),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
.map_ok(|result: crate::types::Oauth2AppResponseResultsPage| {
Some((
futures::stream::iter(result.items().into_iter().map(Ok)),
(new_result.next_page_token(), result),
))
})
.await
} else {
Ok(None)
}
}
},
)
.try_flatten();
items.chain(next_pages)
})
.try_flatten_stream()
.boxed()
}
#[doc = "List personal OAuth apps.\n\nThis endpoint requires authentication by any Zoo user. It lists the authenticated user's active public OAuth apps.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_user_oauth_2_apps_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_user_oauth_2_apps_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_user_oauth_2_apps<'a>(
&'a self,
limit: Option<u32>,
page_token: Option<String>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> Result<crate::types::Oauth2AppResponseResultsPage, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "user/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = page_token {
query_params.push(("page_token", p));
}
if let Some(p) = sort_by {
query_params.push(("sort_by", format!("{}", p)));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List personal OAuth apps.\n\nThis endpoint requires authentication by any Zoo user. It lists the authenticated user's active public OAuth apps.\n\n**Parameters:**\n\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_user_oauth_2_apps_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_user_oauth_2_apps_stream(\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_user_oauth_2_apps_stream<'a>(
&'a self,
limit: Option<u32>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> impl futures::Stream<
Item = Result<crate::types::Oauth2AppResponse, crate::types::error::Error>,
> + Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};
use crate::types::paginate::Pagination;
let pagination_url_path = ("user/oauth2/apps").to_string();
let mut pagination_query_params: Vec<(&str, String)> = Vec::new();
if let Some(p) = limit.as_ref() {
pagination_query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = sort_by.as_ref() {
pagination_query_params.push(("sort_by", format!("{}", p)));
}
self.list_user_oauth_2_apps(limit, None, sort_by)
.map_ok(move |result| {
let items = futures::stream::iter(result.items().into_iter().map(Ok));
let next_pages = futures::stream::try_unfold(
(None, result),
move |(prev_page_token, new_result)| {
let pagination_url_path = pagination_url_path.clone();
let pagination_query_params = pagination_query_params.clone();
async move {
if new_result.has_more_pages()
&& !new_result.items().is_empty()
&& prev_page_token != new_result.next_page_token()
{
async {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
pagination_url_path.clone()
),
);
req = req.bearer_auth(&self.client.token);
let query_params = pagination_query_params.clone();
req = req.query(&query_params);
let mut request = req.build()?;
request =
new_result.next_page_with_param(request, "page_token")?;
let resp = self.client.client.execute(request).await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(
text.to_string(),
err,
),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
.map_ok(|result: crate::types::Oauth2AppResponseResultsPage| {
Some((
futures::stream::iter(result.items().into_iter().map(Ok)),
(new_result.next_page_token(), result),
))
})
.await
} else {
Ok(None)
}
}
},
)
.try_flatten();
items.chain(next_pages)
})
.try_flatten_stream()
.boxed()
}
#[doc = "Create a personal OAuth app.\n\nThis endpoint requires authentication by any Zoo user. It creates an active public OAuth app owned by the authenticated user.\n\n```rust,no_run\nasync fn example_oauth2_create_user_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .create_user_oauth_2_app(&kittycad::types::CreateOAuth2AppRequest {\n grant_types: Some(vec![kittycad::types::Oauth2AppGrantType::RefreshToken]),\n mode: Some(kittycad::types::Oauth2AppMode::Production),\n name: \"some-string\".to_string(),\n redirect_uris: Some(vec![\"https://example.com/foo/bar\".to_string()]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn create_user_oauth_2_app<'a>(
&'a self,
body: &crate::types::CreateOAuth2AppRequest,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::POST,
format!("{}/{}", self.client.base_url, "user/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Get a personal OAuth app.\n\nThis endpoint requires authentication by any Zoo user. It returns the authenticated user's active public OAuth app by client ID.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth client identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_get_user_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .get_user_oauth_2_app(uuid::Uuid::from_str(\n \"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn get_user_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"user/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Update a personal OAuth app.\n\nThis endpoint requires authentication by any Zoo user. It updates the configuration of the authenticated user's active public OAuth app.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth client identifier. (required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn example_oauth2_update_user_oauth_2_app() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let result: kittycad::types::Oauth2AppResponse = client\n .oauth2()\n .update_user_oauth_2_app(\n uuid::Uuid::from_str(\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\")?,\n &kittycad::types::UpdateOAuth2AppRequest {\n grant_types: Some(vec![kittycad::types::Oauth2AppGrantType::RefreshToken]),\n mode: Some(kittycad::types::Oauth2AppMode::Production),\n name: Some(\"some-string\".to_string()),\n redirect_uris: Some(vec![\"https://example.com/foo/bar\".to_string()]),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn update_user_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
body: &crate::types::UpdateOAuth2AppRequest,
) -> Result<crate::types::Oauth2AppResponse, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::PUT,
format!(
"{}/{}",
self.client.base_url,
"user/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "Delete a personal OAuth app.\n\nThis endpoint requires authentication by any Zoo \
user. It deactivates the authenticated user's active public OAuth \
app.\n\n**Parameters:**\n\n- `client_id: uuid::Uuid`: The OAuth client identifier. \
(required)\n\n```rust,no_run\nuse std::str::FromStr;\nasync fn \
example_oauth2_delete_user_oauth_2_app() -> anyhow::Result<()> {\n let client = \
kittycad::Client::new_from_env();\n client\n .oauth2()\n \
.delete_user_oauth_2_app(uuid::Uuid::from_str(\n \
\"d9797f8d-9ad6-4e08-90d7-2ec17e13471c\",\n )?)\n .await?;\n \
Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn delete_user_oauth_2_app<'a>(
&'a self,
client_id: uuid::Uuid,
) -> Result<(), crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::DELETE,
format!(
"{}/{}",
self.client.base_url,
"user/oauth2/apps/{client_id}".replace("{client_id}", &format!("{}", client_id))
),
);
req = req.bearer_auth(&self.client.token);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
Ok(())
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List OAuth 2.0 apps owned by a user.\n\nThis endpoint requires Zoo admin authentication. It returns the target user's active OAuth apps so the admin dashboard can inspect them without impersonating the user.\n\n**Parameters:**\n\n- `id: &'astr`: The user's identifier (uuid or email). (required)\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_oauth_2_apps_for_any_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_oauth_2_apps_for_any_user_stream(\n \"some-string\",\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
pub async fn list_oauth_2_apps_for_any_user<'a>(
&'a self,
id: &'a str,
limit: Option<u32>,
page_token: Option<String>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> Result<crate::types::Oauth2AppResponseResultsPage, crate::types::error::Error> {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
"users/{id}/oauth2/apps".replace("{id}", id)
),
);
req = req.bearer_auth(&self.client.token);
let mut query_params = vec![];
if let Some(p) = limit {
query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = page_token {
query_params.push(("page_token", p));
}
if let Some(p) = sort_by {
query_params.push(("sort_by", format!("{}", p)));
}
req = req.query(&query_params);
let resp = req.send().await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(text.to_string(), err),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
#[doc = "List OAuth 2.0 apps owned by a user.\n\nThis endpoint requires Zoo admin authentication. It returns the target user's active OAuth apps so the admin dashboard can inspect them without impersonating the user.\n\n**Parameters:**\n\n- `id: &'astr`: The user's identifier (uuid or email). (required)\n- `limit: Option<u32>`: Maximum number of items returned by a single call\n- `page_token: Option<String>`: Token returned by previous call to retrieve the subsequent page\n- `sort_by: Option<crate::types::CreatedAtSortMode>`\n\n```rust,no_run\nuse futures_util::TryStreamExt;\nasync fn example_oauth2_list_oauth_2_apps_for_any_user_stream() -> anyhow::Result<()> {\n let client = kittycad::Client::new_from_env();\n let mut oauth2 = client.oauth2();\n let mut stream = oauth2.list_oauth_2_apps_for_any_user_stream(\n \"some-string\",\n Some(4 as u32),\n Some(kittycad::types::CreatedAtSortMode::CreatedAtDescending),\n );\n loop {\n match stream.try_next().await {\n Ok(Some(item)) => {\n println!(\"{:?}\", item);\n }\n Ok(None) => {\n break;\n }\n Err(err) => {\n return Err(err.into());\n }\n }\n }\n\n Ok(())\n}\n```"]
#[tracing::instrument]
#[cfg(not(feature = "js"))]
pub fn list_oauth_2_apps_for_any_user_stream<'a>(
&'a self,
id: &'a str,
limit: Option<u32>,
sort_by: Option<crate::types::CreatedAtSortMode>,
) -> impl futures::Stream<
Item = Result<crate::types::Oauth2AppResponse, crate::types::error::Error>,
> + Unpin
+ '_ {
use futures::{StreamExt, TryFutureExt, TryStreamExt};
use crate::types::paginate::Pagination;
let pagination_url_path = ("users/{id}/oauth2/apps".replace("{id}", id)).to_string();
let mut pagination_query_params: Vec<(&str, String)> = Vec::new();
if let Some(p) = limit.as_ref() {
pagination_query_params.push(("limit", format!("{}", p)));
}
if let Some(p) = sort_by.as_ref() {
pagination_query_params.push(("sort_by", format!("{}", p)));
}
self.list_oauth_2_apps_for_any_user(id, limit, None, sort_by)
.map_ok(move |result| {
let items = futures::stream::iter(result.items().into_iter().map(Ok));
let next_pages = futures::stream::try_unfold(
(None, result),
move |(prev_page_token, new_result)| {
let pagination_url_path = pagination_url_path.clone();
let pagination_query_params = pagination_query_params.clone();
async move {
if new_result.has_more_pages()
&& !new_result.items().is_empty()
&& prev_page_token != new_result.next_page_token()
{
async {
let mut req = self.client.client.request(
http::Method::GET,
format!(
"{}/{}",
self.client.base_url,
pagination_url_path.clone()
),
);
req = req.bearer_auth(&self.client.token);
let query_params = pagination_query_params.clone();
req = req.query(&query_params);
let mut request = req.build()?;
request =
new_result.next_page_with_param(request, "page_token")?;
let resp = self.client.client.execute(request).await?;
let status = resp.status();
if status.is_success() {
let text = resp.text().await.unwrap_or_default();
serde_json::from_str(&text).map_err(|err| {
crate::types::error::Error::from_serde_error(
format_serde_error::SerdeError::new(
text.to_string(),
err,
),
status,
)
})
} else {
let text = resp.text().await.unwrap_or_default();
Err(crate::types::error::Error::Server {
body: text.to_string(),
status,
})
}
}
.map_ok(|result: crate::types::Oauth2AppResponseResultsPage| {
Some((
futures::stream::iter(result.items().into_iter().map(Ok)),
(new_result.next_page_token(), result),
))
})
.await
} else {
Ok(None)
}
}
},
)
.try_flatten();
items.chain(next_pages)
})
.try_flatten_stream()
.boxed()
}
}