#oauth #oauth1

oauth1-request

Yet yet yet another OAuth 1 client library

5 releases

0.2.1 Dec 2, 2018
0.2.0 Oct 28, 2018
0.1.2 Oct 18, 2018
0.1.1 Oct 15, 2018
0.1.0 Oct 14, 2018

#16 in Authentication

Download history 81/week @ 2018-10-16 15/week @ 2018-10-23 83/week @ 2018-10-30 45/week @ 2018-11-06 28/week @ 2018-11-13 10/week @ 2018-11-20 10/week @ 2018-11-27 72/week @ 2018-12-04 13/week @ 2018-12-11 13/week @ 2018-12-18 66/week @ 2018-12-25 10/week @ 2019-01-08

146 downloads per month
Used in 2 crates

MIT/Apache

64KB
1.5K SLoC


lib.rs:

Yet yet yet another OAuth 1 client library.

Usage

Using #[derive] (recommended)

Add this to your Cargo.toml:

oauth1-request-derive = "0.2"

Creating a GET request:

extern crate oauth1_request as oauth;
#[macro_use]
extern crate oauth1_request_derive;

use oauth::OAuth1Authorize;

#[derive(OAuth1Authorize)]
struct SearchComments<'a> {
    article_id: u64,
    text: &'a str,
}

# fn main() {
let req = SearchComments {
    article_id: 123456789,
    text: "Rust",
};

let oauth::Request { authorization, data } = req.authorize(
    "GET",
    "https://example.com/api/v1/comments/search.json",
    "consumer_key",
    "consumer_secret",
    "token_secret",
    oauth::HmacSha1,
    &*oauth::Options::new()
        .token("token")
        .nonce("nonce")
        .timestamp(9999999999),
);

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",
);
# }

Creating an x-www-form-urlencoded request:

# extern crate oauth1_request as oauth;
# #[macro_use] extern crate oauth1_request_derive;
# use oauth::OAuth1Authorize;
#[derive(OAuth1Authorize)]
struct CreateComment<'a> {
    article_id: u64,
    text: &'a str,
}

# fn main() {
let req = CreateComment {
    article_id: 123456789,
    text: "Rust lang is great 🦀",
};

// Use `authorize_form` method to create an `x-www-form-urlencoded` string.
let oauth::Request { authorization, data } = req.authorize_form(
    "POST",
    "https://example.com/api/v1/comments/create.json",
    "consumer_key",
    "consumer_secret",
    "token_secret",
    oauth::HmacSha1,
    &*oauth::Options::new()
        .token("token")
        .nonce("nonce")
        .timestamp(9999999999),
);

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 OAuth1Authorize for more details on the custom derive macro.

Using Signer

See Signer.

Dependencies

~1MB
~14K SLoC