1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//! # Microsoft Graph API Client in Rust
//! graph-rs-sdk is an API client for Microsoft Graph V1.0 and Graph Beta.
//!
//! Installation and basic usage can be found below and there are extensive examples in the example's directory
//! on [GitHub](https://github.com/sreeise/graph-rs-sdk).
//!
//! ## What APIs are available
//!
//! The APIs available are generated from Microsoft's msgraph-metadata repository which stores OpenApi configs for the
//! Graph API. There may be some requests and/or API not yet included in this project but in general most of them are
//! implemented.
//!
//! ## Feature requests or Bug reports.
//!
//! For bug reports please file an issue on [GitHub](https://github.com/sreeise/graph-rs-sdk)
//! and a response or fix will be given as soon as possible.
//!
//! The [Discussions](https://github.com/sreeise/graph-rs-sdk/discussions) tab on
//! [GitHub](https://github.com/sreeise/graph-rs-sdk/discussions) is enabled so feel free to stop by
//! there with any questions or feature requests as well. For bugs, please file an issue first. Other
//! than that feel free to ask questions, provide tips to others, and talk about the project in general.
//!
//! ## Use
//! The client is async by default and it is recommended to use
//! tokio as the runtime. Tokio is what is used internally and what the project
//! is tested with.
//!
//! ```rust,ignore
//! use graph_rs_sdk::*;
//!
//! #[tokio::main]
//! async fn main() -> GraphResult<()> {
//!     let client =  Graph::new("ACCESS_TOKEN");
//!
//!     let response = client.users()
//!         .list_user()
//!         .send()
//!         .await?;
//!
//!     println!("{response:#?}");
//!
//!     let body: serde_json::Value = response.json().await?;
//!     println!("{body:#?}");
//!
//!     Ok(())
//! }
//! ```
//! ### Using the blocking client
//!
//! The blocking client can be used by calling `into_blocking()` on a request.
//!
//! ```rust,ignore
//! use graph_rs_sdk::*;
//!
//! fn main() -> GraphResult<()> {
//!     let client =  Graph::new("ACCESS_TOKEN");
//!
//!     let response = client.users()
//!         .list_user()
//!         .into_blocking()
//!         .send()?;
//!
//!     println!("{response:#?}");
//!
//!     let body: serde_json::Value = response.json()?;
//!     println!("{body:#?}");
//!
//!     Ok(())
//! }
//! ```
//!
//! ### Use the Graph version one or beta Api
//! v1() refers to the endpoint for version 1 of the Microsoft graph API. You can also
//! use the beta() method which uses the Microsoft graph beta API endpoint or use
//! custom_endpoint() for those graph APIs that have custom endpoints such as in
//! countries or governments with their own endpoint.
//!
//! The Graph client must be mutable in order to change from v1 to beta or a custom endpoint.
//!
//! #### Beta
//! ```rust,ignore
//! use graph_rs_sdk::*;
//!
//! #[tokio::main]
//! async fn main() -> GraphResult<()> {
//!     let mut client =  Graph::new("ACCESS_TOKEN");
//!
//!     let response = client.beta()
//!         .users()
//!         .list_user()
//!         .send()
//!         .await?;
//!
//!     println!("{response:#?}");
//!
//!     let body: serde_json::Value = response.json().await?;
//!     println!("{body:#?}");
//!
//!     Ok(())
//! }
//! ```
//!
//! #### Custom Endpoint
//! ```rust,ignore
//! use graph_rs_sdk::*;
//!
//! #[tokio::main]
//! async fn main() -> GraphResult<()> {
//!     let mut client =  Graph::new("ACCESS_TOKEN");
//!
//!     let response = client.custom_endpoint("https://api.microsoft.com/api")
//!         .users()
//!         .list_user()
//!         .send()
//!         .await?;
//!
//!     println!("{response:#?}");
//!
//!     let body: serde_json::Value = response.json().await?;
//!     println!("{body:#?}");
//!
//!     Ok(())
//! }
//! ```
//!
//! #### Custom endpoint using `use_endpoint()`
//! ```rust,ignore
//! use graph_rs_sdk::*;
//!
//! #[tokio::main]
//! async fn main() -> GraphResult<()> {
//!     let mut client =  Graph::new("ACCESS_TOKEN");
//!     client.use_endpoint("https://graph.microsoft.com");
//!
//!     let response = client
//!         .users()
//!         .list_user()
//!         .send()
//!         .await?;
//!
//!     println!("{response:#?}");
//!
//!     let body: serde_json::Value = response.json().await?;
//!     println!("{body:#?}");
//!
//!     Ok(())
//! }
//! ```
//!
//! - For more information and examples please see the repository on
//! [GitHub](https://github.com/sreeise/graph-rs-sdk)
//! - If you run into issues related to graph-rs specifically please
//! file an issue on [GitHub](https://github.com/sreeise/graph-rs-sdk)
//!
//! # OAuth
//!
//! OAuth client implementing the OAuth 2.0 and OpenID Connect protocols on Microsoft identity platform
//!
//! Purpose built as OAuth client for Microsoft Graph and the [graph-rs-sdk](https://crates.io/crates/graph-rs-sdk) project.
//! This project can however be used outside [graph-rs-sdk](https://crates.io/crates/graph-rs-sdk) as an OAuth client
//! for Microsoft Identity Platform.
//!
//! ### Supported Authorization Flows
//!
//! #### Microsoft OneDrive and SharePoint
//!
//! - [Token Flow](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/graph-oauth?view=odsp-graph-online#token-flow)
//! - [Code Flow](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/graph-oauth?view=odsp-graph-online#code-flow)
//!
//! #### Microsoft Identity Platform
//!
//! - [Authorization Code Grant](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
//! - [Authorization Code Grant PKCE](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
//! - [Open ID Connect](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc)
//! - [Implicit Grant](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow)
//! - [Device Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-device-code)
//! - [Client Credentials](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow)
//! - [Resource Owner Password Credentials](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc)
//!
//! # Example
//! ```
//! use graph_rs_sdk::oauth::OAuth;
//! let mut oauth = OAuth::new();
//! oauth
//!     .client_id("<YOUR_CLIENT_ID>")
//!     .client_secret("<YOUR_CLIENT_SECRET>")
//!     .add_scope("files.read")
//!     .add_scope("files.readwrite")
//!     .add_scope("files.read.all")
//!     .add_scope("files.readwrite.all")
//!     .add_scope("offline_access")
//!     .redirect_uri("http://localhost:8000/redirect")
//!     .authorize_url("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
//!     .access_token_url("https://login.microsoftonline.com/common/oauth2/v2.0/token")
//!     .refresh_token_url("https://login.microsoftonline.com/common/oauth2/v2.0/token")
//!     .response_type("code")
//!     .logout_url("https://login.microsoftonline.com/common/oauth2/v2.0/logout")
//!     .post_logout_redirect_uri("http://localhost:8000/redirect");
//! ```
//! Get the access code for the authorization code grant by sending the user to
//! log in using their browser.
//! ```rust,ignore
//! # use graph_rs_sdk::oauth::OAuth;
//! # let mut oauth = OAuth::new();
//! let mut request = oauth.build().authorization_code_grant();
//! let _ = request.browser_authorization().open();
//! ```
//!
//! The access code will be appended to the url on redirect. Pass
//! this code to the OAuth instance:
//! ```rust,ignore
//! # use graph_rs_sdk::oauth::OAuth;
//! # let mut oauth = OAuth::new();
//! oauth.access_code("<ACCESS CODE>");
//! ```
//!
//! Perform an authorization code grant request for an access token:
//! ```rust,ignore
//! # use graph_rs_sdk::oauth::{AccessToken, OAuth};
//! # let mut oauth = OAuth::new();
//! let mut request = oauth.build().authorization_code_grant();
//!
//! let response = request.access_token().send()?;
//! println!("{:#?}", access_token);
//!
//! if response.status().is_success() {
//!     let mut access_token: AccessToken = response.json()?;
//!
//!     let jwt = access_token.jwt();
//!     println!("{jwt:#?}");
//!
//!     // Store in OAuth to make requests for refresh tokens.
//!     oauth.access_token(access_token);
//! } else {
//!     // See if Microsoft Graph returned an error in the Response body
//!     let result: reqwest::Result<serde_json::Value> = response.json();
//!     println!("{:#?}", result);
//! }
//!
//! ```

