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

oauth1-request-derive

oauth1_request::Request 特性提供 derive 宏

13 个版本

0.5.1 2024年6月19日
0.5.0 2022年6月12日
0.4.2 2021年12月8日
0.4.1 2020年10月21日
0.2.0 2018年12月2日

#136#oauth

Download history 677/week @ 2024-04-18 848/week @ 2024-04-25 480/week @ 2024-05-02 735/week @ 2024-05-09 841/week @ 2024-05-16 1174/week @ 2024-05-23 691/week @ 2024-05-30 1983/week @ 2024-06-06 2362/week @ 2024-06-13 3480/week @ 2024-06-20 4365/week @ 2024-06-27 3201/week @ 2024-07-04 1939/week @ 2024-07-11 1159/week @ 2024-07-18 773/week @ 2024-07-25 925/week @ 2024-08-01

5,373 每月下载量
用于 3 个crate(2个直接使用)

MIT/Apache

31KB
733

oauth1-request

Build Status Current Version Documentation

又一个为Rust设计的OAuth 1.0客户端库。

用法

将此内容添加到您的 Cargo.toml

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

典型的授权流程如下

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

lib.rs:

这个crate提供了一个 derive 宏,用于 oauth1_request::Request

#[derive(oauth::Request)]

oauth1_request crate 如果启用了 crate 的 derive 功能(默认启用),则会重新导出 derive 宏。您应该使用重新导出的宏而不是直接依赖此 crate。

依赖关系

~1.4–2MB
~42K SLoC