| Crates.io | onedrive |
| lib.rs | onedrive |
| version | 1.1.3 |
| created_at | 2023-10-18 10:22:00.788104+00 |
| updated_at | 2023-11-28 12:14:00.791075+00 |
| description | A library package for interacting with OneDrive |
| homepage | https://github.com/PromH/codr |
| repository | https://github.com/PromH/codr |
| max_upload_size | |
| id | 1006578 |
| size | 100,909 |
onedriveA package for interacting with OneDrive.
In order to use this package, your own Microsoft OAuth2 credentials (see here for official instructions.) will need to be provided, in order to function properly.
The following steps outline how these credentials can be obtained.
Web application with:
Redirect URI of http://localhost:<REDIRECT_PORT><REDIRECT_ENDPOINT>
8080/redirectOverview. Copy the Application (client) ID as the MSGRAPH_CLIENT_ID.Certificates & secrets and add a new client secret. Copy the secret value
as MSGRAPH_CLIENT_SECRET.API permissions and add a permission then select Microsoft Graph and
Delegated permissions. Now add the Files.Read permission (and other permissions as necessary).cargo add onedrive
use onedrive::{GraphTokenObtainer, TokenObtainer};
use std::env;
use std::time::SystemTime;
fn setup_logger(log_level: log::LevelFilter) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"[{} {} {} {}:{}] {}",
humantime::format_rfc3339_seconds(SystemTime::now()),
record.level(),
record.target(),
record.file().unwrap_or("unknown"),
record.line().unwrap_or(0),
message
))
})
.level(log_level)
.chain(std::io::stdout())
.chain(fern::log_file("output.log")?)
.apply()?;
Ok(())
}
fn main() {
setup_logger(log::LevelFilter::Info).unwrap();
let token_obtainer = GraphTokenObtainer {
client_id: env::var("MSGRAPH_CLIENT_ID")
.expect("Missing the MSGRAPH_CLIENT_ID environment variable."),
client_secret: env::var("MSGRAPH_CLIENT_SECRET")
.expect("Missing the MSGRAPH_CLIENT_SECRET environment variable."),
access_scopes: vec![
"https://graph.microsoft.com/Files.Read".to_string(),
"https://graph.microsoft.com/User.Read".to_string(),
"https://graph.microsoft.com/Files.Read.All".to_string(),
],
auto_open_auth_url: true,
redirect_endpoint: Some("/redirect".to_string()),
redirect_port: Some(8080),
};
// This token can then be used to start interacting with MSGraph
println!(
"Token={:?}",
token_obtainer.get_token().unwrap().access_token()
)
}
Please examine the source code in codr to see how that's using the package to interact with OneDrive.
This package was developed to aid codr with interacting with OneDrive.
[!WARNING] This is my first Rust project so use with caution...