#oauth #oauth1

oauth1-request

Yet yet yet another OAuth 1 client library

17 unstable releases (4 breaking)

0.5.0 Jan 11, 2021
0.4.3 Nov 19, 2020
0.4.2 Oct 21, 2020
0.3.2 Mar 12, 2020
0.2.0 Oct 28, 2018

#9 in Authentication

Download history 54/week @ 2020-10-05 125/week @ 2020-10-12 174/week @ 2020-10-19 65/week @ 2020-10-26 57/week @ 2020-11-02 59/week @ 2020-11-09 223/week @ 2020-11-16 104/week @ 2020-11-23 69/week @ 2020-11-30 84/week @ 2020-12-07 35/week @ 2020-12-14 39/week @ 2020-12-21 52/week @ 2020-12-28 118/week @ 2021-01-04 154/week @ 2021-01-11 75/week @ 2021-01-18

393 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

96KB
1.5K SLoC

oauth1-request

Build Status Current Version Documentation

Yet yet yet another OAuth 1 client library for Rust.

Usage

Add this to your Cargo.toml:

[dependencies]
oauth = { version = "0.5", package = "oauth1-request" }

A typical authorization flow looks like this:

// Define a type to represent your request.
#[derive(oauth::Request)]
struct CreateComment<'a> {
    article_id: u64,
    text: &'a str,
}

let uri = "https://example.com/api/v1/comments/create.json";

let request = CreateComment {
    article_id: 123456789,
    text: "A request signed with OAuth & Rust 🦀 🔏",
};

// Prepare your credentials.
let token =
    oauth::Token::from_parts("consumer_key", "consumer_secret", "token", "token_secret");

// Create the `Authorization` header.
let authorization_header = oauth::post(uri, &request, &token, oauth::HmacSha1);
// `oauth_nonce` and `oauth_timestamp` vary on each execution.
assert_eq!(
    authorization_header,
    "OAuth \
         oauth_consumer_key=\"consumer_key\",\
         oauth_nonce=\"Dk-OGluFEQ4f\",\
         oauth_signature_method=\"HMAC-SHA1\",\
         oauth_timestamp=\"1234567890\",\
         oauth_token=\"token\",\
         oauth_signature=\"n%2FrUgos4CFFZbZK8Z8wFR7drU4c%3D\"",
);

// You can create an `x-www-form-urlencoded` string or a URI with query pairs from the request.

let form = oauth::to_form_urlencoded(&request);
assert_eq!(
    form,
    "article_id=123456789&text=A%20request%20signed%20with%20OAuth%20%26%20Rust%20%F0%9F%A6%80%20%F0%9F%94%8F",
);

let uri = oauth::to_uri_query(uri.to_owned(), &request);
assert_eq!(
    uri,
    "https://example.com/api/v1/comments/create.json?article_id=123456789&text=A%20request%20signed%20with%20OAuth%20%26%20Rust%20%F0%9F%A6%80%20%F0%9F%94%8F",
);

Dependencies

~0.5–0.8MB
~17K SLoC