orvanta_api/apis/
mcp_oauth_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DenyMcpOAuthServerAuthorizationError {
22 Status400(),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DiscoverMcpOAuthError {
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetMcpOAuthClientMetadataError {
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum McpOAuthCallbackError {
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum RefreshMcpOAuthError {
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum StartMcpOAuthPopupError {
58 UnknownValue(serde_json::Value),
59}
60
61
62pub async fn deny_mcp_o_auth_server_authorization(configuration: &configuration::Configuration, deny_mcp_o_auth_server_authorization_request: models::DenyMcpOAuthServerAuthorizationRequest) -> Result<models::DenyMcpOAuthServerAuthorization200Response, Error<DenyMcpOAuthServerAuthorizationError>> {
64 let local_var_configuration = configuration;
65
66 let local_var_client = &local_var_configuration.client;
67
68 let local_var_uri_str = format!("{}/mcp/gateway/oauth/server/deny", local_var_configuration.base_path);
69 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
70
71 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
72 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
73 }
74 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
75 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
76 };
77 local_var_req_builder = local_var_req_builder.json(&deny_mcp_o_auth_server_authorization_request);
78
79 let local_var_req = local_var_req_builder.build()?;
80 let local_var_resp = local_var_client.execute(local_var_req).await?;
81
82 let local_var_status = local_var_resp.status();
83 let local_var_content = local_var_resp.text().await?;
84
85 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
86 crate::from_str_patched(&local_var_content).map_err(Error::from)
87 } else {
88 let local_var_entity: Option<DenyMcpOAuthServerAuthorizationError> = crate::from_str_patched(&local_var_content).ok();
89 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
90 Err(Error::ResponseError(local_var_error))
91 }
92}
93
94pub async fn discover_mcp_o_auth(configuration: &configuration::Configuration, discover_mcp_o_auth_request: models::DiscoverMcpOAuthRequest) -> Result<models::DiscoverMcpOAuth200Response, Error<DiscoverMcpOAuthError>> {
95 let local_var_configuration = configuration;
96
97 let local_var_client = &local_var_configuration.client;
98
99 let local_var_uri_str = format!("{}/mcp/oauth/discover", local_var_configuration.base_path);
100 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
101
102 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104 }
105 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
106 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
107 };
108 local_var_req_builder = local_var_req_builder.json(&discover_mcp_o_auth_request);
109
110 let local_var_req = local_var_req_builder.build()?;
111 let local_var_resp = local_var_client.execute(local_var_req).await?;
112
113 let local_var_status = local_var_resp.status();
114 let local_var_content = local_var_resp.text().await?;
115
116 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117 crate::from_str_patched(&local_var_content).map_err(Error::from)
118 } else {
119 let local_var_entity: Option<DiscoverMcpOAuthError> = crate::from_str_patched(&local_var_content).ok();
120 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
121 Err(Error::ResponseError(local_var_error))
122 }
123}
124
125pub async fn get_mcp_o_auth_client_metadata(configuration: &configuration::Configuration, ) -> Result<models::GetMcpOAuthClientMetadata200Response, Error<GetMcpOAuthClientMetadataError>> {
127 let local_var_configuration = configuration;
128
129 let local_var_client = &local_var_configuration.client;
130
131 let local_var_uri_str = format!("{}/mcp/oauth/client-metadata.json", local_var_configuration.base_path);
132 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
133
134 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
136 }
137
138 let local_var_req = local_var_req_builder.build()?;
139 let local_var_resp = local_var_client.execute(local_var_req).await?;
140
141 let local_var_status = local_var_resp.status();
142 let local_var_content = local_var_resp.text().await?;
143
144 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145 crate::from_str_patched(&local_var_content).map_err(Error::from)
146 } else {
147 let local_var_entity: Option<GetMcpOAuthClientMetadataError> = crate::from_str_patched(&local_var_content).ok();
148 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
149 Err(Error::ResponseError(local_var_error))
150 }
151}
152
153pub async fn mcp_o_auth_callback(configuration: &configuration::Configuration, state: &str, code: Option<&str>, error: Option<&str>, error_description: Option<&str>) -> Result<String, Error<McpOAuthCallbackError>> {
155 let local_var_configuration = configuration;
156
157 let local_var_client = &local_var_configuration.client;
158
159 let local_var_uri_str = format!("{}/mcp/oauth/callback", local_var_configuration.base_path);
160 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
161
162 if let Some(ref local_var_str) = code {
163 local_var_req_builder = local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
164 }
165 local_var_req_builder = local_var_req_builder.query(&[("state", &state.to_string())]);
166 if let Some(ref local_var_str) = error {
167 local_var_req_builder = local_var_req_builder.query(&[("error", &local_var_str.to_string())]);
168 }
169 if let Some(ref local_var_str) = error_description {
170 local_var_req_builder = local_var_req_builder.query(&[("error_description", &local_var_str.to_string())]);
171 }
172 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174 }
175
176 let local_var_req = local_var_req_builder.build()?;
177 let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179 let local_var_status = local_var_resp.status();
180 let local_var_content = local_var_resp.text().await?;
181
182 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183 crate::from_str_patched(&local_var_content).map_err(Error::from)
184 } else {
185 let local_var_entity: Option<McpOAuthCallbackError> = crate::from_str_patched(&local_var_content).ok();
186 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
187 Err(Error::ResponseError(local_var_error))
188 }
189}
190
191pub async fn refresh_mcp_o_auth(configuration: &configuration::Configuration, refresh_mcp_o_auth_request: models::RefreshMcpOAuthRequest) -> Result<models::RefreshMcpOAuth200Response, Error<RefreshMcpOAuthError>> {
193 let local_var_configuration = configuration;
194
195 let local_var_client = &local_var_configuration.client;
196
197 let local_var_uri_str = format!("{}/mcp/oauth/refresh", local_var_configuration.base_path);
198 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
199
200 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
202 }
203 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
204 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205 };
206 local_var_req_builder = local_var_req_builder.json(&refresh_mcp_o_auth_request);
207
208 let local_var_req = local_var_req_builder.build()?;
209 let local_var_resp = local_var_client.execute(local_var_req).await?;
210
211 let local_var_status = local_var_resp.status();
212 let local_var_content = local_var_resp.text().await?;
213
214 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215 crate::from_str_patched(&local_var_content).map_err(Error::from)
216 } else {
217 let local_var_entity: Option<RefreshMcpOAuthError> = crate::from_str_patched(&local_var_content).ok();
218 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
219 Err(Error::ResponseError(local_var_error))
220 }
221}
222
223pub async fn start_mcp_o_auth_popup(configuration: &configuration::Configuration, mcp_server_url: &str, workspace_id: &str, scopes: Option<&str>) -> Result<(), Error<StartMcpOAuthPopupError>> {
225 let local_var_configuration = configuration;
226
227 let local_var_client = &local_var_configuration.client;
228
229 let local_var_uri_str = format!("{}/mcp/oauth/start", local_var_configuration.base_path);
230 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
231
232 local_var_req_builder = local_var_req_builder.query(&[("mcp_server_url", &mcp_server_url.to_string())]);
233 local_var_req_builder = local_var_req_builder.query(&[("workspace_id", &workspace_id.to_string())]);
234 if let Some(ref local_var_str) = scopes {
235 local_var_req_builder = local_var_req_builder.query(&[("scopes", &local_var_str.to_string())]);
236 }
237 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
238 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
239 }
240 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
241 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
242 };
243
244 let local_var_req = local_var_req_builder.build()?;
245 let local_var_resp = local_var_client.execute(local_var_req).await?;
246
247 let local_var_status = local_var_resp.status();
248 let local_var_content = local_var_resp.text().await?;
249
250 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251 Ok(())
252 } else {
253 let local_var_entity: Option<StartMcpOAuthPopupError> = crate::from_str_patched(&local_var_content).ok();
254 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255 Err(Error::ResponseError(local_var_error))
256 }
257}
258