[−][src]Struct oauth1_request::Signer
A type that creates a signed Request
.
Example
Creating a GET
request:
extern crate oauth1_request as oauth; let mut sign = oauth::HmacSha1Signer::new( "GET", "https://example.com/api/v1/get.json", "consumer_secret", "token_secret", // or `None` ); // The parameters must be appended in the ascending ordering. sign.parameter("abc", "value") .parameter("lmn", "something"); // Append `oauth_*` parameters. let mut sign = sign.oauth_parameters( "consumer_key", &*oauth::Options::new() .token("token") .nonce("nonce") .timestamp(9999999999), ); sign.parameter("qrs", "stuff") .parameter("xyz", "blah-blah"); let oauth::Request { authorization, data } = sign.finish(); assert_eq!( authorization, "OAuth \ oauth_consumer_key=\"consumer_key\",\ oauth_nonce=\"nonce\",\ oauth_signature_method=\"HMAC-SHA1\",\ oauth_timestamp=\"9999999999\",\ oauth_token=\"token\",\ oauth_signature=\"R1%2B4C7PHNUwA2TyMeNZDo0T8lSM%3D\"", ); assert_eq!( data, "https://example.com/api/v1/get.json?abc=value&lmn=something&qrs=stuff&xyz=blah-blah", );
Creating an x-www-form-urlencoded
request
// Use `new_form` method to create an `x-www-form-urlencoded` string. let mut sign = oauth::HmacSha1Signer::new_form( "POST", "https://example.com/api/v1/post.json", "consumer_secret", "token_secret", // or `None` ); // ... // (same as the above example...) let oauth::Request { authorization, data } = sign.finish(); assert_eq!( authorization, "OAuth \ oauth_consumer_key=\"consumer_key\",\ oauth_nonce=\"nonce\",\ oauth_signature_method=\"HMAC-SHA1\",\ oauth_timestamp=\"9999999999\",\ oauth_token=\"token\",\ oauth_signature=\"YUOk%2FeMb2r%2BAF5wW0H%2FgEx%2FoLp0%3D\"", ); assert_eq!( data, "abc=value&lmn=something&qrs=stuff&xyz=blah-blah", );
Methods
impl<SM: SignatureMethod> Signer<SM, NotReady>
[src]
pub fn new<'a>(
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self where
SM: Default,
[src]
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self where
SM: Default,
Returns a Signer
that appends query string to uri
and returns it as Request.data
.
uri
must not contain a query part. Otherwise, the Signer
will produce a wrong signature.
Panics
In debug builds, panics if uri
contains a '?'
character.
pub fn with_signature_method<'a>(
signature_method: SM,
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self
[src]
signature_method: SM,
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self
Same as new
except that this uses signature_method
as the signature method.
pub fn new_form<'a>(
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self where
SM: Default,
[src]
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self where
SM: Default,
Returns a Signer
that creates an x-www-form-urlencoded string and returns it as
Request.data
.
uri
must not contain a query part. Otherwise, the Signer
will produce a wrong signature.
Panics
In debug builds, panics if uri
contains a '?'
character.
pub fn form_with_signature_method<'a>(
signature_method: SM,
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self
[src]
signature_method: SM,
method: &str,
uri: impl Display,
consumer_secret: &str,
token_secret: impl Into<Option<&'a str>>
) -> Self
Same as new_form
except that this uses signature_method
as the signature method.
pub fn oauth_parameters<'a>(
self,
consumer_key: &str,
options: impl Into<Option<&'a Options<'a>>>
) -> Signer<SM, Ready>
[src]
self,
consumer_key: &str,
options: impl Into<Option<&'a Options<'a>>>
) -> Signer<SM, Ready>
Appends oauth_*
parameters to the signing key.
This must be called just after all the keys less than oauth_*
in byte order (if any)
is appended, and just before a key greater than oauth_*
(if any) is appended.
impl<SM: SignatureMethod, State> Signer<SM, State>
[src]
pub fn parameter(&mut self, k: &str, v: impl Display) -> &mut Self
[src]
Appends a parameter to the query/form string and signing key.
This percent encodes the value, but not the key.
The parameters must be appended in byte ascending order.
Panics
In debug builds, panics if the key is not appended in ascending order
pub fn parameter_encoded(&mut self, k: &str, v: impl Display) -> &mut Self
[src]
Appends a parameter to the query/form string and signing key.
Unlike parameter
, this will not percent encode the value.
Panics
In debug builds, panics if the key is not appended in ascending order.
impl<SM: SignatureMethod> Signer<SM, NotReady>
[src]
pub fn finish<'a>(
self,
consumer_key: &str,
options: impl Into<Option<&'a Options<'a>>>
) -> Request
[src]
self,
consumer_key: &str,
options: impl Into<Option<&'a Options<'a>>>
) -> Request
Shorthand for self.oauth_parameters(consumer_key, options).finish()
.
impl<SM: SignatureMethod> Signer<SM, Ready>
[src]
Trait Implementations
impl<SM: Clone + SignatureMethod, State: Clone> Clone for Signer<SM, State> where
SM::Sign: Clone,
[src]
SM::Sign: Clone,
impl<SM: Debug + SignatureMethod, State: Debug> Debug for Signer<SM, State> where
SM::Sign: Debug,
[src]
SM::Sign: Debug,
Auto Trait Implementations
impl<SM, State> Sync for Signer<SM, State> where
<SM as SignatureMethod>::Sign: Sync,
<SM as SignatureMethod>::Sign: Sync,
impl<SM, State> Send for Signer<SM, State> where
<SM as SignatureMethod>::Sign: Send,
<SM as SignatureMethod>::Sign: Send,
impl<SM, State> Unpin for Signer<SM, State> where
<SM as SignatureMethod>::Sign: Unpin,
<SM as SignatureMethod>::Sign: Unpin,
impl<SM, State> UnwindSafe for Signer<SM, State> where
<SM as SignatureMethod>::Sign: UnwindSafe,
<SM as SignatureMethod>::Sign: UnwindSafe,
impl<SM, State> RefUnwindSafe for Signer<SM, State> where
<SM as SignatureMethod>::Sign: RefUnwindSafe,
<SM as SignatureMethod>::Sign: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Same<T> for T
type Output = T
Should always be Self