use serde::{Deserialize, Serialize};
use super::types::ClientType;
use super::{ManagementClient, Result};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OauthClientEnvelope {
pub id: String,
pub client_id: String,
pub client_name: String,
pub client_type: ClientType,
pub redirect_uris: Vec<String>,
pub allowed_scopes: Vec<String>,
pub allowed_grant_types: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OauthClientListResponse {
pub data: Vec<OauthClientEnvelope>,
}
#[derive(Debug, Clone, Serialize)]
pub struct RegisterOauthClientRequest {
pub client_name: String,
pub client_type: ClientType,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub redirect_uris: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub allowed_scopes: Vec<String>,
pub allowed_grant_types: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterOauthClientResponse {
pub id: String,
pub client_id: String,
pub client_secret: Option<String>,
pub client_name: String,
pub client_type: ClientType,
pub redirect_uris: Vec<String>,
pub allowed_scopes: Vec<String>,
pub allowed_grant_types: Vec<String>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct UpdateOauthClientRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub client_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_uris: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_scopes: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_grant_types: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteOauthClientResponse {
pub deleted: bool,
}
impl ManagementClient {
pub async fn list_oauth_clients(&self) -> Result<OauthClientListResponse> {
let path = self.namespaced("/oauth/clients")?;
self.get_json(&path).await
}
pub async fn register_oauth_client(
&self,
body: &RegisterOauthClientRequest,
) -> Result<RegisterOauthClientResponse> {
let path = self.namespaced("/oauth/clients")?;
self.post_json(&path, body).await
}
pub async fn update_oauth_client(
&self,
client_id: &str,
body: &UpdateOauthClientRequest,
) -> Result<OauthClientEnvelope> {
let path = self.namespaced(&format!("/oauth/clients/{client_id}"))?;
self.put_json(&path, body).await
}
pub async fn delete_oauth_client(&self, client_id: &str) -> Result<DeleteOauthClientResponse> {
let path = self.namespaced(&format!("/oauth/clients/{client_id}"))?;
self.delete_json(&path).await
}
}