Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge remote-tracking branch 'origin/import-master'
Conflicts:
	src/oauth.erl
  • Loading branch information
rnewson committed May 14, 2014
2 parents 912739c + db23ab2 commit 2e26bf0f4ace399ea0dcc593255ec042445c02e9
Showing 2 changed files with 13 additions and 18 deletions.
@@ -1,6 +1,6 @@
{application, oauth, [
{description, "An Erlang OAuth 1.0 implementation"},
{vsn, "1.2.2"},
{vsn, "1.3.0"},
{modules, [oauth]},
{registered, []},
{applications, [kernel, stdlib, crypto, public_key, inets]}
@@ -1,11 +1,11 @@
-module(oauth).

-export([get/3, get/5, get/6, post/3, post/5, post/6, uri/2, header/1,
-export([get/3, get/5, get/6, post/3, post/5, post/6, put/6, put/7, uri/2, header/1,
sign/6, params_decode/1, token/1, token_secret/1, verify/6]).

-export([plaintext_signature/2, hmac_sha1_signature/5,
hmac_sha1_signature/3, rsa_sha1_signature/4, rsa_sha1_signature/2,
signature_base_string/3, params_encode/1, signature/5]).
signature_base_string/3, params_encode/1]).

-export([plaintext_verify/3, hmac_sha1_verify/6, hmac_sha1_verify/4,
rsa_sha1_verify/5, rsa_sha1_verify/3]).
@@ -15,12 +15,6 @@

-include_lib("public_key/include/public_key.hrl").

-ifndef(no_sha_hmac).
-define(SHA_HMAC(Key, Data), crypto:hmac(sha, Key, Data)).
-else.
-define(SHA_HMAC(Key, Data), crypto:sha_mac(Key, Data)).
-endif.

get(URL, ExtraParams, Consumer) ->
get(URL, ExtraParams, Consumer, "", "").

@@ -29,7 +23,7 @@ get(URL, ExtraParams, Consumer, Token, TokenSecret) ->

get(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
SignedParams = sign("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
http_get(uri(URL, SignedParams), HttpcOptions).
http_request(get, {uri(URL, SignedParams), []}, HttpcOptions).

post(URL, ExtraParams, Consumer) ->
post(URL, ExtraParams, Consumer, "", "").
@@ -39,7 +33,14 @@ post(URL, ExtraParams, Consumer, Token, TokenSecret) ->

post(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
SignedParams = sign("POST", URL, ExtraParams, Consumer, Token, TokenSecret),
http_post(URL, uri_params_encode(SignedParams), HttpcOptions).
http_request(post, {URL, [], "application/x-www-form-urlencoded", uri_params_encode(SignedParams)}, HttpcOptions).

put(URL, ExtraParams, {ContentType, Body}, Consumer, Token, TokenSecret) ->
put(URL, ExtraParams, {ContentType, Body}, Consumer, Token, TokenSecret, []).

put(URL, ExtraParams, {ContentType, Body}, Consumer, Token, TokenSecret, HttpcOptions) ->
SignedParams = sign("PUT", URL, ExtraParams, Consumer, Token, TokenSecret),
http_request(put, {uri(URL, SignedParams), [], ContentType, Body}, HttpcOptions).

uri(Base, []) ->
Base;
@@ -127,7 +128,7 @@ hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->

hmac_sha1_signature(BaseString, Consumer, TokenSecret) ->
Key = uri_join([consumer_secret(Consumer), TokenSecret]),
base64:encode_to_string(?SHA_HMAC(Key, BaseString)).
base64:encode_to_string(crypto:sha_mac(Key, BaseString)).

hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)).
@@ -179,12 +180,6 @@ params_encode(Params) ->
params_decode(_Response={{_, _, _}, _, Body}) ->
uri_params_decode(Body).

http_get(URL, Options) ->
http_request(get, {URL, []}, Options).

http_post(URL, Data, Options) ->
http_request(post, {URL, [], "application/x-www-form-urlencoded", Data}, Options).

http_request(Method, Request, Options) ->
httpc:request(Method, Request, [{autoredirect, false}], Options).

0 comments on commit 2e26bf0

Please sign in to comment.