// mod client needs to stay on top of all other
// client mod declarations for macro use.
/// Main Graph client.
#[macro_use]
pub(crate) mod client;
pub mod admin;
pub mod agreement_acceptances;
pub mod agreements;
pub mod app_catalogs;
pub mod applications;
pub mod audit_logs;
pub mod authentication_method_configurations;
pub mod authentication_methods_policy;
pub mod batch;
pub mod branding;
pub mod certificate_based_auth_configuration;
pub mod chats;
pub mod communications;
pub mod contracts;
pub mod data_policy_operations;
pub mod default_drive;
pub mod device_app_management;
pub mod device_management;
pub mod directory;
pub mod directory_objects;
pub mod directory_role_templates;
pub mod directory_roles;
pub mod domain_dns_records;
pub mod domains;
pub mod drives;
pub mod education;
pub mod extended_properties;
pub mod group_lifecycle_policies;
pub mod groups;
pub mod identity;
pub mod identity_governance;
pub mod identity_providers;
pub mod invitations;
pub mod me;
pub mod oauth2_permission_grants;
pub mod organization;
pub mod permission_grants;
pub mod places;
pub mod planner;
pub mod policies;
pub mod reports;
pub mod schema_extensions;
pub mod service_principals;
pub mod sites;
pub mod subscribed_skus;
pub mod subscriptions;
pub mod teams;
pub mod teams_templates;
pub mod teamwork;
pub mod users;

