Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds getting a drive user info to drive #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Permission {
write: bool,
access_shared: bool,
offline_access: bool,
read_user:bool,
}

impl Permission {
Expand All @@ -42,6 +43,13 @@ impl Permission {
self
}

/// Set the read user permission.
#[must_use]
pub fn read_user(mut self, read_user: bool) -> Self {
self.read_user = read_user;
self
}

/// Set whether allows offline access.
///
/// This permission is required to get a [`TokenResponse::refresh_token`] for long time access.
Expand All @@ -58,10 +66,12 @@ impl Permission {
#[rustfmt::skip]
fn to_scope_string(self) -> String {
format!(
"{}{}{}",
"{}{}{}{}",
if self.write { "files.readwrite" } else { "files.read" },
if self.access_shared { ".all" } else { "" },
if self.offline_access { " offline_access" } else { "" },
if self.offline_access { " user.read" } else { "" },

)
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/onedrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
use crate::{
error::{Error, Result},
option::{CollectionOption, DriveItemPutOption, ObjectOption},
resource::{Drive, DriveField, DriveItem, DriveItemField, TimestampString},
resource::{Drive, DriveField, DriveItem, DriveItemField, TimestampString, User},
util::{
handle_error_response, ApiPathComponent, DriveLocation, FileName, ItemLocation,
RequestBuilderExt as _, ResponseExt as _,
},
{ConflictBehavior, ExpectRange},
ConflictBehavior, ExpectRange,
};
use bytes::Bytes;
use reqwest::{header, Client};
Expand Down Expand Up @@ -103,6 +103,22 @@ impl OneDrive {
&self.token
}

/// Get current `UserInfo`.
///
///
///
/// # See also
/// [Microsoft Docs](https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0)
pub async fn get_user_info(&self) -> Result<User> {
self.client
.get(api_url!["me"])
.bearer_auth(&self.token)
.send()
.await?
.parse()
.await
}

/// Get current `Drive`.
///
/// Retrieve the properties and relationships of a [`resource::Drive`][drive] resource.
Expand Down
21 changes: 21 additions & 0 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ macro_rules! define_resource_object {
}

define_resource_object! {

/// User resource type
///
/// The User resource type represents a Microsoft Entra user account.
///
/// # See also
/// [Microsoft Docs](https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0)
pub struct User #UserItemField {
pub business_phones: Option<Vec<String>>,
pub display_name: Option<String>,
pub given_name: Option<String>,
pub job_title: Option<String>,
pub mail: Option<String>,
pub mobile_phone: Option<String>,
pub office_location: Option<String>,
pub preferred_language: Option<String>,
pub surname: Option<String>,
pub user_principal_name: Option<String>,
pub id: Option<String>,
}

/// Drive resource type
///
/// The drive resource is the top level object representing a user's OneDrive
Expand Down