OAuthSession

Implements an OAuth client session.

Members

Aliases

encode
alias encode = oauthEncode

Alias to oauthEncode.

Functions

prepareRequest
UrlParameters prepareRequest(string requestUrl, string method, UrlParameters[] parameters)

Signs a request and returns the relevant parameters for the "Authorization" header.

signRequest
string signRequest(string method, string requestUrl, UrlParameters[] parameters)

Calculates the signature for a request.

Variables

config
OAuthConfig config;
token
string token;
tokenSecret
string tokenSecret;

Examples

OAuthSession session;
session.config.consumerKey    = "(... obtain from service ...)";
session.config.consumerSecret = "(... obtain from service ...)";
session.token                 = "(... obtain from service ...)";
session.tokenSecret           = "(... obtain from service ...)";

...

UrlParameters parameters;
parameters["payload"] = "(... some data here ...)";
auto request = new HttpRequest;
auto queryString = parameters.byPair.map!(p => session.encode(p.key) ~ "=" ~ session.encode(p.value)).join("&");
auto baseURL = "https://api.example.com/endpoint";
auto fullURL = baseURL ~ "?" ~ queryString;
request.resource = fullURL;
request.method = "POST";
request.headers["Authorization"] = session.prepareRequest(baseURL, "POST", parameters).oauthHeader;
httpRequest(request, null);

Meta