Giter Club home page Giter Club logo

oauth1-request-rs's Issues

Best way to serialize keywords/reserved words

I need to create a query string from, e.g.:

#[derive(oauth1_request::Request)]
struct TextQuery {
    r#type: String,
}

But oauth1_request::to_uri_query(uri, &request_query) produces ?r#type=text (note r#). With serde you would use #[serde(rename = "type")], but it's not clear how to best go about doing it here.

Replace `Request` with plain `String` and make query serialization optional

Request.data can have either of a URI with query parameters or a form-urlencoded string. A single field having two different meaning depending on context is error-prone.

Also, the field actually has nothing to do with the OAuth authorization process. It was introduced just as a convenience and not all users require it, spending cost for unnecessary feature.

For these reasons, I'm planning to separate the query serialization from the Authorize-ation process and make Signer return a single "Authorization" header String. So, I'm going to change this:

extern crate oauth1_request as oauth;

let mut builder = oauth::Builder::new(client, oauth::HmacSha1);
builder.token(token);

let req = Foo { a: 1 };

let oauth::Request { authorization, data } = builder.post_form("https://example.com/", &req);
assert_eq!(data, "a=1");

let oauth::Request { authorization, data } = builder.get("https://example.com/", &req);
assert_eq!(data, "https://example.com/?a=1");

to something like this:

extern crate oauth1_request as oauth;
extern crate url;

let mut builder = oauth::Builder::new(client, oauth::HmacSha1);
builder.token(token);

let req = Foo { a: 1 };

let mut url: url::Url = "https://example.com/".parse().unwrap();

// N.B. we now call this method `post` instead of `post_form`
// since the method no longer generates a form-urlencoded string.
let authorization: String = builder.post("https://example.com/", &req);
let form = oauth::make_form_urlencoded(&req);
assert_eq!(form, "a=1");

let authorization: String = builder.get(&url, &req);
oauth::make_query(&req, url.query_pairs_mut());
assert_eq!(url.as_str(), "https://example.com/?a=1");

The concrete interface for oauth::make_{form_urlencoded,query} above is yet to be decided. There a few possibility for them, including:

  1. Using another crate like serde_urlencoded

  2. Make Signer generic over a "target" type. For example, Signer<Authorization> (where Authorization is a unit struct) would create an "Authorization" header string, and Signer<url::form_urlencoded::Serializer<_>> would append query pairs to the underlying Serializer, ignoring any OAuth parameters

Naming of `Token` type

While the term "token" in OAuth 1.0 refers to token credentials, oauth_credentials::Token represents a set of client credentials and token credentials, which are not identical concepts. The difference is confusing especially when a user uses the term to refer to the both concepts at the same time, which is the case almost every time they construct a Token.

let token: Credentials = get_token(&client).await; // Token credentials
let token = Token::new(client, token); // Client and token credentials

Also, token.client() and token.token() doesn't sound very well.

So I think Token should be renamed if there is a good alternative. Renaming a type doesn't prevent the semver trick, so it wouldn't cause a breakage provided that it is done before 1.0 release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.