pub static GRAPH_URL: &str = "https://graph.microsoft.com/v1.0";
pub static GRAPH_URL_BETA: &str = "https://graph.microsoft.com/beta";

pub use crate::client::Graph;
pub use graph_error::{GraphFailure, GraphResult};
pub use graph_http::api_impl::{GraphClientConfiguration, ODataQuery};

/// Reexport of graph-oauth crate.
pub mod oauth {
    pub use graph_oauth::jwt;
    pub use graph_oauth::oauth::*;
}

pub mod http {
    pub use graph_http::api_impl::{
        BodyRead, FileConfig, PagingResponse, PagingResult, UploadSession,
    };
    pub use graph_http::traits::{
        AsyncIterator, HttpResponseBuilderExt, HttpResponseExt, ODataDeltaLink, ODataDownloadLink,
        ODataMetadataLink, ODataNextLink, ODataQuery, ResponseBlockingExt, ResponseExt,
        UploadSessionLink,
    };
    pub use reqwest::tls::Version;
    pub use reqwest::{Body, Method};

    pub mod blocking {
        pub use graph_http::api_impl::UploadSessionBlocking;
        pub use reqwest::blocking::Body;
    }
}

/// Reexport of graph-error crate.
pub mod error {
    pub use graph_error::*;
}

/// Reexport of reqwest headers for use with API requests.
pub mod header {
    pub use reqwest::header::*;
}

pub(crate) mod api_default_imports {
    pub(crate) use handlebars::*;
    pub use reqwest::Method;
    pub use url::Url;

    pub use graph_core::resource::ResourceIdentity;
    pub use graph_error::*;
    pub(crate) use graph_http::api_impl::*;

    pub use crate::client::Graph;
    pub(crate) use crate::client::{map_errors, map_parameters, ResourceProvisioner};
}