[−][src]Crate oauth1_request
Yet yet yet another OAuth 1 client library.
Usage
Add this to your Cargo.toml
:
[dependencies]
oauth = { version = "0.3", package = "oauth1-request" }
For brevity we refer to the crate name as oauth
throughout the documentation.
Create a GET
request
#[derive(oauth::Authorize)] struct SearchComments<'a> { article_id: u64, text: &'a str, } let client = oauth::Credentials::new("consumer_key", "consumer_secret"); let token = oauth::Credentials::new("token", "token_secret"); let mut builder = oauth::Builder::new(client, oauth::HmacSha1); builder .token(token) .nonce("nonce") .timestamp(9999999999); let req = SearchComments { article_id: 123456789, text: "Rust", }; let oauth::Request { authorization, data, } = builder.get("https://example.com/api/v1/comments/search.json", &req); assert_eq!( authorization, "OAuth \ oauth_consumer_key=\"consumer_key\",\ oauth_nonce=\"nonce\",\ oauth_signature_method=\"HMAC-SHA1\",\ oauth_timestamp=\"9999999999\",\ oauth_token=\"token\",\ oauth_signature=\"kAkbCLL7obDyzdjz3uJoWSwiLqU%3D\"", ); assert_eq!( data, "https://example.com/api/v1/comments/search.json?article_id=123456789&text=Rust", );
Create an x-www-form-urlencoded
request
#[derive(oauth::Authorize)] struct CreateComment<'a> { article_id: u64, text: &'a str, } let req = CreateComment { article_id: 123456789, text: "Rust lang is great 🦀", }; // Use `post_form` method to create an `x-www-form-urlencoded` request. let oauth::Request { authorization, data, } = builder.post_form("https://example.com/api/v1/comments/create.json", &req); assert_eq!( authorization, "OAuth \ oauth_consumer_key=\"consumer_key\",\ oauth_nonce=\"nonce\",\ oauth_signature_method=\"HMAC-SHA1\",\ oauth_timestamp=\"9999999999\",\ oauth_token=\"token\",\ oauth_signature=\"bbhEIrjfisdDBrZkKnEXKa4ykE4%3D\"", ); assert_eq!( data, "article_id=123456789&text=Rust%20lang%20is%20great%20%F0%9F%A6%80", );
See Authorize
for more details on the custom derive macro.
Re-exports
pub use authorize::Authorize; |
pub use signature_method::HmacSha1; |
pub use signature_method::Plaintext; |
Modules
authorize | A trait representing requests that can be signed with OAuth. |
signature_method | Signature methods (RFC 5849 section 3.4.). |
signer | A low-level type for signing requests with OAuth. |
Structs
Builder | An OAuth |
Credentials | The "credentials" pair defined in RFC 5849 section 1.1. |
Options | Optional OAuth parameters. |
Request | A pair of an OAuth header and its corresponding query/form string. |
Derive Macros
Authorize |