use anyhow::Result;
use crate::Client;
#[derive(Clone, Debug)]
pub struct Oauth2 {
pub client: Client,
}
impl Oauth2 {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Self { client }
}
#[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::Microsoft,\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::Microsoft,\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::Microsoft,\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 = "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;
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)| 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, "org/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
let mut request = req.build()?;
request = new_result.next_page(request)?;
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 device-flow 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 name: \
\"some-string\".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 name 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 name: \
\"some-string\".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;
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)| 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,
"orgs/{id}/oauth2/apps".replace("{id}", &format!("{}", id))
),
);
req = req.bearer_auth(&self.client.token);
let mut request = req.build()?;
request = new_result.next_page(request)?;
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;
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)| 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, "user/oauth2/apps"),
);
req = req.bearer_auth(&self.client.token);
let mut request = req.build()?;
request = new_result.next_page(request)?;
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 device-flow 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 \
name: \"some-string\".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 name 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 name: \
\"some-string\".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;
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)| 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,
"users/{id}/oauth2/apps".replace("{id}", id)
),
);
req = req.bearer_auth(&self.client.token);
let mut request = req.build()?;
request = new_result.next_page(request)?;
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()
}
}