Skip to content

Instantly share code, notes, and snippets.

@keith-miller
Created May 30, 2012 18:00
Show Gist options
  • Save keith-miller/2837981 to your computer and use it in GitHub Desktop.
Save keith-miller/2837981 to your computer and use it in GitHub Desktop.
OAuth post example
oauth_post(header, URL, Params, Consumer, Token, TokenSecret, Realm, Domain) ->
Signed = oauth:sign("POST", URL, Params, Consumer, Token, TokenSecret),
{AuthorizationParams, QueryParams} = lists:partition(fun({K, _}) -> lists:prefix("oauth_", K) end, Signed),
Request = {oauth:uri(URL, QueryParams), header(AuthorizationParams, Domain, Realm),
"application/x-www-form-urlencoded", ""},
httpc:request(post, Request, [{autoredirect, false}], [{headers_as_is, true}]).
header(Params, Domain, Realm) ->
RealmHeader = string:concat(string:concat("OAuth realm=\"", Realm), "\", "),
[{"Host", Domain},
{"Connection", "keep-alive"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Authorization", string:concat(RealmHeader, oauth:header_params_encode(Params))}].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment