#macro-derive #oauth #traits #request #client

macro oauth1-request-derive

A derive macro for oauth1_request::Request trait

13 releases

0.5.1 Jun 19, 2024
0.5.0 Jun 12, 2022
0.4.2 Dec 8, 2021
0.4.1 Oct 21, 2020
0.2.0 Dec 2, 2018

#168 in #request

Download history 675/week @ 2025-09-24 787/week @ 2025-10-01 605/week @ 2025-10-08 896/week @ 2025-10-15 990/week @ 2025-10-22 861/week @ 2025-10-29 1065/week @ 2025-11-05 896/week @ 2025-11-12 1079/week @ 2025-11-19 993/week @ 2025-11-26 999/week @ 2025-12-03 843/week @ 2025-12-10 972/week @ 2025-12-17 649/week @ 2025-12-24 908/week @ 2025-12-31 711/week @ 2026-01-07

3,398 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

31KB
733 lines

This crate provides a derive macro for oauth1_request::Request:

#[derive(oauth::Request)]

oauth1_request crate re-exports the derive macro if the derive feature of the crate is enabled (which is on by default). You should use the re-export instead of depending on this crate directly.


oauth1-request

Build Status Current Version Documentation

Yet yet yet another OAuth 1.0 client library for Rust.

Usage

Add this to your Cargo.toml:

[dependencies]
oauth = { version = "0.6", 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(&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_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

~3MB
~69K SLoC