20个发布版

0.6.1 2024年6月19日
0.6.0 2022年6月12日
0.5.1 2021年10月6日
0.5.0 2021年1月11日
0.2.0 2018年10月28日

#45 in 身份验证

Download history 616/week @ 2024-05-04 671/week @ 2024-05-11 1188/week @ 2024-05-18 956/week @ 2024-05-25 676/week @ 2024-06-01 2258/week @ 2024-06-08 2975/week @ 2024-06-15 3439/week @ 2024-06-22 3980/week @ 2024-06-29 3667/week @ 2024-07-06 1487/week @ 2024-07-13 709/week @ 2024-07-20 882/week @ 2024-07-27 915/week @ 2024-08-03 1270/week @ 2024-08-10 674/week @ 2024-08-17

每月3,836次下载
用于 17 个crates (11 直接)

MIT/Apache

145KB
2.5K SLoC

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

依赖项

~0.6–2MB
~37K SLoC