Trait oauth1_request::serializer::Serializer
source · [−]pub trait Serializer {
type Output;
fn serialize_parameter<V>(&mut self, key: &str, value: V)
where
V: Display;
fn serialize_parameter_encoded<V>(&mut self, key: &str, value: V)
where
V: Display;
fn serialize_oauth_callback(&mut self);
fn serialize_oauth_consumer_key(&mut self);
fn serialize_oauth_nonce(&mut self);
fn serialize_oauth_signature_method(&mut self);
fn serialize_oauth_timestamp(&mut self);
fn serialize_oauth_token(&mut self);
fn serialize_oauth_verifier(&mut self);
fn serialize_oauth_version(&mut self);
fn end(self) -> Self::Output;
}
Expand description
A Serializer
will be fed with the key-value pairs of a request
and produces a single value from them.
A Request
implementation serialize
s itself by feeding a Serializer
with its key-value
pairs through the serializer’s serialize_*
methods. The serialize_*
method calls correspond
to appending parameters to the signature base string (RFC 5849 section 3.4.1.) of
the OAuth request, and the key-value pairs must be serialized in ascending dictionary order.
use std::num::NonZeroU64;
use oauth::serializer::auth::{self, Authorizer};
use oauth::serializer::{Serializer, SerializerExt};
// Create an OAuth 1.0 `Authorization` header serializer.
let client = oauth::Credentials::new("consumer_key", "consumer_secret");
let token = oauth::Credentials::new("token", "token_secret");
let options = auth::Options::new();
let mut serializer = Authorizer::authorization(
"GET",
"https://example.com/api/v1/get.json",
client,
Some(token),
&options,
oauth::HMAC_SHA1,
);
// The parameters must be serialized in ascending ordering.
serializer.serialize_parameter("abc", "value");
serializer.serialize_parameter("lmn", "something");
// Add `oauth_*` parameters to the signature base string.
serializer.serialize_oauth_parameters();
// Continue serializing parameters greater than `oauth_*=...`.
serializer.serialize_parameter("qrs", "stuff");
serializer.serialize_parameter("xyz", "blah-blah");
let authorization = serializer.end();
assert_eq!(
authorization,
"OAuth \
oauth_consumer_key=\"consumer_key\",\
oauth_nonce=\"mo8_whwD5c91\",\
oauth_signature_method=\"HMAC-SHA1\",\
oauth_timestamp=\"1234567890\",\
oauth_token=\"token\",\
oauth_signature=\"eC5rUmIcYvAaIIWCIvOwhgUDByk%3D\"",
);
Required Associated Types
Required Methods
fn serialize_parameter<V>(&mut self, key: &str, value: V) where
V: Display,
fn serialize_parameter<V>(&mut self, key: &str, value: V) where
V: Display,
Serializes a key-value pair.
The serializer percent encodes the value, but not the key.
Panics
The parameters must be serialized in byte ascending order and implementations may panic otherwise.
fn serialize_parameter_encoded<V>(&mut self, key: &str, value: V) where
V: Display,
fn serialize_parameter_encoded<V>(&mut self, key: &str, value: V) where
V: Display,
Serializes a key-value pair.
This treats the value as already percent encoded and will not encode it again.
Panics
The parameters must be serialized in byte ascending order and implementations may panic otherwise.
fn serialize_oauth_callback(&mut self)
fn serialize_oauth_callback(&mut self)
Appends oauth_callback
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_consumer_key(&mut self)
fn serialize_oauth_consumer_key(&mut self)
Appends oauth_consumer_key
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_nonce(&mut self)
fn serialize_oauth_nonce(&mut self)
Appends oauth_nonce
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_signature_method(&mut self)
fn serialize_oauth_signature_method(&mut self)
Appends oauth_signature_method
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_timestamp(&mut self)
fn serialize_oauth_timestamp(&mut self)
Appends oauth_timestamp
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_token(&mut self)
fn serialize_oauth_token(&mut self)
Appends oauth_token
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_verifier(&mut self)
fn serialize_oauth_verifier(&mut self)
Appends oauth_verifier
parameter to the Authorization
header.
This must be called exactly once in a serialization process.
fn serialize_oauth_version(&mut self)
fn serialize_oauth_version(&mut self)
Appends oauth_version
parameter to the Authorization
header.
This must be called exactly once in a serialization process.