Crates.io | usos-rs |
lib.rs | usos-rs |
version | 1.0.0 |
source | src |
created_at | 2024-03-13 14:22:21.567361 |
updated_at | 2024-03-13 14:22:21.567361 |
description | Crate provides a convenient way to authenticate to USOS api |
homepage | |
repository | https://gitlab.com/fili_pk/usos-rs |
max_upload_size | |
id | 1171720 |
size | 50,976 |
The usos-rs
crate provides a convenient way to authenticate to USOS api
use reqwest::Url;
use std::error::Error;
use std::{collections::HashSet, io};
use usos_rs::{self, Scope, UsosRs};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let consumer_key = "consumer key";
let consumer_secret = "consumer secret";
let api_url = Url::parse("api url")?;
let usos = UsosRs::new(api_url, consumer_key.to_owned(), consumer_secret.to_owned())?;
let scopes = HashSet::from([Scope::PersonalData]);
let u_user = usos.get_unauthorized_user(Some(&scopes)).await?;
println!("{}", u_user.authorize_url());
let mut user_input = String::new();
io::stdin().read_line(&mut user_input)?;
let pin = user_input.trim();
let user = u_user.authorize(pin).await.map_err(|(_, e)| e)?;
let response = user
.reqwest_client()
.post(user.api_url().join("/services/users/user")?)
.query(&[("fields", "first_name")])
.send()
.await?;
println!("{}", response.text().await?);
Ok(())
}
use reqwest::Url;
use std::error::Error;
use usos_rs::{self, AccessToken, UsosRs};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let consumer_key = "consumer key";
let consumer_secret = "consumer secret";
let api_url = Url::parse("api url")?;
let usos = UsosRs::new(api_url, consumer_key.to_owned(), consumer_secret.to_owned())?;
let user = usos
.get_authorized_user(AccessToken {
token: "access token".to_owned(),
token_secret: "access token secret".to_owned(),
})
.await;
let response = user
.reqwest_client()
.post(user.api_url().join("/services/users/user")?)
.query(&[("fields", "first_name")])
.send()
.await?;
println!("{}", response.text().await?);
Ok(())
}
AGPLv3+ © Filip K.