You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:57:05 UTC

[01/50] git commit: Move signature verification code into helper modules.

Updated Branches:
  refs/heads/import [created] d50a78688


Move signature verification code into helper modules.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/d8be2369
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/d8be2369
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/d8be2369

Branch: refs/heads/import
Commit: d8be23693bf76637f13845cb3dc003480415431b
Parents: fb4ac88
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Wed Feb 25 14:16:51 2009 +0000
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Wed Feb 25 14:16:51 2009 +0000

----------------------------------------------------------------------
 src/oauth.erl           |  8 ++++----
 src/oauth_hmac_sha1.erl |  5 ++++-
 src/oauth_plaintext.erl |  5 ++++-
 src/oauth_rsa_sha1.erl  | 10 +++++++++-
 4 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d8be2369/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 9b22aed..866655c 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -39,13 +39,13 @@ token_secret(Params) ->
 verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
   case signature_method(Consumer) of
     plaintext ->
-      Signature =:= signature(HttpMethod, URL, Params, Consumer, TokenSecret);
+      oauth_plaintext:verify(Signature, consumer_secret(Consumer), TokenSecret);
     hmac_sha1 ->
-      Signature =:= signature(HttpMethod, URL, Params, Consumer, TokenSecret);
+      BaseString = signature_base_string(HttpMethod, URL, Params),
+      oauth_hmac_sha1:verify(Signature, BaseString, consumer_secret(Consumer), TokenSecret);
     rsa_sha1 ->
       BaseString = signature_base_string(HttpMethod, URL, Params),
-      PublicKey = oauth_rsa_sha1:public_key(consumer_secret(Consumer)),
-      public_key:verify_signature(BaseString, sha, Signature, PublicKey)
+      oauth_rsa_sha1:verify(Signature, BaseString, consumer_secret(Consumer))
   end.
 
 signed_params(HttpMethod, URL, ExtraParams, Consumer, Token, TokenSecret) ->

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d8be2369/src/oauth_hmac_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_hmac_sha1.erl b/src/oauth_hmac_sha1.erl
index ed232c4..69064ed 100644
--- a/src/oauth_hmac_sha1.erl
+++ b/src/oauth_hmac_sha1.erl
@@ -1,8 +1,11 @@
 -module(oauth_hmac_sha1).
 
--export([signature/3]).
+-export([signature/3, verify/4]).
 
 
 signature(BaseString, CS, TS) ->
   Key = oauth_uri:calate("&", [CS, TS]),
   base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
+
+verify(Signature, BaseString, CS, TS) ->
+  Signature =:= signature(BaseString, CS, TS).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d8be2369/src/oauth_plaintext.erl
----------------------------------------------------------------------
diff --git a/src/oauth_plaintext.erl b/src/oauth_plaintext.erl
index 9f6e0f2..1aae8fc 100644
--- a/src/oauth_plaintext.erl
+++ b/src/oauth_plaintext.erl
@@ -1,7 +1,10 @@
 -module(oauth_plaintext).
 
--export([signature/2]).
+-export([signature/2, verify/3]).
 
 
 signature(CS, TS) ->
   oauth_uri:encode(oauth_uri:calate("&", [CS, TS])).
+
+verify(Signature, CS, TS) ->
+  Signature =:= signature(CS, TS).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d8be2369/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
index 45a0ca5..c90ba21 100644
--- a/src/oauth_rsa_sha1.erl
+++ b/src/oauth_rsa_sha1.erl
@@ -1,6 +1,6 @@
 -module(oauth_rsa_sha1).
 
--export([signature/2, public_key/1]).
+-export([signature/2, verify/3]).
 
 -include_lib("public_key/include/public_key.hrl").
 
@@ -10,6 +10,14 @@ signature(BaseString, PrivateKeyPath) ->
   {ok, PrivateKey} = public_key:decode_private_key(Info),
   base64:encode_to_string(public_key:sign(list_to_binary(BaseString), PrivateKey)).
 
+verify(Signature, BaseString, PublicKey) ->
+  public_key:verify_signature(to_binary(BaseString), sha, base64:decode(Signature), public_key(PublicKey)).
+
+to_binary(Term) when is_list(Term) ->
+  list_to_binary(Term);
+to_binary(Term) when is_binary(Term) ->
+  Term.
+
 public_key(Path) when is_list(Path) ->
   {ok, [{cert, DerCert, not_encrypted}]} = public_key:pem_to_der(Path),
   {ok, Cert} = pubkey_cert_records:decode_cert(DerCert, otp),


[38/50] git commit: Remove last clause from verify_in_constant_time/2

Posted by da...@apache.org.
Remove last clause from verify_in_constant_time/2


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/ed213ddc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/ed213ddc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/ed213ddc

Branch: refs/heads/import
Commit: ed213ddc91d95a37d3095533d1b312c2b60b8e65
Parents: 8abf2d6
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Oct 17 11:56:40 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Oct 17 11:56:40 2011 +0100

----------------------------------------------------------------------
 src/oauth.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/ed213ddc/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 692ac19..18c428d 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -158,8 +158,7 @@ verify_in_constant_time(X, Y) when is_list(X) and is_list(Y) ->
             verify_in_constant_time(X, Y, 0);
         false ->
             false
-    end;
-verify_in_constant_time(_X, _Y) -> false.
+    end.
 
 signature_base_string(HttpMethod, URL, Params) ->
   uri_join([HttpMethod, uri_normalize(URL), params_encode(Params)]).


[11/50] git commit: Add option for sending protocol parameters in either the header or querystring.

Posted by da...@apache.org.
Add option for sending protocol parameters in either the header or querystring.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/9d00161b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/9d00161b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/9d00161b

Branch: refs/heads/import
Commit: 9d00161bcd47498d753feae1b81e48f72a595a09
Parents: 1bcd44f
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Sep 26 14:44:42 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Sep 26 14:44:42 2009 +0100

----------------------------------------------------------------------
 src/oauth_client.erl | 45 ++++++++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/9d00161b/src/oauth_client.erl
----------------------------------------------------------------------
diff --git a/src/oauth_client.erl b/src/oauth_client.erl
index b6fd831..4b50901 100644
--- a/src/oauth_client.erl
+++ b/src/oauth_client.erl
@@ -2,9 +2,9 @@
 
 -behaviour(gen_server).
 
--export([access_token_params/1, deauthorize/1, get/2, get/3, get_access_token/2,
-  get_access_token/3, get_request_token/2, get_request_token/3, start/1, start/2,
-  start_link/1, start_link/2, stop/1]).
+-export([access_token_params/1, deauthorize/1, get/2, get/3, get/4, get_access_token/2,
+  get_access_token/3, get_access_token/4, get_request_token/2, get_request_token/3,
+  get_request_token/4, start/1, start/2, start_link/1, start_link/2, stop/1]).
 
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
 
@@ -25,22 +25,31 @@ start_link(ServerName, Consumer) ->
   gen_server:start_link(ServerName, ?MODULE, Consumer, []).
 
 get_request_token(Client, URL) ->
-  get_request_token(Client, URL, []).
+  get_request_token(Client, URL, [], header).
 
 get_request_token(Client, URL, Params) ->
-  gen_server:call(Client, {get_request_token, URL, Params}).
+  gen_server:call(Client, {get_request_token, URL, Params, header}).
+
+get_request_token(Client, URL, Params, ParamsMethod) ->
+  gen_server:call(Client, {get_request_token, URL, Params, ParamsMethod}).
 
 get_access_token(Client, URL) ->
-  get_access_token(Client, URL, []).
+  get_access_token(Client, URL, [], header).
 
 get_access_token(Client, URL, Params) ->
-  gen_server:call(Client, {get_access_token, URL, Params}).
+  gen_server:call(Client, {get_access_token, URL, Params, header}).
+
+get_access_token(Client, URL, Params, ParamsMethod) ->
+  gen_server:call(Client, {get_access_token, URL, Params, ParamsMethod}).
 
 get(Client, URL) ->
-  get(Client, URL, []).
+  get(Client, URL, [], header).
 
 get(Client, URL, Params) ->
-  gen_server:call(Client, {get, URL, Params}).
+  gen_server:call(Client, {get, URL, Params, header}).
+
+get(Client, URL, Params, ParamsMethod) ->
+  gen_server:call(Client, {get, URL, Params, ParamsMethod}).
 
 access_token_params(Client) ->
   gen_server:call(Client, {access_token_params}).
@@ -55,11 +64,13 @@ stop(Client) ->
 %% Helper functions
 %%============================================================================
 
-oauth_get(URL, Params, Consumer, Token, TokenSecret) ->
+oauth_get(header, URL, Params, Consumer, Token, TokenSecret) ->
   Signed = oauth:signed_params("GET", URL, Params, Consumer, Token, TokenSecret),
   {AuthorizationParams, QueryParams} = lists:partition(fun({K, _}) -> lists:prefix("oauth_", K) end, Signed),
   Request = {oauth:uri(URL, QueryParams), [oauth:header(AuthorizationParams)]},
-  http:request(get, Request, [{autoredirect, false}], []).
+  http:request(get, Request, [{autoredirect, false}], []);
+oauth_get(querystring, URL, Params, Consumer, Token, TokenSecret) ->
+  oauth:get(URL, Params, Consumer, Token, TokenSecret).
 
 %%============================================================================
 %% gen_server callbacks
@@ -68,8 +79,8 @@ oauth_get(URL, Params, Consumer, Token, TokenSecret) ->
 init(Consumer) ->
   {ok, {Consumer}}.
 
-handle_call({get_request_token, URL, Params}, _From, State={Consumer}) ->
-  case oauth_get(URL, Params, Consumer, "", "") of
+handle_call({get_request_token, URL, Params, ParamsMethod}, _From, State={Consumer}) ->
+  case oauth_get(ParamsMethod, URL, Params, Consumer, "", "") of
     {ok, Response} ->
       case oauth_http:response_code(Response) of
         200 ->
@@ -81,8 +92,8 @@ handle_call({get_request_token, URL, Params}, _From, State={Consumer}) ->
     Error ->
       {reply, Error, State}
   end;
-handle_call({get_access_token, URL, Params}, _From, State={Consumer, RParams}) ->
-  case oauth_get(URL, Params, Consumer, oauth:token(RParams), oauth:token_secret(RParams)) of
+handle_call({get_access_token, URL, Params, ParamsMethod}, _From, State={Consumer, RParams}) ->
+  case oauth_get(ParamsMethod, URL, Params, Consumer, oauth:token(RParams), oauth:token_secret(RParams)) of
     {ok, Response} ->
       case oauth_http:response_code(Response) of
         200 ->
@@ -94,8 +105,8 @@ handle_call({get_access_token, URL, Params}, _From, State={Consumer, RParams}) -
     Error ->
       {reply, Error, State}
   end;
-handle_call({get, URL, Params}, _From, State={Consumer, _RParams, AParams}) ->
-  case oauth_get(URL, Params, Consumer, oauth:token(AParams), oauth:token_secret(AParams)) of
+handle_call({get, URL, Params, ParamsMethod}, _From, State={Consumer, _RParams, AParams}) ->
+  case oauth_get(ParamsMethod, URL, Params, Consumer, oauth:token(AParams), oauth:token_secret(AParams)) of
     {ok, Response={{_, Status, _}, Headers, Body}} ->
       case Status of
         200 ->


[19/50] git commit: Move .app file to ebin; update Makefile.

Posted by da...@apache.org.
Move .app file to ebin; update Makefile.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/24a39a27
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/24a39a27
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/24a39a27

Branch: refs/heads/import
Commit: 24a39a2700c6e1ca32c670a9f4fe82a28c40b6ba
Parents: 2c9269b
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 14:19:37 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 14:19:37 2010 +0000

----------------------------------------------------------------------
 Makefile       |  4 +---
 ebin/oauth.app | 21 +++++++++++++++++++++
 src/oauth.app  | 21 ---------------------
 3 files changed, 22 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/24a39a27/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index f6aedc9..09880ea 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,5 @@
 all:
-	@test -d ebin || mkdir ebin
-	@cp src/oauth.app ebin/
 	@erl -make
 
 clean:
-	@rm -rf ebin/* erl_crash.dump
+	@rm -rf ebin/*.beam erl_crash.dump

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/24a39a27/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
new file mode 100644
index 0000000..f368f9c
--- /dev/null
+++ b/ebin/oauth.app
@@ -0,0 +1,21 @@
+{application, oauth, [
+  {description, "An Erlang OAuth 1.0 implementation"},
+  {vsn, "1.0.1"},
+  {modules, [
+    oauth,
+    oauth_client,
+    oauth_hmac_sha1,
+    oauth_http,
+    oauth_plaintext,
+    oauth_rsa_sha1,
+    oauth_unix,
+    oauth_uri
+  ]},
+  {registered, []},
+  {applications, [
+    kernel,
+    stdlib,
+    crypto,
+    inets
+  ]}
+]}.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/24a39a27/src/oauth.app
----------------------------------------------------------------------
diff --git a/src/oauth.app b/src/oauth.app
deleted file mode 100644
index f368f9c..0000000
--- a/src/oauth.app
+++ /dev/null
@@ -1,21 +0,0 @@
-{application, oauth, [
-  {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.0.1"},
-  {modules, [
-    oauth,
-    oauth_client,
-    oauth_hmac_sha1,
-    oauth_http,
-    oauth_plaintext,
-    oauth_rsa_sha1,
-    oauth_unix,
-    oauth_uri
-  ]},
-  {registered, []},
-  {applications, [
-    kernel,
-    stdlib,
-    crypto,
-    inets
-  ]}
-]}.


[04/50] git commit: Fix README quick start prompt numbering.

Posted by da...@apache.org.
Fix README quick start prompt numbering.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/41ead739
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/41ead739
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/41ead739

Branch: refs/heads/import
Commit: 41ead739b7b5a21e6fbef837c6eb3eaad9b1aaf7
Parents: 646c13e
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Mar 14 11:56:40 2009 +0000
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Mar 14 11:56:40 2009 +0000

----------------------------------------------------------------------
 README.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/41ead739/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index f8270c4..2df3ab3 100644
--- a/README.txt
+++ b/README.txt
@@ -20,7 +20,7 @@ Quick start (client usage):
   ...
   7> AccessTokenURL = "http://term.ie/oauth/example/access_token.php".
   ...
-  6> {ok, ResponseA} = oauth:get(AccessTokenURL, [], Consumer, TokenR, TokenSecretR).
+  8> {ok, ResponseA} = oauth:get(AccessTokenURL, [], Consumer, TokenR, TokenSecretR).
   ...
 
 


[16/50] git commit: Use httpc module instead of http module.

Posted by da...@apache.org.
Use httpc module instead of http module.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/7d85d3ef
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/7d85d3ef
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/7d85d3ef

Branch: refs/heads/import
Commit: 7d85d3efdc4723ef0a02212653ab71ecebf9e7c5
Parents: e8aecf0
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Jun 25 18:43:15 2010 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Fri Jun 25 18:43:15 2010 +0100

----------------------------------------------------------------------
 src/oauth_client.erl | 2 +-
 src/oauth_http.erl   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/7d85d3ef/src/oauth_client.erl
----------------------------------------------------------------------
diff --git a/src/oauth_client.erl b/src/oauth_client.erl
index 73a7869..2bd24c0 100644
--- a/src/oauth_client.erl
+++ b/src/oauth_client.erl
@@ -68,7 +68,7 @@ oauth_get(header, URL, Params, Consumer, Token, TokenSecret) ->
   Signed = oauth:signed_params("GET", URL, Params, Consumer, Token, TokenSecret),
   {AuthorizationParams, QueryParams} = lists:partition(fun({K, _}) -> lists:prefix("oauth_", K) end, Signed),
   Request = {oauth:uri(URL, QueryParams), [oauth:header(AuthorizationParams)]},
-  http:request(get, Request, [{autoredirect, false}], []);
+  httpc:request(get, Request, [{autoredirect, false}], []);
 oauth_get(querystring, URL, Params, Consumer, Token, TokenSecret) ->
   oauth:get(URL, Params, Consumer, Token, TokenSecret).
 

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/7d85d3ef/src/oauth_http.erl
----------------------------------------------------------------------
diff --git a/src/oauth_http.erl b/src/oauth_http.erl
index bf5a4ba..92c806c 100644
--- a/src/oauth_http.erl
+++ b/src/oauth_http.erl
@@ -10,7 +10,7 @@ post(URL, Data) ->
   request(post, {URL, [], "application/x-www-form-urlencoded", Data}).
 
 request(Method, Request) ->
-  http:request(Method, Request, [{autoredirect, false}], []).
+  httpc:request(Method, Request, [{autoredirect, false}], []).
 
 response_params(Response) ->
   oauth_uri:params_from_string(response_body(Response)).


[50/50] git commit: fix typo

Posted by da...@apache.org.
fix typo


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/d50a7868
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/d50a7868
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/d50a7868

Branch: refs/heads/import
Commit: d50a78688b6b489ae0a57799519b88f3b9f81401
Parents: b8e18a7
Author: benoitc <bc...@gmail.com>
Authored: Sun Jun 23 17:04:36 2013 +0200
Committer: benoitc <bc...@gmail.com>
Committed: Sun Jun 23 17:04:36 2013 +0200

----------------------------------------------------------------------
 rebar.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d50a7868/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 21d678e..815f982 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,3 +1,3 @@
 {erl_opts, [
-  {platform_define, "(R14|R15)", "no_sha_hmac"}
+  {platform_define, "(R14|R15)", 'no_sha_hmac'}
 ]}.


[45/50] git commit: Bump version to 1.2.2

Posted by da...@apache.org.
Bump version to 1.2.2


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/994f3d49
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/994f3d49
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/994f3d49

Branch: refs/heads/import
Commit: 994f3d497ceea784b78e81b2aa93eaedfee2fbf8
Parents: e2c5524
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sun Dec 18 11:30:57 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sun Dec 18 11:30:57 2011 +0000

----------------------------------------------------------------------
 ebin/oauth.app | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/994f3d49/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index 0928ee8..7a5d8fc 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,6 +1,6 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.2.1"},
+  {vsn, "1.2.2"},
   {modules, [oauth]},
   {registered, []},
   {applications, [kernel, stdlib, crypto, public_key, inets]}


[14/50] git commit: Add improved implementation of percent encoding/decoding functions.

Posted by da...@apache.org.
Add improved implementation of percent encoding/decoding functions.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/ca45418d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/ca45418d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/ca45418d

Branch: refs/heads/import
Commit: ca45418d126f9333c9e697c149e77d5e035f35ce
Parents: be1aa96
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Tue Oct 6 18:13:51 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Tue Oct 6 18:13:51 2009 +0100

----------------------------------------------------------------------
 src/oauth_uri.erl | 66 +++++++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/ca45418d/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
index 8859ea6..c019427 100644
--- a/src/oauth_uri.erl
+++ b/src/oauth_uri.erl
@@ -6,14 +6,6 @@
 
 -import(lists, [concat/1]).
 
--define(is_uppercase_alpha(C), C >= $A, C =< $Z).
--define(is_lowercase_alpha(C), C >= $a, C =< $z).
--define(is_alpha(C), ?is_uppercase_alpha(C); ?is_lowercase_alpha(C)).
--define(is_digit(C), C >= $0, C =< $9).
--define(is_alphanumeric(C), ?is_alpha(C); ?is_digit(C)).
--define(is_unreserved(C), ?is_alphanumeric(C); C =:= $-; C =:= $_; C =:= $.; C =:= $~).
--define(is_hex(C), ?is_digit(C); C >= $A, C =< $F).
-
 
 normalize(URI) ->
   case http_uri:parse(URI) of
@@ -66,23 +58,41 @@ intersperse(_, [X]) -> [X];
 intersperse(Sep, [X|Xs]) ->
   [X, Sep|intersperse(Sep, Xs)].
 
-decode(Chars) ->
-  decode(Chars, []).
-
-decode([], Decoded) ->
-  lists:reverse(Decoded);
-decode([$%,A,B|Etc], Decoded) when ?is_hex(A), ?is_hex(B) ->
-  decode(Etc, [erlang:list_to_integer([A,B], 16)|Decoded]);
-decode([C|Etc], Decoded) when ?is_unreserved(C) ->
-  decode(Etc, [C|Decoded]).
-
-encode(Chars) ->
-  encode(Chars, []).
-
-encode([], Encoded) ->
-  lists:flatten(lists:reverse(Encoded));
-encode([C|Etc], Encoded) when ?is_unreserved(C) ->
-  encode(Etc, [C|Encoded]);
-encode([C|Etc], Encoded) ->
-  Value = io_lib:format("%~2.1.0s", [erlang:integer_to_list(C, 16)]),
-  encode(Etc, [Value|Encoded]).
+-define(is_alphanum(C), C >= $A, C =< $Z; C >= $a, C =< $z; C >= $0, C =< $9).
+
+encode(Term) when is_integer(Term) ->
+  integer_to_list(Term);
+encode(Term) when is_atom(Term) ->
+  encode(atom_to_list(Term));
+encode(Term) when is_list(Term) ->
+  encode(lists:reverse(Term, []), []).
+
+encode([X | T], Acc) when ?is_alphanum(X); X =:= $-; X =:= $_; X =:= $.; X =:= $~ ->
+  encode(T, [X | Acc]);
+encode([X | T], Acc) ->
+  NewAcc = [$%, dec2hex(X bsr 4), dec2hex(X band 16#0f) | Acc],
+  encode(T, NewAcc);
+encode([], Acc) ->
+  Acc.
+
+decode(Str) when is_list(Str) ->
+  decode(Str, []).
+
+decode([$%, A, B | T], Acc) ->
+  decode(T, [(hex2dec(A) bsl 4) + hex2dec(B) | Acc]);
+decode([X | T], Acc) ->
+  decode(T, [X | Acc]);
+decode([], Acc) ->
+  lists:reverse(Acc, []).
+
+-compile({inline, [{dec2hex, 1}, {hex2dec, 1}]}).
+
+dec2hex(N) when N >= 10 andalso N =< 15 ->
+  N + $A - 10;
+dec2hex(N) when N >= 0 andalso N =< 9 ->
+  N + $0.
+
+hex2dec(C) when C >= $A andalso C =< $F ->
+  C - $A + 10;
+hex2dec(C) when C >= $0 andalso C =< $9 ->
+  C - $0.


[30/50] git commit: Use correct request parameter normalization algorithm.

Posted by da...@apache.org.
Use correct request parameter normalization algorithm.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/b9dcd4f8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/b9dcd4f8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/b9dcd4f8

Branch: refs/heads/import
Commit: b9dcd4f8e31218e549aadfd870d1147bcee1159c
Parents: dcbf227
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sat Jan 29 17:11:11 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sat Jan 29 17:11:11 2011 +0000

----------------------------------------------------------------------
 src/oauth.erl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/b9dcd4f8/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index c6467d9..f2fa946 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -61,9 +61,16 @@ signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
 
 signature_base_string(HttpMethod, URL, Params) ->
   NormalizedURL = oauth_uri:normalize(URL),
-  NormalizedParams = oauth_uri:params_to_string(lists:sort(Params)),
+  NormalizedParams = normalized_params_string(Params),
   oauth_uri:calate("&", [HttpMethod, NormalizedURL, NormalizedParams]).
 
+normalized_params_string(Params) ->
+  % cf. http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
+  Encoded = [{oauth_uri:encode(K), oauth_uri:encode(V)} || {K, V} <- Params],
+  Sorted = lists:sort(Encoded),
+  Concatenated = [lists:concat([K, "=", V]) || {K, V} <- Sorted],
+  string:join(Concatenated, "&").
+
 token_param("", Params) ->
   Params;
 token_param(Token, Params) ->


[40/50] git commit: Use verify_in_constant_time in plaintext signature verification

Posted by da...@apache.org.
Use verify_in_constant_time in plaintext signature verification


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/72f7a878
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/72f7a878
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/72f7a878

Branch: refs/heads/import
Commit: 72f7a87808fed14e66c82485674faff9c4bb1fbf
Parents: 3ae1cc7
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Oct 17 11:58:18 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Oct 17 11:58:18 2011 +0100

----------------------------------------------------------------------
 src/oauth.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/72f7a878/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 61e4a0a..5fc563e 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -113,7 +113,7 @@ plaintext_signature(Consumer, TokenSecret) ->
   uri_join([consumer_secret(Consumer), TokenSecret]).
 
 plaintext_verify(Signature, Consumer, TokenSecret) ->
-  Signature =:= plaintext_signature(Consumer, TokenSecret).
+  verify_in_constant_time(Signature, plaintext_signature(Consumer, TokenSecret)).
 
 hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
   BaseString = signature_base_string(HttpMethod, URL, Params),


[41/50] git commit: Bump version to 1.2.1

Posted by da...@apache.org.
Bump version to 1.2.1


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/7969309d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/7969309d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/7969309d

Branch: refs/heads/import
Commit: 7969309dd61afb180a544ab941b189fde389c430
Parents: 72f7a87
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Oct 17 11:59:04 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Oct 17 11:59:04 2011 +0100

----------------------------------------------------------------------
 ebin/oauth.app | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/7969309d/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index d379b8d..0928ee8 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,6 +1,6 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.2.0"},
+  {vsn, "1.2.1"},
   {modules, [oauth]},
   {registered, []},
   {applications, [kernel, stdlib, crypto, public_key, inets]}


[34/50] git commit: Add oauth:get/3 and oauth:post/3 functions

Posted by da...@apache.org.
Add oauth:get/3 and oauth:post/3 functions


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2b001da2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2b001da2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2b001da2

Branch: refs/heads/import
Commit: 2b001da23e1b33ee18bd14ff0c4501ccb3814935
Parents: fc5f528
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Thu Jun 23 16:04:00 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Thu Jun 23 16:04:00 2011 +0100

----------------------------------------------------------------------
 src/oauth.erl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2b001da2/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index fe66d4a..c46728f 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -1,7 +1,7 @@
 -module(oauth).
 
--export([get/5, get/6, post/5, post/6, uri/2, header/1, sign/6,
-  params_decode/1, token/1, token_secret/1, verify/6]).
+-export([get/3, get/5, get/6, post/3, post/5, post/6, 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,
@@ -15,6 +15,9 @@
 
 -include_lib("public_key/include/public_key.hrl").
 
+get(URL, ExtraParams, Consumer) ->
+  get(URL, ExtraParams, Consumer, "", "").
+
 get(URL, ExtraParams, Consumer, Token, TokenSecret) ->
   get(URL, ExtraParams, Consumer, Token, TokenSecret, []).
 
@@ -22,6 +25,9 @@ get(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
   SignedParams = sign("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
   http_get(uri(URL, SignedParams), HttpcOptions).
 
+post(URL, ExtraParams, Consumer) ->
+  post(URL, ExtraParams, Consumer, "", "").
+
 post(URL, ExtraParams, Consumer, Token, TokenSecret) ->
   post(URL, ExtraParams, Consumer, Token, TokenSecret, []).
 


[09/50] git commit: README updates.

Posted by da...@apache.org.
README updates.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2c625a0c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2c625a0c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2c625a0c

Branch: refs/heads/import
Commit: 2c625a0ce65dcb7a8208ed7e4967388cf4615fcf
Parents: 8bf2603
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sun Jul 19 19:01:53 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sun Jul 19 19:01:53 2009 +0100

----------------------------------------------------------------------
 README.txt | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2c625a0c/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index 2df3ab3..d2ff5f9 100644
--- a/README.txt
+++ b/README.txt
@@ -24,8 +24,10 @@ Quick start (client usage):
   ...
 
 
-Example client/server code: http://github.com/tim/erlang-oauth-examples.
+Thanks to Jason Davies, Paul Bonser, and Roberto Aloi for their patches.
 
-Unit tests: http://github.com/tim/erlang-oauth-tests.
+Example client/server code is at http://github.com/tim/erlang-oauth-examples.
 
-Erlang R12B-5 required for RSA-SHA1.
+Unit tests are at http://github.com/tim/erlang-oauth-tests.
+
+Erlang R12B-5 or greater is required for RSA-SHA1.


[44/50] git commit: Update THANKS

Posted by da...@apache.org.
Update THANKS


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/e2c55240
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/e2c55240
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/e2c55240

Branch: refs/heads/import
Commit: e2c55240324b34dfef3a5d3e5446c23dd72ed784
Parents: 3968d19
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sun Dec 18 11:29:47 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sun Dec 18 11:29:47 2011 +0000

----------------------------------------------------------------------
 THANKS.txt | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/e2c55240/THANKS.txt
----------------------------------------------------------------------
diff --git a/THANKS.txt b/THANKS.txt
index 33df40e..56344c1 100644
--- a/THANKS.txt
+++ b/THANKS.txt
@@ -11,3 +11,5 @@ Thanks to the following for patches and suggestions:
 * Paul Bonser <github.com/pib>
 
 * Roberto Aloi <github.com/prof3ta>
+
+* naoya_t <github.com/naoyat>


[03/50] git commit: Lowercase the host part when normalising URI.

Posted by da...@apache.org.
Lowercase the host part when normalising URI.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/646c13e2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/646c13e2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/646c13e2

Branch: refs/heads/import
Commit: 646c13e262d4f08ffbd66f4e778e767054b0377b
Parents: 090bebe
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Mar 14 11:54:56 2009 +0000
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Mar 14 11:54:56 2009 +0000

----------------------------------------------------------------------
 src/oauth_uri.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/646c13e2/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
index d9e3411..2baa0b0 100644
--- a/src/oauth_uri.erl
+++ b/src/oauth_uri.erl
@@ -16,8 +16,8 @@
 
 normalize(URI) ->
   case http_uri:parse(URI) of
-    {Scheme, UserInfo, Host, Port, Path, Query} ->
-      normalize(Scheme, UserInfo, Host, Port, [Path, Query]);
+    {Scheme, UserInfo, Host, Port, Path, _Query} ->
+      normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
     Else ->
       Else
   end.


[05/50] git commit: Use the public_key API; not the helper modules.

Posted by da...@apache.org.
Use the public_key API; not the helper modules.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/09857076
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/09857076
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/09857076

Branch: refs/heads/import
Commit: 09857076a1cb0963eacc2f46495bb22b9c6ef8db
Parents: 41ead73
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Fri Mar 20 09:42:22 2009 +0000
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Fri Mar 20 09:42:22 2009 +0000

----------------------------------------------------------------------
 src/oauth_rsa_sha1.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/09857076/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
index c90ba21..6f4828e 100644
--- a/src/oauth_rsa_sha1.erl
+++ b/src/oauth_rsa_sha1.erl
@@ -20,7 +20,7 @@ to_binary(Term) when is_binary(Term) ->
 
 public_key(Path) when is_list(Path) ->
   {ok, [{cert, DerCert, not_encrypted}]} = public_key:pem_to_der(Path),
-  {ok, Cert} = pubkey_cert_records:decode_cert(DerCert, otp),
+  {ok, Cert} = public_key:pkix_decode_cert(DerCert, otp),
   public_key(Cert);
 public_key(#'OTPCertificate'{tbsCertificate=Cert}) ->
   public_key(Cert);


[35/50] git commit: Update README

Posted by da...@apache.org.
Update README


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/e32d4909
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/e32d4909
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/e32d4909

Branch: refs/heads/import
Commit: e32d49094ba77fbd416a89f1a0a50a4f55ec1d27
Parents: 2b001da
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Thu Jun 23 16:16:41 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Thu Jun 23 16:16:41 2011 +0100

----------------------------------------------------------------------
 README.txt | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/e32d4909/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index 41b923a..d943634 100644
--- a/README.txt
+++ b/README.txt
@@ -10,18 +10,41 @@ Quick start (client usage):
   ...
   2> RequestTokenURL = "http://term.ie/oauth/example/request_token.php".
   ...
-  3> {ok, ResponseR} = oauth:get(RequestTokenURL, [], Consumer, "", "").
+  3> {ok, RequestTokenResponse} = oauth:get(RequestTokenURL, [], Consumer).
   ...
-  4> ParamsR = oauth_http:response_params(ResponseR).
+  4> RequestTokenParams = oauth:params_decode(RequestTokenResponse).
   ...
-  5> TokenR = oauth:token(ParamsR).
+  5> RequestToken = oauth:token(RequestTokenParams).
   ...
-  6> TokenSecretR = oauth:token_secret(ParamsR).
+  6> RequestTokenSecret = oauth:token_secret(RequestTokenParams).
   ...
   7> AccessTokenURL = "http://term.ie/oauth/example/access_token.php".
   ...
-  8> {ok, ResponseA} = oauth:get(AccessTokenURL, [], Consumer, TokenR, TokenSecretR).
+  8> {ok, AccessTokenResponse} = oauth:get(AccessTokenURL, [], Consumer, RequestToken, RequestTokenSecret).
   ...
+  9> AccessTokenParams = oauth:params_decode(AccessTokenResponse).
+  ...
+  10> AccessToken = oauth:token(AccessTokenParams).
+  ...
+  11> AccessTokenSecret = oauth:token_secret(AccessTokenParams).
+  ...
+  12> URL = "http://term.ie/oauth/example/echo_api.php".
+  ...
+  13> {ok, Response} = oauth:get(URL, [{"hello", "world"}], Consumer, AccessToken, AccessTokenSecret).
+  ...
+  14> oauth:params_decode(Response).
+  ...
+
+
+Consumer credentials are represented as follows:
+
+  {Key::string(), Secret::string(), plaintext}
+
+  {Key::string(), Secret::string(), hmac_sha1}
+
+  {Key::string(), RSAPrivateKeyPath::string(), rsa_sha1}  % client side
+
+  {Key::string(), RSACertificatePath::string(), rsa_sha1}  % server side
 
 
 The percent encoding/decoding implementations are based on those found in


[08/50] git commit: Add handy params_from_header_string/1.

Posted by da...@apache.org.
Add handy params_from_header_string/1.

For use when decoding the OAuth's "Authorization" header.

Signed-off-by: Tim Fletcher <ti...@tfletcher.com>

Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/8bf26038
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/8bf26038
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/8bf26038

Branch: refs/heads/import
Commit: 8bf26038f9b65a88c4ce5f7965da84be29523c0a
Parents: 5625976
Author: Jason Davies <ja...@jdd.local>
Authored: Tue Jul 14 06:02:42 2009 +0800
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Mon Jul 20 01:43:31 2009 +0800

----------------------------------------------------------------------
 src/oauth_uri.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/8bf26038/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
index 2baa0b0..8859ea6 100644
--- a/src/oauth_uri.erl
+++ b/src/oauth_uri.erl
@@ -1,7 +1,8 @@
 -module(oauth_uri).
 
 -export([normalize/1, calate/2, encode/1]).
--export([params_from_string/1, params_to_string/1, params_to_header_string/1]).
+-export([params_from_string/1, params_to_string/1,
+  params_from_header_string/1, params_to_header_string/1]).
 
 -import(lists, [concat/1]).
 
@@ -37,6 +38,14 @@ normalize(Scheme, UserInfo, Acc) ->
 params_to_header_string(Params) ->
   intercalate(", ", [concat([encode(K), "=\"", encode(V), "\""]) || {K, V} <- Params]).
 
+params_from_header_string(String) ->
+  [param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}])].
+
+param_from_header_string(Param) ->
+  [Key, QuotedValue] = string:tokens(Param, "="),
+  Value = string:substr(QuotedValue, 2, length(QuotedValue) - 2),
+  {decode(Key), decode(Value)}.
+
 params_from_string(Params) ->
   [param_from_string(Param) || Param <- string:tokens(Params, "&")].
 


[06/50] git commit: Specifying version key, to help automatic building tools to build the application.

Posted by da...@apache.org.
Specifying version key, to help automatic building tools to build the application.

Signed-off-by: Tim Fletcher <tw...@gmail.com>

Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/5d93e6bf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/5d93e6bf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/5d93e6bf

Branch: refs/heads/import
Commit: 5d93e6bf3b1593281a0f4a926f13c64dbcd9c4dc
Parents: 0985707
Author: Roberto Aloi <pr...@lestat-desktop.site>
Authored: Thu Jun 4 17:17:53 2009 +0800
Committer: Tim Fletcher <tw...@gmail.com>
Committed: Fri Jun 5 05:23:42 2009 +0800

----------------------------------------------------------------------
 src/oauth.app | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/5d93e6bf/src/oauth.app
----------------------------------------------------------------------
diff --git a/src/oauth.app b/src/oauth.app
index c620b03..6357b9b 100644
--- a/src/oauth.app
+++ b/src/oauth.app
@@ -1,5 +1,6 @@
 {application, oauth, [
   {description, "Erlang OAuth implementation"},
+  {vsn, "dev"},
   {modules, [
     oauth,
     oauth_hmac_sha1,
@@ -16,4 +17,4 @@
     crypto,
     inets
   ]}
-]}.
\ No newline at end of file
+]}.


[48/50] git commit: fix support for R16

Posted by da...@apache.org.
fix support for R16


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2ab4a24c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2ab4a24c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2ab4a24c

Branch: refs/heads/import
Commit: 2ab4a24c3f7db95b9ab43099ba1fa876a072e955
Parents: 1093051
Author: benoitc <bc...@gmail.com>
Authored: Fri Jun 21 23:15:17 2013 +0200
Committer: benoitc <bc...@gmail.com>
Committed: Fri Jun 21 23:15:17 2013 +0200

----------------------------------------------------------------------
 Emakefile     | 1 -
 Makefile      | 5 -----
 rebar.config  | 3 +++
 src/oauth.erl | 8 +++++++-
 4 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2ab4a24c/Emakefile
----------------------------------------------------------------------
diff --git a/Emakefile b/Emakefile
deleted file mode 100644
index a961122..0000000
--- a/Emakefile
+++ /dev/null
@@ -1 +0,0 @@
-{"src/*", [debug_info, warn_unused_vars, warn_unused_import, {outdir, "ebin"}]}.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2ab4a24c/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 09880ea..0000000
--- a/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-all:
-	@erl -make
-
-clean:
-	@rm -rf ebin/*.beam erl_crash.dump

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2ab4a24c/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
new file mode 100644
index 0000000..c839359
--- /dev/null
+++ b/rebar.config
@@ -0,0 +1,3 @@
+{erl_opts, [
+  {platform_define, "^R15", "no_sha_hmac"}
+]}.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2ab4a24c/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 64d5888..e05196a 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -15,6 +15,12 @@
 
 -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, "", "").
 
@@ -121,7 +127,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(crypto:sha_mac(Key, BaseString)).
+  base64:encode_to_string(?SHA_HMAC(Key, BaseString)).
 
 hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
   verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)).


[49/50] git commit: be compatible with R14 as well

Posted by da...@apache.org.
be compatible with R14 as well


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/b8e18a7d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/b8e18a7d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/b8e18a7d

Branch: refs/heads/import
Commit: b8e18a7d7d053540e64839926307543565147715
Parents: 2ab4a24
Author: benoitc <bc...@gmail.com>
Authored: Sat Jun 22 15:08:38 2013 +0200
Committer: benoitc <bc...@gmail.com>
Committed: Sat Jun 22 15:08:38 2013 +0200

----------------------------------------------------------------------
 rebar.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/b8e18a7d/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index c839359..21d678e 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,3 +1,3 @@
 {erl_opts, [
-  {platform_define, "^R15", "no_sha_hmac"}
+  {platform_define, "(R14|R15)", "no_sha_hmac"}
 ]}.


[21/50] git commit: Fix formatting of exports (be consistent).

Posted by da...@apache.org.
Fix formatting of exports (be consistent).


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/cfe8271c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/cfe8271c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/cfe8271c

Branch: refs/heads/import
Commit: cfe8271cc378bd8aa5e5217cd452f3f368574c67
Parents: 6b012de
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 14:46:00 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 14:46:00 2010 +0000

----------------------------------------------------------------------
 src/oauth.erl           | 17 ++---------------
 src/oauth_hmac_sha1.erl |  1 -
 src/oauth_http.erl      |  1 -
 src/oauth_plaintext.erl |  1 -
 src/oauth_rsa_sha1.erl  |  1 -
 src/oauth_unix.erl      |  1 -
 src/oauth_uri.erl       |  6 ++----
 7 files changed, 4 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 70770ba..77eed92 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -1,20 +1,7 @@
 -module(oauth).
 
--export(
-  [ get/5
-  , get/6
-  , header/1
-  , post/5
-  , post/6
-  , signature/5
-  , signature_base_string/3
-  , signed_params/6
-  , token/1
-  , token_secret/1
-  , uri/2
-  , verify/6
-  ]).
-
+-export([get/5, get/6, header/1, post/5, post/6, signature/5, signature_base_string/3,
+  signed_params/6, token/1, token_secret/1, uri/2, verify/6]).
 
 get(URL, ExtraParams, Consumer, Token, TokenSecret) ->
   get(URL, ExtraParams, Consumer, Token, TokenSecret, []).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_hmac_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_hmac_sha1.erl b/src/oauth_hmac_sha1.erl
index 69064ed..975278f 100644
--- a/src/oauth_hmac_sha1.erl
+++ b/src/oauth_hmac_sha1.erl
@@ -2,7 +2,6 @@
 
 -export([signature/3, verify/4]).
 
-
 signature(BaseString, CS, TS) ->
   Key = oauth_uri:calate("&", [CS, TS]),
   base64:encode_to_string(crypto:sha_mac(Key, BaseString)).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_http.erl
----------------------------------------------------------------------
diff --git a/src/oauth_http.erl b/src/oauth_http.erl
index 32261d3..02128f7 100644
--- a/src/oauth_http.erl
+++ b/src/oauth_http.erl
@@ -2,7 +2,6 @@
 
 -export([get/1, get/2, post/2, post/3, response_params/1, response_body/1, response_code/1]).
 
-
 get(URL) ->
   get(URL, []).
 

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_plaintext.erl
----------------------------------------------------------------------
diff --git a/src/oauth_plaintext.erl b/src/oauth_plaintext.erl
index d8085e0..fbdc0a3 100644
--- a/src/oauth_plaintext.erl
+++ b/src/oauth_plaintext.erl
@@ -2,7 +2,6 @@
 
 -export([signature/2, verify/3]).
 
-
 signature(CS, TS) ->
   oauth_uri:calate("&", [CS, TS]).
 

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
index 6f4828e..a7b570c 100644
--- a/src/oauth_rsa_sha1.erl
+++ b/src/oauth_rsa_sha1.erl
@@ -4,7 +4,6 @@
 
 -include_lib("public_key/include/public_key.hrl").
 
-
 signature(BaseString, PrivateKeyPath) ->
   {ok, [Info]} = public_key:pem_to_der(PrivateKeyPath),
   {ok, PrivateKey} = public_key:decode_private_key(Info),

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_unix.erl
----------------------------------------------------------------------
diff --git a/src/oauth_unix.erl b/src/oauth_unix.erl
index 73ca314..27f6de9 100644
--- a/src/oauth_unix.erl
+++ b/src/oauth_unix.erl
@@ -2,7 +2,6 @@
 
 -export([timestamp/0]).
 
-
 timestamp() ->
   timestamp(calendar:universal_time()).
 

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cfe8271c/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
index 5023f98..5c33a1e 100644
--- a/src/oauth_uri.erl
+++ b/src/oauth_uri.erl
@@ -1,12 +1,10 @@
 -module(oauth_uri).
 
--export([normalize/1, calate/2, encode/1]).
--export([params_from_string/1, params_to_string/1,
-  params_from_header_string/1, params_to_header_string/1]).
+-export([calate/2, encode/1, normalize/1, params_from_string/1,
+  params_from_header_string/1, params_to_string/1, params_to_header_string/1]).
 
 -import(lists, [concat/1]).
 
-
 normalize(URI) ->
   case http_uri:parse(URI) of
     {Scheme, UserInfo, Host, Port, Path, _Query} ->


[07/50] git commit: Fix suspected bug in PLAINTEXT signature.

Posted by da...@apache.org.
Fix suspected bug in PLAINTEXT signature.

This JavaScript implementation:
http://oauth.googlecode.com/svn/code/javascript/oauth.js appears to
indicate that the signature only needs to be encoded once, not twice.
This makes erlang-oauth comply, assuming it is passed an already-decoded
signature to verify (which is usual when using something like Mochiweb,
for example).

Signed-off-by: Tim Fletcher <ti...@tfletcher.com>

Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/56259760
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/56259760
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/56259760

Branch: refs/heads/import
Commit: 562597602b054f8e2412ff54d7957839aa88c2c5
Parents: 5d93e6b
Author: Jason Davies <ja...@jdd.local>
Authored: Tue Jul 14 05:59:42 2009 +0800
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Mon Jul 20 01:43:30 2009 +0800

----------------------------------------------------------------------
 src/oauth_plaintext.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/56259760/src/oauth_plaintext.erl
----------------------------------------------------------------------
diff --git a/src/oauth_plaintext.erl b/src/oauth_plaintext.erl
index 1aae8fc..d8085e0 100644
--- a/src/oauth_plaintext.erl
+++ b/src/oauth_plaintext.erl
@@ -4,7 +4,7 @@
 
 
 signature(CS, TS) ->
-  oauth_uri:encode(oauth_uri:calate("&", [CS, TS])).
+  oauth_uri:calate("&", [CS, TS]).
 
 verify(Signature, CS, TS) ->
   Signature =:= signature(CS, TS).


[25/50] git commit: Up version to 1.0.2.

Posted by da...@apache.org.
Up version to 1.0.2.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/d9bfb30d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/d9bfb30d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/d9bfb30d

Branch: refs/heads/import
Commit: d9bfb30dab5e2ef20a0a3192a5872811756185dd
Parents: 09fa180
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 15:59:15 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 15:59:15 2010 +0000

----------------------------------------------------------------------
 ebin/oauth.app | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/d9bfb30d/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index 4a2563b..445762b 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,6 +1,6 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.0.1"},
+  {vsn, "1.0.2"},
   {modules, [
     oauth,
     oauth_client,


[32/50] git commit: Move oauth_client module to github.com/tim/erlang-oauth-examples

Posted by da...@apache.org.
Move oauth_client module to github.com/tim/erlang-oauth-examples


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/9e43769b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/9e43769b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/9e43769b

Branch: refs/heads/import
Commit: 9e43769b9402f91975208274a0cd8f3e15f86084
Parents: 18cee77
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Thu Jun 23 13:26:10 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Thu Jun 23 13:26:10 2011 +0100

----------------------------------------------------------------------
 src/oauth_client.erl | 149 ----------------------------------------------
 1 file changed, 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/9e43769b/src/oauth_client.erl
----------------------------------------------------------------------
diff --git a/src/oauth_client.erl b/src/oauth_client.erl
deleted file mode 100644
index 2bd24c0..0000000
--- a/src/oauth_client.erl
+++ /dev/null
@@ -1,149 +0,0 @@
--module(oauth_client).
-
--behaviour(gen_server).
-
--export([access_token_params/1, deauthorize/1, get/2, get/3, get/4, get_access_token/2,
-  get_access_token/3, get_access_token/4, get_request_token/2, get_request_token/3,
-  get_request_token/4, start/1, start/2, start_link/1, start_link/2, stop/1]).
-
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
-
-%%============================================================================
-%% API functions
-%%============================================================================
-
-start(Consumer) ->
-  gen_server:start(?MODULE, Consumer, []).
-
-start(ServerName, Consumer) ->
-  gen_server:start(ServerName, ?MODULE, Consumer, []).
-
-start_link(Consumer) ->
-  gen_server:start_link(?MODULE, Consumer, []).
-
-start_link(ServerName, Consumer) ->
-  gen_server:start_link(ServerName, ?MODULE, Consumer, []).
-
-get_request_token(Client, URL) ->
-  get_request_token(Client, URL, [], header).
-
-get_request_token(Client, URL, Params) ->
-  gen_server:call(Client, {get_request_token, URL, Params, header}).
-
-get_request_token(Client, URL, Params, ParamsMethod) ->
-  gen_server:call(Client, {get_request_token, URL, Params, ParamsMethod}).
-
-get_access_token(Client, URL) ->
-  get_access_token(Client, URL, [], header).
-
-get_access_token(Client, URL, Params) ->
-  gen_server:call(Client, {get_access_token, URL, Params, header}).
-
-get_access_token(Client, URL, Params, ParamsMethod) ->
-  gen_server:call(Client, {get_access_token, URL, Params, ParamsMethod}).
-
-get(Client, URL) ->
-  get(Client, URL, [], header).
-
-get(Client, URL, Params) ->
-  gen_server:call(Client, {get, URL, Params, header}).
-
-get(Client, URL, Params, ParamsMethod) ->
-  gen_server:call(Client, {get, URL, Params, ParamsMethod}).
-
-access_token_params(Client) ->
-  gen_server:call(Client, {access_token_params}).
-
-deauthorize(Client) ->
-  gen_server:cast(Client, deauthorize).
-
-stop(Client) ->
-  gen_server:cast(Client, stop).
-
-%%============================================================================
-%% Helper functions
-%%============================================================================
-
-oauth_get(header, URL, Params, Consumer, Token, TokenSecret) ->
-  Signed = oauth:signed_params("GET", URL, Params, Consumer, Token, TokenSecret),
-  {AuthorizationParams, QueryParams} = lists:partition(fun({K, _}) -> lists:prefix("oauth_", K) end, Signed),
-  Request = {oauth:uri(URL, QueryParams), [oauth:header(AuthorizationParams)]},
-  httpc:request(get, Request, [{autoredirect, false}], []);
-oauth_get(querystring, URL, Params, Consumer, Token, TokenSecret) ->
-  oauth:get(URL, Params, Consumer, Token, TokenSecret).
-
-%%============================================================================
-%% gen_server callbacks
-%%============================================================================
-
-init(Consumer) ->
-  {ok, {Consumer}}.
-
-handle_call({get_request_token, URL, Params, ParamsMethod}, _From, State={Consumer}) ->
-  case oauth_get(ParamsMethod, URL, Params, Consumer, "", "") of
-    {ok, Response} ->
-      case oauth_http:response_code(Response) of
-        200 ->
-          RParams = oauth_http:response_params(Response),
-          {reply, {ok, oauth:token(RParams)}, {Consumer, RParams}};
-        _ ->
-          {reply, Response, State}
-      end;
-    Error ->
-      {reply, Error, State}
-  end;
-handle_call({get_access_token, URL, Params, ParamsMethod}, _From, State={Consumer, RParams}) ->
-  case oauth_get(ParamsMethod, URL, Params, Consumer, oauth:token(RParams), oauth:token_secret(RParams)) of
-    {ok, Response} ->
-      case oauth_http:response_code(Response) of
-        200 ->
-          AParams = oauth_http:response_params(Response),
-          {reply, ok, {Consumer, RParams, AParams}};
-        _ ->
-          {reply, Response, State}
-      end;
-    Error ->
-      {reply, Error, State}
-  end;
-handle_call({get, URL, Params, ParamsMethod}, _From, State={Consumer, _RParams, AParams}) ->
-  case oauth_get(ParamsMethod, URL, Params, Consumer, oauth:token(AParams), oauth:token_secret(AParams)) of
-    {ok, Response={{_, Status, _}, Headers, Body}} ->
-      case Status of
-        200 ->
-          case proplists:get_value("content-type", Headers) of
-            undefined ->
-              {reply, {ok, Headers, Body}, State};
-            ContentType ->
-              MediaType = hd(string:tokens(ContentType, ";")),
-              case lists:suffix("/xml", MediaType) orelse lists:suffix("+xml", MediaType) of
-                true ->
-                  {XML, []} = xmerl_scan:string(Body),
-                  {reply, {ok, Headers, XML}, State};
-                false ->
-                  {reply, {ok, Headers, Body}, State}
-              end
-          end;
-        _ ->
-          {reply, Response, State}
-      end;
-    Error ->
-      {reply, Error, State}
-  end;
-handle_call({access_token_params}, _From, State={_Consumer, _RParams, AParams}) ->
-  {reply, AParams, State}.
-
-handle_cast(deauthorize, {Consumer, _RParams}) ->
-  {noreply, {Consumer}};
-handle_cast(deauthorize, {Consumer, _RParams, _AParams}) ->
-  {noreply, {Consumer}};
-handle_cast(stop, State) ->
-  {stop, normal, State}.
-
-handle_info(_Msg, State) ->
-  {noreply, State}.
-
-code_change(_OldVsn, State, _Extra) ->
-  {ok, State}.
-
-terminate(normal, _State) ->
-  ok.


[17/50] git commit: Allow parsing of requests with no OAuth headers.

Posted by da...@apache.org.
Allow parsing of requests with no OAuth headers.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/cec39b1d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/cec39b1d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/cec39b1d

Branch: refs/heads/import
Commit: cec39b1d83d18988597a1fbbbb0858d8a43fdaf7
Parents: 7d85d3e
Author: Jan Lehnardt <ja...@apache.org>
Authored: Fri Nov 26 14:28:09 2010 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Fri Nov 26 14:28:09 2010 +0100

----------------------------------------------------------------------
 src/oauth_uri.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/cec39b1d/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
index c019427..5023f98 100644
--- a/src/oauth_uri.erl
+++ b/src/oauth_uri.erl
@@ -31,7 +31,7 @@ params_to_header_string(Params) ->
   intercalate(", ", [concat([encode(K), "=\"", encode(V), "\""]) || {K, V} <- Params]).
 
 params_from_header_string(String) ->
-  [param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}])].
+  [param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}]), Param =/= ""].
 
 param_from_header_string(Param) ->
   [Key, QuotedValue] = string:tokens(Param, "="),


[33/50] git commit: Combine modules and refactor

Posted by da...@apache.org.
Combine modules and refactor


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/fc5f528c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/fc5f528c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/fc5f528c

Branch: refs/heads/import
Commit: fc5f528cea05b6b0b5e3ace0300268a330b01ac6
Parents: 9e43769
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Thu Jun 23 16:00:29 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Thu Jun 23 16:00:29 2011 +0100

----------------------------------------------------------------------
 src/oauth.erl           | 282 ++++++++++++++++++++++++++++++++++---------
 src/oauth_hmac_sha1.erl |  10 --
 src/oauth_http.erl      |  27 -----
 src/oauth_plaintext.erl |   9 --
 src/oauth_rsa_sha1.erl  |  30 -----
 src/oauth_uri.erl       |  96 ---------------
 6 files changed, 226 insertions(+), 228 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index f2fa946..fe66d4a 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -1,29 +1,41 @@
 -module(oauth).
 
--export([get/5, get/6, header/1, post/5, post/6, signature/5, signature_base_string/3,
-  signed_params/6, token/1, token_secret/1, uri/2, verify/6]).
+-export([get/5, get/6, post/5, post/6, 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]).
+
+-export([plaintext_verify/3, hmac_sha1_verify/6, hmac_sha1_verify/4,
+  rsa_sha1_verify/5, rsa_sha1_verify/3]).
+
+-export([header_params_encode/1, header_params_decode/1,
+  uri_params_encode/1, uri_params_decode/1]).
+
+-include_lib("public_key/include/public_key.hrl").
 
 get(URL, ExtraParams, Consumer, Token, TokenSecret) ->
   get(URL, ExtraParams, Consumer, Token, TokenSecret, []).
 
 get(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
-  SignedParams = signed_params("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
-  oauth_http:get(uri(URL, SignedParams), HttpcOptions).
+  SignedParams = sign("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
+  http_get(uri(URL, SignedParams), HttpcOptions).
 
 post(URL, ExtraParams, Consumer, Token, TokenSecret) ->
   post(URL, ExtraParams, Consumer, Token, TokenSecret, []).
 
 post(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
-  SignedParams = signed_params("POST", URL, ExtraParams, Consumer, Token, TokenSecret),
-  oauth_http:post(URL, oauth_uri:params_to_string(SignedParams), HttpcOptions).
+  SignedParams = sign("POST", URL, ExtraParams, Consumer, Token, TokenSecret),
+  http_post(URL, uri_params_encode(SignedParams), HttpcOptions).
 
 uri(Base, []) ->
   Base;
 uri(Base, Params) ->
-  lists:concat([Base, "?", oauth_uri:params_to_string(Params)]).
+  lists:concat([Base, "?", uri_params_encode(Params)]).
 
 header(Params) ->
-  {"Authorization", "OAuth " ++ oauth_uri:params_to_header_string(Params)}.
+  {"Authorization", "OAuth " ++ header_params_encode(Params)}.
 
 token(Params) ->
   proplists:get_value("oauth_token", Params).
@@ -31,63 +43,123 @@ token(Params) ->
 token_secret(Params) ->
   proplists:get_value("oauth_token_secret", Params).
 
+consumer_key(_Consumer={Key, _, _}) ->
+  Key.
+
+consumer_secret(_Consumer={_, Secret, _}) ->
+  Secret.
+
+signature_method(_Consumer={_, _, Method}) ->
+  Method.
+
+sign(HttpMethod, URL, Params, Consumer, Token, TokenSecret) ->
+  SignatureParams = signature_params(Consumer, Params, Token),
+  Signature = signature(HttpMethod, URL, SignatureParams, Consumer, TokenSecret),
+  [{"oauth_signature", Signature} | SignatureParams].
+
+signature_params(Consumer, Params, "") ->
+  signature_params(Consumer, Params);
+signature_params(Consumer, Params, Token) ->
+  signature_params(Consumer, [{"oauth_token", Token} | Params]).
+
+signature_params(Consumer, Params) ->
+  Timestamp = unix_timestamp(),
+  Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth
+  [ {"oauth_version", "1.0"}
+  , {"oauth_nonce", Nonce}
+  , {"oauth_timestamp", integer_to_list(Timestamp)}
+  , {"oauth_signature_method", signature_method_string(Consumer)}
+  , {"oauth_consumer_key", consumer_key(Consumer)}
+  | Params
+  ].
+
 verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
   case signature_method(Consumer) of
     plaintext ->
-      oauth_plaintext:verify(Signature, consumer_secret(Consumer), TokenSecret);
+      plaintext_verify(Signature, Consumer, TokenSecret);
     hmac_sha1 ->
-      BaseString = signature_base_string(HttpMethod, URL, Params),
-      oauth_hmac_sha1:verify(Signature, BaseString, consumer_secret(Consumer), TokenSecret);
+      hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret);
     rsa_sha1 ->
-      BaseString = signature_base_string(HttpMethod, URL, Params),
-      oauth_rsa_sha1:verify(Signature, BaseString, consumer_secret(Consumer))
+      rsa_sha1_verify(Signature, HttpMethod, URL, Params, Consumer)
   end.
 
-signed_params(HttpMethod, URL, ExtraParams, Consumer, Token, TokenSecret) ->
-  Params = token_param(Token, params(Consumer, ExtraParams)),
-  [{"oauth_signature", signature(HttpMethod, URL, Params, Consumer, TokenSecret)}|Params].
-
 signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
   case signature_method(Consumer) of
     plaintext ->
-      oauth_plaintext:signature(consumer_secret(Consumer), TokenSecret);
+      plaintext_signature(Consumer, TokenSecret);
     hmac_sha1 ->
-      BaseString = signature_base_string(HttpMethod, URL, Params),
-      oauth_hmac_sha1:signature(BaseString, consumer_secret(Consumer), TokenSecret);
+      hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret);
+    rsa_sha1 ->
+      rsa_sha1_signature(HttpMethod, URL, Params, Consumer)
+  end.
+
+signature_method_string(Consumer) ->
+  case signature_method(Consumer) of
+    plaintext ->
+      "PLAINTEXT";
+    hmac_sha1 ->
+      "HMAC-SHA1";
     rsa_sha1 ->
-      BaseString = signature_base_string(HttpMethod, URL, Params),
-      oauth_rsa_sha1:signature(BaseString, consumer_secret(Consumer))
+      "RSA-SHA1"
   end.
 
+plaintext_signature(Consumer, TokenSecret) ->
+  uri_join([consumer_secret(Consumer), TokenSecret]).
+
+plaintext_verify(Signature, Consumer, TokenSecret) ->
+  Signature =:= plaintext_signature(Consumer, TokenSecret).
+
+hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret) ->
+  BaseString = signature_base_string(HttpMethod, URL, Params),
+  hmac_sha1_signature(BaseString, Consumer, TokenSecret).
+
+hmac_sha1_signature(BaseString, Consumer, TokenSecret) ->
+  Key = uri_join([consumer_secret(Consumer), TokenSecret]),
+  base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
+
+hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
+  Signature =:= hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret).
+
+hmac_sha1_verify(Signature, BaseString, Consumer, TokenSecret) ->
+  Signature =:= hmac_sha1_signature(BaseString, Consumer, TokenSecret).
+
+rsa_sha1_signature(HttpMethod, URL, Params, Consumer) ->
+  BaseString = signature_base_string(HttpMethod, URL, Params),
+  rsa_sha1_signature(BaseString, Consumer).
+
+rsa_sha1_signature(BaseString, Consumer) ->
+  Key = read_private_key(consumer_secret(Consumer)),
+  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), sha, Key)).
+
+rsa_sha1_verify(Signature, HttpMethod, URL, Params, Consumer) ->
+  BaseString = signature_base_string(HttpMethod, URL, Params),
+  rsa_sha1_verify(Signature, BaseString, Consumer).
+
+rsa_sha1_verify(Signature, BaseString, Consumer) ->
+  Key = read_cert_key(consumer_secret(Consumer)),
+  public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), Key).
+
 signature_base_string(HttpMethod, URL, Params) ->
-  NormalizedURL = oauth_uri:normalize(URL),
-  NormalizedParams = normalized_params_string(Params),
-  oauth_uri:calate("&", [HttpMethod, NormalizedURL, NormalizedParams]).
+  uri_join([HttpMethod, uri_normalize(URL), params_encode(Params)]).
 
-normalized_params_string(Params) ->
+params_encode(Params) ->
   % cf. http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
-  Encoded = [{oauth_uri:encode(K), oauth_uri:encode(V)} || {K, V} <- Params],
+  Encoded = [{uri_encode(K), uri_encode(V)} || {K, V} <- Params],
   Sorted = lists:sort(Encoded),
   Concatenated = [lists:concat([K, "=", V]) || {K, V} <- Sorted],
   string:join(Concatenated, "&").
 
-token_param("", Params) ->
-  Params;
-token_param(Token, Params) ->
-  [{"oauth_token", Token}|Params].
+params_decode(_Response={{_, _, _}, _, Body}) ->
+  uri_params_decode(Body).
 
-params(Consumer, Params) ->
-  Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth
-  params(Consumer, unix_timestamp(), Nonce, Params).
+http_get(URL, Options) ->
+  http_request(get, {URL, []}, Options).
 
-params(Consumer, Timestamp, Nonce, Params) ->
-  [ {"oauth_version", "1.0"}
-  , {"oauth_nonce", Nonce}
-  , {"oauth_timestamp", integer_to_list(Timestamp)}
-  , {"oauth_signature_method", signature_method_string(Consumer)}
-  , {"oauth_consumer_key", consumer_key(Consumer)}
-  | Params
-  ].
+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).
 
 unix_timestamp() ->
   unix_timestamp(calendar:universal_time()).
@@ -101,21 +173,119 @@ unix_epoch() ->
 unix_seconds(DateTime) ->
   calendar:datetime_to_gregorian_seconds(DateTime).
 
-signature_method_string(Consumer) ->
-  case signature_method(Consumer) of
-    plaintext ->
-      "PLAINTEXT";
-    hmac_sha1 ->
-      "HMAC-SHA1";
-    rsa_sha1 ->
-      "RSA-SHA1"
+read_cert_key(Path) when is_list(Path) ->
+  {ok, Contents} = file:read_file(Path),
+  [{'Certificate', DerCert, not_encrypted}] = public_key:pem_decode(Contents),
+  read_cert_key(public_key:pkix_decode_cert(DerCert, otp));
+read_cert_key(#'OTPCertificate'{tbsCertificate=Cert}) ->
+  read_cert_key(Cert);
+read_cert_key(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
+  read_cert_key(Info);
+read_cert_key(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
+  Key.
+
+read_private_key(Path) ->
+  {ok, Contents} = file:read_file(Path),
+  [Info] = public_key:pem_decode(Contents),
+  public_key:pem_entry_decode(Info).
+
+to_binary(Term) when is_list(Term) ->
+  list_to_binary(Term);
+to_binary(Term) when is_binary(Term) ->
+  Term.
+
+header_params_encode(Params) ->
+  intercalate(", ", [lists:concat([uri_encode(K), "=\"", uri_encode(V), "\""]) || {K, V} <- Params]).
+
+header_params_decode(String) ->
+  [header_param_decode(Param) || Param <- re:split(String, ",\\s*", [{return, list}]), Param =/= ""].
+
+header_param_decode(Param) ->
+  [Key, QuotedValue] = string:tokens(Param, "="),
+  Value = string:substr(QuotedValue, 2, length(QuotedValue) - 2),
+  {uri_decode(Key), uri_decode(Value)}.
+
+uri_normalize(URI) ->
+  case http_uri:parse(URI) of
+    {Scheme, UserInfo, Host, Port, Path, _Query} ->
+      uri_normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
+    Else ->
+      Else
   end.
 
-signature_method(_Consumer={_, _, Method}) ->
-  Method.
+uri_normalize(http, UserInfo, Host, 80, Acc) ->
+  uri_normalize(http, UserInfo, [Host|Acc]);
+uri_normalize(https, UserInfo, Host, 443, Acc) ->
+  uri_normalize(https, UserInfo, [Host|Acc]);
+uri_normalize(Scheme, UserInfo, Host, Port, Acc) ->
+  uri_normalize(Scheme, UserInfo, [Host, ":", Port|Acc]).
 
-consumer_secret(_Consumer={_, Secret, _}) ->
-  Secret.
+uri_normalize(Scheme, [], Acc) ->
+  lists:concat([Scheme, "://" | Acc]);
+uri_normalize(Scheme, UserInfo, Acc) ->
+  lists:concat([Scheme, "://", UserInfo, "@" | Acc]).
 
-consumer_key(_Consumer={Key, _, _}) ->
-  Key.
+uri_params_encode(Params) ->
+  intercalate("&", [uri_join([K, V], "=") || {K, V} <- Params]).
+
+uri_params_decode(String) ->
+  [uri_param_decode(Substring) || Substring <- string:tokens(String, "&")].
+
+uri_param_decode(String) ->
+  [Key, Value] = string:tokens(String, "="),
+  {uri_decode(Key), uri_decode(Value)}.
+
+uri_join(Values) ->
+  uri_join(Values, "&").
+
+uri_join(Values, Separator) ->
+  string:join([uri_encode(Value) || Value <- Values], Separator).
+
+intercalate(Sep, Xs) ->
+  lists:concat(intersperse(Sep, Xs)).
+
+intersperse(_, []) ->
+  [];
+intersperse(_, [X]) ->
+  [X];
+intersperse(Sep, [X | Xs]) ->
+  [X, Sep | intersperse(Sep, Xs)].
+
+uri_encode(Term) when is_integer(Term) ->
+  integer_to_list(Term);
+uri_encode(Term) when is_atom(Term) ->
+  uri_encode(atom_to_list(Term));
+uri_encode(Term) when is_list(Term) ->
+  uri_encode(lists:reverse(Term, []), []).
+
+-define(is_alphanum(C), C >= $A, C =< $Z; C >= $a, C =< $z; C >= $0, C =< $9).
+
+uri_encode([X | T], Acc) when ?is_alphanum(X); X =:= $-; X =:= $_; X =:= $.; X =:= $~ ->
+  uri_encode(T, [X | Acc]);
+uri_encode([X | T], Acc) ->
+  NewAcc = [$%, dec2hex(X bsr 4), dec2hex(X band 16#0f) | Acc],
+  uri_encode(T, NewAcc);
+uri_encode([], Acc) ->
+  Acc.
+
+uri_decode(Str) when is_list(Str) ->
+  uri_decode(Str, []).
+
+uri_decode([$%, A, B | T], Acc) ->
+  uri_decode(T, [(hex2dec(A) bsl 4) + hex2dec(B) | Acc]);
+uri_decode([X | T], Acc) ->
+  uri_decode(T, [X | Acc]);
+uri_decode([], Acc) ->
+  lists:reverse(Acc, []).
+
+-compile({inline, [{dec2hex, 1}, {hex2dec, 1}]}).
+
+dec2hex(N) when N >= 10 andalso N =< 15 ->
+  N + $A - 10;
+dec2hex(N) when N >= 0 andalso N =< 9 ->
+  N + $0.
+
+hex2dec(C) when C >= $A andalso C =< $F ->
+  C - $A + 10;
+hex2dec(C) when C >= $0 andalso C =< $9 ->
+  C - $0.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth_hmac_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_hmac_sha1.erl b/src/oauth_hmac_sha1.erl
deleted file mode 100644
index 975278f..0000000
--- a/src/oauth_hmac_sha1.erl
+++ /dev/null
@@ -1,10 +0,0 @@
--module(oauth_hmac_sha1).
-
--export([signature/3, verify/4]).
-
-signature(BaseString, CS, TS) ->
-  Key = oauth_uri:calate("&", [CS, TS]),
-  base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
-
-verify(Signature, BaseString, CS, TS) ->
-  Signature =:= signature(BaseString, CS, TS).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth_http.erl
----------------------------------------------------------------------
diff --git a/src/oauth_http.erl b/src/oauth_http.erl
deleted file mode 100644
index 02128f7..0000000
--- a/src/oauth_http.erl
+++ /dev/null
@@ -1,27 +0,0 @@
--module(oauth_http).
-
--export([get/1, get/2, post/2, post/3, response_params/1, response_body/1, response_code/1]).
-
-get(URL) ->
-  get(URL, []).
-
-get(URL, Options) ->
-  request(get, {URL, []}, Options).
-
-post(URL, Data) ->
-  post(URL, Data, []).
-
-post(URL, Data, Options) ->
-  request(post, {URL, [], "application/x-www-form-urlencoded", Data}, Options).
-
-request(Method, Request, Options) ->
-  httpc:request(Method, Request, [{autoredirect, false}], Options).
-
-response_params(Response) ->
-  oauth_uri:params_from_string(response_body(Response)).
-
-response_body({{_, _, _}, _, Body}) ->
-  Body.
-
-response_code({{_, Code, _}, _, _}) ->
-  Code.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth_plaintext.erl
----------------------------------------------------------------------
diff --git a/src/oauth_plaintext.erl b/src/oauth_plaintext.erl
deleted file mode 100644
index fbdc0a3..0000000
--- a/src/oauth_plaintext.erl
+++ /dev/null
@@ -1,9 +0,0 @@
--module(oauth_plaintext).
-
--export([signature/2, verify/3]).
-
-signature(CS, TS) ->
-  oauth_uri:calate("&", [CS, TS]).
-
-verify(Signature, CS, TS) ->
-  Signature =:= signature(CS, TS).

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
deleted file mode 100644
index 99bd926..0000000
--- a/src/oauth_rsa_sha1.erl
+++ /dev/null
@@ -1,30 +0,0 @@
--module(oauth_rsa_sha1).
-
--export([signature/2, verify/3]).
-
--include_lib("public_key/include/public_key.hrl").
-
-signature(BaseString, PrivateKeyPath) ->
-  {ok, Contents} = file:read_file(PrivateKeyPath),
-  [Info] = public_key:pem_decode(Contents),
-  PrivateKey = public_key:pem_entry_decode(Info),
-  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), sha, PrivateKey)).
-
-verify(Signature, BaseString, Cert) ->
-  public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), pkey(Cert)).
-
-to_binary(Term) when is_list(Term) ->
-  list_to_binary(Term);
-to_binary(Term) when is_binary(Term) ->
-  Term.
-
-pkey(Path) when is_list(Path) ->
-  {ok, Contents} = file:read_file(Path),
-  [{'Certificate', DerCert, not_encrypted}] = public_key:pem_decode(Contents),
-  pkey(public_key:pkix_decode_cert(DerCert, otp));
-pkey(#'OTPCertificate'{tbsCertificate=Cert}) ->
-  pkey(Cert);
-pkey(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
-  pkey(Info);
-pkey(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
-  Key.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/fc5f528c/src/oauth_uri.erl
----------------------------------------------------------------------
diff --git a/src/oauth_uri.erl b/src/oauth_uri.erl
deleted file mode 100644
index 5c33a1e..0000000
--- a/src/oauth_uri.erl
+++ /dev/null
@@ -1,96 +0,0 @@
--module(oauth_uri).
-
--export([calate/2, encode/1, normalize/1, params_from_string/1,
-  params_from_header_string/1, params_to_string/1, params_to_header_string/1]).
-
--import(lists, [concat/1]).
-
-normalize(URI) ->
-  case http_uri:parse(URI) of
-    {Scheme, UserInfo, Host, Port, Path, _Query} ->
-      normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
-    Else ->
-      Else
-  end.
-
-normalize(http, UserInfo, Host, 80, Acc) ->
-  normalize(http, UserInfo, [Host|Acc]);
-normalize(https, UserInfo, Host, 443, Acc) ->
-  normalize(https, UserInfo, [Host|Acc]);
-normalize(Scheme, UserInfo, Host, Port, Acc) ->
-  normalize(Scheme, UserInfo, [Host, ":", Port|Acc]).
-
-normalize(Scheme, [], Acc) ->
-  concat([Scheme, "://"|Acc]);
-normalize(Scheme, UserInfo, Acc) ->
-  concat([Scheme, "://", UserInfo, "@"|Acc]).
-
-params_to_header_string(Params) ->
-  intercalate(", ", [concat([encode(K), "=\"", encode(V), "\""]) || {K, V} <- Params]).
-
-params_from_header_string(String) ->
-  [param_from_header_string(Param) || Param <- re:split(String, ",\\s*", [{return, list}]), Param =/= ""].
-
-param_from_header_string(Param) ->
-  [Key, QuotedValue] = string:tokens(Param, "="),
-  Value = string:substr(QuotedValue, 2, length(QuotedValue) - 2),
-  {decode(Key), decode(Value)}.
-
-params_from_string(Params) ->
-  [param_from_string(Param) || Param <- string:tokens(Params, "&")].
-
-param_from_string(Param) ->
-  list_to_tuple([decode(Value) || Value <- string:tokens(Param, "=")]).
-
-params_to_string(Params) ->
-  intercalate("&", [calate("=", [K, V]) || {K, V} <- Params]).
-
-calate(Sep, Xs) ->
-  intercalate(Sep, [encode(X) || X <- Xs]).
-
-intercalate(Sep, Xs) ->
-  concat(intersperse(Sep, Xs)).
-
-intersperse(_, []) -> [];
-intersperse(_, [X]) -> [X];
-intersperse(Sep, [X|Xs]) ->
-  [X, Sep|intersperse(Sep, Xs)].
-
--define(is_alphanum(C), C >= $A, C =< $Z; C >= $a, C =< $z; C >= $0, C =< $9).
-
-encode(Term) when is_integer(Term) ->
-  integer_to_list(Term);
-encode(Term) when is_atom(Term) ->
-  encode(atom_to_list(Term));
-encode(Term) when is_list(Term) ->
-  encode(lists:reverse(Term, []), []).
-
-encode([X | T], Acc) when ?is_alphanum(X); X =:= $-; X =:= $_; X =:= $.; X =:= $~ ->
-  encode(T, [X | Acc]);
-encode([X | T], Acc) ->
-  NewAcc = [$%, dec2hex(X bsr 4), dec2hex(X band 16#0f) | Acc],
-  encode(T, NewAcc);
-encode([], Acc) ->
-  Acc.
-
-decode(Str) when is_list(Str) ->
-  decode(Str, []).
-
-decode([$%, A, B | T], Acc) ->
-  decode(T, [(hex2dec(A) bsl 4) + hex2dec(B) | Acc]);
-decode([X | T], Acc) ->
-  decode(T, [X | Acc]);
-decode([], Acc) ->
-  lists:reverse(Acc, []).
-
--compile({inline, [{dec2hex, 1}, {hex2dec, 1}]}).
-
-dec2hex(N) when N >= 10 andalso N =< 15 ->
-  N + $A - 10;
-dec2hex(N) when N >= 0 andalso N =< 9 ->
-  N + $0.
-
-hex2dec(C) when C >= $A andalso C =< $F ->
-  C - $A + 10;
-hex2dec(C) when C >= $0 andalso C =< $9 ->
-  C - $0.


[43/50] git commit: Merge pull request #9 from naoyat/master

Posted by da...@apache.org.
Merge pull request #9 from naoyat/master

http_uri:parse(URI) now returns {ok,{Scheme,...}} in R15B

Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/3968d19a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/3968d19a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/3968d19a

Branch: refs/heads/import
Commit: 3968d19a95faf2b7acc572c316c5d9d9447ac06b
Parents: 7969309 89ebe2c
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sun Dec 18 03:28:26 2011 -0800
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sun Dec 18 03:28:26 2011 -0800

----------------------------------------------------------------------
 src/oauth.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------



[37/50] git commit: Use a constant time algorithm to compare signature strings.

Posted by da...@apache.org.
Use a constant time algorithm to compare signature strings.

This guards against timing attacks of the class outlined
in http://codahale.com/a-lesson-in-timing-attacks/


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/8abf2d69
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/8abf2d69
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/8abf2d69

Branch: refs/heads/import
Commit: 8abf2d69fa5aa4c78c1a6222336d6e0dff7904b3
Parents: 29cb478
Author: Jan Lehnardt <ja...@apache.org>
Authored: Fri Oct 14 15:57:17 2011 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Fri Oct 14 15:59:59 2011 +0200

----------------------------------------------------------------------
 src/oauth.erl | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/8abf2d69/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index c46728f..692ac19 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -124,10 +124,10 @@ hmac_sha1_signature(BaseString, Consumer, TokenSecret) ->
   base64:encode_to_string(crypto:sha_mac(Key, BaseString)).
 
 hmac_sha1_verify(Signature, HttpMethod, URL, Params, Consumer, TokenSecret) ->
-  Signature =:= hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret).
+  verify_in_constant_time(Signature, hmac_sha1_signature(HttpMethod, URL, Params, Consumer, TokenSecret)).
 
 hmac_sha1_verify(Signature, BaseString, Consumer, TokenSecret) ->
-  Signature =:= hmac_sha1_signature(BaseString, Consumer, TokenSecret).
+  verify_in_constant_time(Signature, hmac_sha1_signature(BaseString, Consumer, TokenSecret)).
 
 rsa_sha1_signature(HttpMethod, URL, Params, Consumer) ->
   BaseString = signature_base_string(HttpMethod, URL, Params),
@@ -145,6 +145,22 @@ rsa_sha1_verify(Signature, BaseString, Consumer) ->
   Key = read_cert_key(consumer_secret(Consumer)),
   public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), Key).
 
+verify_in_constant_time([X|RestX], [Y|RestY], Result) ->
+    verify_in_constant_time(RestX, RestY, (X bxor Y) bor Result);
+verify_in_constant_time([], [], Result) ->
+    Result == 0.
+
+verify_in_constant_time(<<X/binary>>, <<Y/binary>>) ->
+    verify_in_constant_time(binary_to_list(X), binary_to_list(Y));
+verify_in_constant_time(X, Y) when is_list(X) and is_list(Y) ->
+    case length(X) == length(Y) of
+        true ->
+            verify_in_constant_time(X, Y, 0);
+        false ->
+            false
+    end;
+verify_in_constant_time(_X, _Y) -> false.
+
 signature_base_string(HttpMethod, URL, Params) ->
   uri_join([HttpMethod, uri_normalize(URL), params_encode(Params)]).
 


[22/50] git commit: Fold oauth_unix module into oauth module.

Posted by da...@apache.org.
Fold oauth_unix module into oauth module.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/546d0ee7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/546d0ee7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/546d0ee7

Branch: refs/heads/import
Commit: 546d0ee7e45dca21c9ae74f82fbb25e191d8dae7
Parents: cfe8271
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 14:48:37 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 14:48:37 2010 +0000

----------------------------------------------------------------------
 ebin/oauth.app     |  1 -
 src/oauth.erl      | 14 +++++++++++++-
 src/oauth_unix.erl | 15 ---------------
 3 files changed, 13 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/546d0ee7/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index f368f9c..4a2563b 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -8,7 +8,6 @@
     oauth_http,
     oauth_plaintext,
     oauth_rsa_sha1,
-    oauth_unix,
     oauth_uri
   ]},
   {registered, []},

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/546d0ee7/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 77eed92..c6467d9 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -71,7 +71,7 @@ token_param(Token, Params) ->
 
 params(Consumer, Params) ->
   Nonce = base64:encode_to_string(crypto:rand_bytes(32)), % cf. ruby-oauth
-  params(Consumer, oauth_unix:timestamp(), Nonce, Params).
+  params(Consumer, unix_timestamp(), Nonce, Params).
 
 params(Consumer, Timestamp, Nonce, Params) ->
   [ {"oauth_version", "1.0"}
@@ -82,6 +82,18 @@ params(Consumer, Timestamp, Nonce, Params) ->
   | Params
   ].
 
+unix_timestamp() ->
+  unix_timestamp(calendar:universal_time()).
+
+unix_timestamp(DateTime) ->
+  unix_seconds(DateTime) - unix_epoch().
+
+unix_epoch() ->
+  unix_seconds({{1970,1,1},{00,00,00}}).
+
+unix_seconds(DateTime) ->
+  calendar:datetime_to_gregorian_seconds(DateTime).
+
 signature_method_string(Consumer) ->
   case signature_method(Consumer) of
     plaintext ->

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/546d0ee7/src/oauth_unix.erl
----------------------------------------------------------------------
diff --git a/src/oauth_unix.erl b/src/oauth_unix.erl
deleted file mode 100644
index 27f6de9..0000000
--- a/src/oauth_unix.erl
+++ /dev/null
@@ -1,15 +0,0 @@
--module(oauth_unix).
-
--export([timestamp/0]).
-
-timestamp() ->
-  timestamp(calendar:universal_time()).
-
-timestamp(DateTime) ->
-  seconds(DateTime) - epoch().
-
-epoch() ->
-  seconds({{1970,1,1},{00,00,00}}).
-
-seconds(DateTime) ->
-  calendar:datetime_to_gregorian_seconds(DateTime).


[31/50] git commit: Bump version to 1.1.1.

Posted by da...@apache.org.
Bump version to 1.1.1.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/18cee778
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/18cee778
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/18cee778

Branch: refs/heads/import
Commit: 18cee77847033eaed2aed16dd210103a36105dd8
Parents: b9dcd4f
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sat Jan 29 17:13:20 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sat Jan 29 17:13:20 2011 +0000

----------------------------------------------------------------------
 ebin/oauth.app | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/18cee778/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index 0bdb7fa..dd05b42 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,6 +1,6 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.1.0"},
+  {vsn, "1.1.1"},
   {modules, [
     oauth,
     oauth_client,


[13/50] git commit: Move compile options to Emakefile; simplify Makefile.

Posted by da...@apache.org.
Move compile options to Emakefile; simplify Makefile.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/be1aa964
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/be1aa964
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/be1aa964

Branch: refs/heads/import
Commit: be1aa9646dcd1d8746dde849854cec3fa8792094
Parents: e632698
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Sep 26 15:04:01 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Sep 26 15:04:01 2009 +0100

----------------------------------------------------------------------
 Emakefile |  2 +-
 Makefile  | 18 ++++--------------
 2 files changed, 5 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/be1aa964/Emakefile
----------------------------------------------------------------------
diff --git a/Emakefile b/Emakefile
index a125769..a961122 100644
--- a/Emakefile
+++ b/Emakefile
@@ -1 +1 @@
-{"src/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
\ No newline at end of file
+{"src/*", [debug_info, warn_unused_vars, warn_unused_import, {outdir, "ebin"}]}.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/be1aa964/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 46ee404..f6aedc9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,7 @@
-SOURCE_FILES := $(wildcard src/*.erl)
-
-
-all: ebin
-
-ebin: ebin/oauth.app $(SOURCE_FILES:src/%.erl=ebin/%.beam)
-
-ebin/oauth.app: src/oauth.app
-	@test -d ebin || mkdir ebin
-	cp src/oauth.app ebin/oauth.app
-
-ebin/%.beam: src/%.erl
+all:
 	@test -d ebin || mkdir ebin
-	erlc -W +debug_info -o ebin $<
+	@cp src/oauth.app ebin/
+	@erl -make
 
 clean:
-	@rm -rf ebin erl_crash.dump
+	@rm -rf ebin/* erl_crash.dump


[24/50] git commit: Add THANKS.

Posted by da...@apache.org.
Add THANKS.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/09fa180b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/09fa180b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/09fa180b

Branch: refs/heads/import
Commit: 09fa180b1c2bed6a798a103d28a6d381c27e58ce
Parents: 546d0ee
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 15:58:55 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 15:58:55 2010 +0000

----------------------------------------------------------------------
 README.txt |  2 --
 THANKS.txt | 13 +++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/09fa180b/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index 0145e45..850fe17 100644
--- a/README.txt
+++ b/README.txt
@@ -24,8 +24,6 @@ Quick start (client usage):
   ...
 
 
-Thanks to Jason Davies, Paul Bonser, and Roberto Aloi for their patches.
-
 The percent encoding/decoding implementations are based on those found in
 the ibrowse library, written by Chandrashekhar Mullaparthi.
 

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/09fa180b/THANKS.txt
----------------------------------------------------------------------
diff --git a/THANKS.txt b/THANKS.txt
new file mode 100644
index 0000000..33df40e
--- /dev/null
+++ b/THANKS.txt
@@ -0,0 +1,13 @@
+Thanks to the following for patches and suggestions:
+
+* Fernando Benavides <github.com/elbrujohalcon>
+
+* Jan Lehnardt <github.com/janl>
+
+* Jason Davies <github.com/jasondavies>
+
+* Jebu Ittiachen <github.com/jebu>
+
+* Paul Bonser <github.com/pib>
+
+* Roberto Aloi <github.com/prof3ta>


[10/50] git commit: Add gen_server based oauth_client module.

Posted by da...@apache.org.
Add gen_server based oauth_client module.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/1bcd44f9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/1bcd44f9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/1bcd44f9

Branch: refs/heads/import
Commit: 1bcd44f95277bddcaaeb8442b61ae77a4937ceb4
Parents: 2c625a0
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Sep 26 14:03:49 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Sep 26 14:03:49 2009 +0100

----------------------------------------------------------------------
 src/oauth_client.erl | 134 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/1bcd44f9/src/oauth_client.erl
----------------------------------------------------------------------
diff --git a/src/oauth_client.erl b/src/oauth_client.erl
new file mode 100644
index 0000000..b6fd831
--- /dev/null
+++ b/src/oauth_client.erl
@@ -0,0 +1,134 @@
+-module(oauth_client).
+
+-behaviour(gen_server).
+
+-export([access_token_params/1, deauthorize/1, get/2, get/3, get_access_token/2,
+  get_access_token/3, get_request_token/2, get_request_token/3, start/1, start/2,
+  start_link/1, start_link/2, stop/1]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
+
+%%============================================================================
+%% API functions
+%%============================================================================
+
+start(Consumer) ->
+  gen_server:start(?MODULE, Consumer, []).
+
+start(ServerName, Consumer) ->
+  gen_server:start(ServerName, ?MODULE, Consumer, []).
+
+start_link(Consumer) ->
+  gen_server:start_link(?MODULE, Consumer, []).
+
+start_link(ServerName, Consumer) ->
+  gen_server:start_link(ServerName, ?MODULE, Consumer, []).
+
+get_request_token(Client, URL) ->
+  get_request_token(Client, URL, []).
+
+get_request_token(Client, URL, Params) ->
+  gen_server:call(Client, {get_request_token, URL, Params}).
+
+get_access_token(Client, URL) ->
+  get_access_token(Client, URL, []).
+
+get_access_token(Client, URL, Params) ->
+  gen_server:call(Client, {get_access_token, URL, Params}).
+
+get(Client, URL) ->
+  get(Client, URL, []).
+
+get(Client, URL, Params) ->
+  gen_server:call(Client, {get, URL, Params}).
+
+access_token_params(Client) ->
+  gen_server:call(Client, {access_token_params}).
+
+deauthorize(Client) ->
+  gen_server:cast(Client, deauthorize).
+
+stop(Client) ->
+  gen_server:cast(Client, stop).
+
+%%============================================================================
+%% Helper functions
+%%============================================================================
+
+oauth_get(URL, Params, Consumer, Token, TokenSecret) ->
+  Signed = oauth:signed_params("GET", URL, Params, Consumer, Token, TokenSecret),
+  {AuthorizationParams, QueryParams} = lists:partition(fun({K, _}) -> lists:prefix("oauth_", K) end, Signed),
+  Request = {oauth:uri(URL, QueryParams), [oauth:header(AuthorizationParams)]},
+  http:request(get, Request, [{autoredirect, false}], []).
+
+%%============================================================================
+%% gen_server callbacks
+%%============================================================================
+
+init(Consumer) ->
+  {ok, {Consumer}}.
+
+handle_call({get_request_token, URL, Params}, _From, State={Consumer}) ->
+  case oauth_get(URL, Params, Consumer, "", "") of
+    {ok, Response} ->
+      case oauth_http:response_code(Response) of
+        200 ->
+          RParams = oauth_http:response_params(Response),
+          {reply, {ok, oauth:token(RParams)}, {Consumer, RParams}};
+        _ ->
+          {reply, Response, State}
+      end;
+    Error ->
+      {reply, Error, State}
+  end;
+handle_call({get_access_token, URL, Params}, _From, State={Consumer, RParams}) ->
+  case oauth_get(URL, Params, Consumer, oauth:token(RParams), oauth:token_secret(RParams)) of
+    {ok, Response} ->
+      case oauth_http:response_code(Response) of
+        200 ->
+          AParams = oauth_http:response_params(Response),
+          {reply, ok, {Consumer, RParams, AParams}};
+        _ ->
+          {reply, Response, State}
+      end;
+    Error ->
+      {reply, Error, State}
+  end;
+handle_call({get, URL, Params}, _From, State={Consumer, _RParams, AParams}) ->
+  case oauth_get(URL, Params, Consumer, oauth:token(AParams), oauth:token_secret(AParams)) of
+    {ok, Response={{_, Status, _}, Headers, Body}} ->
+      case Status of
+        200 ->
+          ContentType = proplists:get_value("content-type", Headers, ""),
+          MediaType = hd(string:tokens(ContentType, ";")),
+          case lists:suffix("/xml", MediaType) orelse lists:suffix("+xml", MediaType) of
+            true ->
+              {XML, []} = xmerl_scan:string(Body),
+              {reply, {ok, Headers, XML}, State};
+            false ->
+              {reply, {ok, Headers, Body}, State}
+          end;
+        _ ->
+          {reply, Response, State}
+      end;
+    Error ->
+      {reply, Error, State}
+  end;
+handle_call({access_token_params}, _From, State={_Consumer, _RParams, AParams}) ->
+  {reply, AParams, State}.
+
+handle_cast(deauthorize, {Consumer, _RParams}) ->
+  {noreply, {Consumer}};
+handle_cast(deauthorize, {Consumer, _RParams, _AParams}) ->
+  {noreply, {Consumer}};
+handle_cast(stop, State) ->
+  {stop, normal, State}.
+
+handle_info(_Msg, State) ->
+  {noreply, State}.
+
+code_change(_OldVsn, State, _Extra) ->
+  {ok, State}.
+
+terminate(normal, _State) ->
+  ok.


[26/50] git commit: Merge branch 'r14b'

Posted by da...@apache.org.
Merge branch 'r14b'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/ee81922d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/ee81922d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/ee81922d

Branch: refs/heads/import
Commit: ee81922dcaa9f47589dd92bbf2e15d515eb51c99
Parents: d9bfb30 2559e8b
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Jan 24 22:59:42 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Jan 24 22:59:42 2011 +0000

----------------------------------------------------------------------
 src/oauth_rsa_sha1.erl | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------



[27/50] git commit: List public_key application in .app file.

Posted by da...@apache.org.
List public_key application in .app file.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/5ee7aa64
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/5ee7aa64
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/5ee7aa64

Branch: refs/heads/import
Commit: 5ee7aa640e6784c7ac35c08efa7dceeda2fe36af
Parents: ee81922
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Jan 24 23:07:25 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Jan 24 23:07:25 2011 +0000

----------------------------------------------------------------------
 ebin/oauth.app | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/5ee7aa64/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index 445762b..c0cc08b 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -15,6 +15,7 @@
     kernel,
     stdlib,
     crypto,
+    public_key,
     inets
   ]}
 ]}.


[36/50] git commit: Update app file and bump version to 1.2.0

Posted by da...@apache.org.
Update app file and bump version to 1.2.0


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/29cb4781
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/29cb4781
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/29cb4781

Branch: refs/heads/import
Commit: 29cb4781fd095f4b194d0c400ee2b89e90824020
Parents: e32d490
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Thu Jun 23 16:17:02 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Thu Jun 23 16:17:02 2011 +0100

----------------------------------------------------------------------
 ebin/oauth.app | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/29cb4781/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index dd05b42..d379b8d 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,21 +1,7 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.1.1"},
-  {modules, [
-    oauth,
-    oauth_client,
-    oauth_hmac_sha1,
-    oauth_http,
-    oauth_plaintext,
-    oauth_rsa_sha1,
-    oauth_uri
-  ]},
+  {vsn, "1.2.0"},
+  {modules, [oauth]},
   {registered, []},
-  {applications, [
-    kernel,
-    stdlib,
-    crypto,
-    public_key,
-    inets
-  ]}
+  {applications, [kernel, stdlib, crypto, public_key, inets]}
 ]}.


[20/50] git commit: Allow httpc options to be passed through.

Posted by da...@apache.org.
Allow httpc options to be passed through.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/6b012def
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/6b012def
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/6b012def

Branch: refs/heads/import
Commit: 6b012def4e49d867e9255de26ef7273a3db27bd5
Parents: 24a39a2
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 14:41:20 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 14:41:20 2010 +0000

----------------------------------------------------------------------
 src/oauth.erl      | 12 ++++++++++--
 src/oauth_http.erl | 16 +++++++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/6b012def/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 866655c..70770ba 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -2,8 +2,10 @@
 
 -export(
   [ get/5
+  , get/6
   , header/1
   , post/5
+  , post/6
   , signature/5
   , signature_base_string/3
   , signed_params/6
@@ -15,12 +17,18 @@
 
 
 get(URL, ExtraParams, Consumer, Token, TokenSecret) ->
+  get(URL, ExtraParams, Consumer, Token, TokenSecret, []).
+
+get(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
   SignedParams = signed_params("GET", URL, ExtraParams, Consumer, Token, TokenSecret),
-  oauth_http:get(uri(URL, SignedParams)).
+  oauth_http:get(uri(URL, SignedParams), HttpcOptions).
 
 post(URL, ExtraParams, Consumer, Token, TokenSecret) ->
+  post(URL, ExtraParams, Consumer, Token, TokenSecret, []).
+
+post(URL, ExtraParams, Consumer, Token, TokenSecret, HttpcOptions) ->
   SignedParams = signed_params("POST", URL, ExtraParams, Consumer, Token, TokenSecret),
-  oauth_http:post(URL, oauth_uri:params_to_string(SignedParams)).
+  oauth_http:post(URL, oauth_uri:params_to_string(SignedParams), HttpcOptions).
 
 uri(Base, []) ->
   Base;

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/6b012def/src/oauth_http.erl
----------------------------------------------------------------------
diff --git a/src/oauth_http.erl b/src/oauth_http.erl
index 92c806c..32261d3 100644
--- a/src/oauth_http.erl
+++ b/src/oauth_http.erl
@@ -1,16 +1,22 @@
 -module(oauth_http).
 
--export([get/1, post/2, response_params/1, response_body/1, response_code/1]).
+-export([get/1, get/2, post/2, post/3, response_params/1, response_body/1, response_code/1]).
 
 
 get(URL) ->
-  request(get, {URL, []}).
+  get(URL, []).
+
+get(URL, Options) ->
+  request(get, {URL, []}, Options).
 
 post(URL, Data) ->
-  request(post, {URL, [], "application/x-www-form-urlencoded", Data}).
+  post(URL, Data, []).
+
+post(URL, Data, Options) ->
+  request(post, {URL, [], "application/x-www-form-urlencoded", Data}, Options).
 
-request(Method, Request) ->
-  httpc:request(Method, Request, [{autoredirect, false}], []).
+request(Method, Request, Options) ->
+  httpc:request(Method, Request, [{autoredirect, false}], Options).
 
 response_params(Response) ->
   oauth_uri:params_from_string(response_body(Response)).


[46/50] git commit: Add a changelog

Posted by da...@apache.org.
Add a changelog


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/f332b773
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/f332b773
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/f332b773

Branch: refs/heads/import
Commit: f332b77371d334d0faa13e106d0c36f948b325b6
Parents: 994f3d4
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sun Dec 18 11:34:10 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sun Dec 18 11:34:10 2011 +0000

----------------------------------------------------------------------
 CHANGELOG.txt | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/f332b773/CHANGELOG.txt
----------------------------------------------------------------------
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
new file mode 100644
index 0000000..1944625
--- /dev/null
+++ b/CHANGELOG.txt
@@ -0,0 +1,35 @@
+v1.2.2 (2011-11-18) 994f3d4
+
+  * Add support for new tagged tuple returned by http_uri:parse/1 (R15B)
+
+
+v1.2.1 (2011-10-17) 7969309
+
+  * Updated to use a constant time algorithm to compare signature strings
+
+
+v1.2.0 (2011-06-23) 29cb478
+
+  * Added oauth:get/3 and oauth:post/3 functions
+
+  * Collapsed into just a single module
+
+
+v1.1.1 (2011-01-29) 18cee77
+
+  * Updated to use the correct request parameter normalization algorithm
+
+
+v1.1.0 (2011-01-24) 3bea612
+
+  * Updated to use the new public key API introduced in R14B (public_key-0.8)
+
+
+v1.0.2 (2010-11-26) d9bfb30
+
+  * Added oauth:get/6 and oauth:post/6 with additional HttpcOptions parameter
+
+
+v1.0.1 (2010-11-26) 2c9269b
+
+  * First version numbered version!


[18/50] git commit: Call this 1.0.1; update the .app file.

Posted by da...@apache.org.
Call this 1.0.1; update the .app file.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2c9269be
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2c9269be
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2c9269be

Branch: refs/heads/import
Commit: 2c9269be68fc6c7b7f14f38a84b00b63fb89aa8c
Parents: cec39b1
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 14:17:08 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 14:17:08 2010 +0000

----------------------------------------------------------------------
 src/oauth.app | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2c9269be/src/oauth.app
----------------------------------------------------------------------
diff --git a/src/oauth.app b/src/oauth.app
index 6357b9b..f368f9c 100644
--- a/src/oauth.app
+++ b/src/oauth.app
@@ -1,8 +1,9 @@
 {application, oauth, [
-  {description, "Erlang OAuth implementation"},
-  {vsn, "dev"},
+  {description, "An Erlang OAuth 1.0 implementation"},
+  {vsn, "1.0.1"},
   {modules, [
     oauth,
+    oauth_client,
     oauth_hmac_sha1,
     oauth_http,
     oauth_plaintext,


[23/50] git commit: Use public_key-0.8 API (R14B).

Posted by da...@apache.org.
Use public_key-0.8 API (R14B).


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/2559e8bb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/2559e8bb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/2559e8bb

Branch: refs/heads/import
Commit: 2559e8bbf4be816c545a5dd467225a20e0c9dd06
Parents: 546d0ee
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Fri Nov 26 15:31:52 2010 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Fri Nov 26 15:31:52 2010 +0000

----------------------------------------------------------------------
 src/oauth_rsa_sha1.erl | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/2559e8bb/src/oauth_rsa_sha1.erl
----------------------------------------------------------------------
diff --git a/src/oauth_rsa_sha1.erl b/src/oauth_rsa_sha1.erl
index a7b570c..99bd926 100644
--- a/src/oauth_rsa_sha1.erl
+++ b/src/oauth_rsa_sha1.erl
@@ -5,25 +5,26 @@
 -include_lib("public_key/include/public_key.hrl").
 
 signature(BaseString, PrivateKeyPath) ->
-  {ok, [Info]} = public_key:pem_to_der(PrivateKeyPath),
-  {ok, PrivateKey} = public_key:decode_private_key(Info),
-  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), PrivateKey)).
+  {ok, Contents} = file:read_file(PrivateKeyPath),
+  [Info] = public_key:pem_decode(Contents),
+  PrivateKey = public_key:pem_entry_decode(Info),
+  base64:encode_to_string(public_key:sign(list_to_binary(BaseString), sha, PrivateKey)).
 
-verify(Signature, BaseString, PublicKey) ->
-  public_key:verify_signature(to_binary(BaseString), sha, base64:decode(Signature), public_key(PublicKey)).
+verify(Signature, BaseString, Cert) ->
+  public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), pkey(Cert)).
 
 to_binary(Term) when is_list(Term) ->
   list_to_binary(Term);
 to_binary(Term) when is_binary(Term) ->
   Term.
 
-public_key(Path) when is_list(Path) ->
-  {ok, [{cert, DerCert, not_encrypted}]} = public_key:pem_to_der(Path),
-  {ok, Cert} = public_key:pkix_decode_cert(DerCert, otp),
-  public_key(Cert);
-public_key(#'OTPCertificate'{tbsCertificate=Cert}) ->
-  public_key(Cert);
-public_key(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
-  public_key(Info);
-public_key(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
+pkey(Path) when is_list(Path) ->
+  {ok, Contents} = file:read_file(Path),
+  [{'Certificate', DerCert, not_encrypted}] = public_key:pem_decode(Contents),
+  pkey(public_key:pkix_decode_cert(DerCert, otp));
+pkey(#'OTPCertificate'{tbsCertificate=Cert}) ->
+  pkey(Cert);
+pkey(#'OTPTBSCertificate'{subjectPublicKeyInfo=Info}) ->
+  pkey(Info);
+pkey(#'OTPSubjectPublicKeyInfo'{subjectPublicKey=Key}) ->
   Key.


[42/50] git commit: http_uri:parse(URI) now returns {ok, {Scheme, ...}} in R15B

Posted by da...@apache.org.
http_uri:parse(URI) now returns {ok,{Scheme,...}} in R15B


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/89ebe2cf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/89ebe2cf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/89ebe2cf

Branch: refs/heads/import
Commit: 89ebe2cf9afc08ba5f32deb7d8a333f0a28a50e6
Parents: 7969309
Author: naoya_t <na...@gmail.com>
Authored: Sun Dec 18 20:07:21 2011 +0900
Committer: naoya_t <na...@gmail.com>
Committed: Sun Dec 18 20:07:21 2011 +0900

----------------------------------------------------------------------
 src/oauth.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/89ebe2cf/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 5fc563e..d7257ad 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -228,6 +228,8 @@ header_param_decode(Param) ->
 
 uri_normalize(URI) ->
   case http_uri:parse(URI) of
+    {ok, {Scheme, UserInfo, Host, Port, Path, _Query}} -> % R15B
+      uri_normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
     {Scheme, UserInfo, Host, Port, Path, _Query} ->
       uri_normalize(Scheme, UserInfo, string:to_lower(Host), Port, [Path]);
     Else ->


[29/50] git commit: Update copyright date.

Posted by da...@apache.org.
Update copyright date.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/dcbf2273
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/dcbf2273
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/dcbf2273

Branch: refs/heads/import
Commit: dcbf2273d916c86ecdac8bcbe2d8b084cfca201e
Parents: 3bea612
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Sat Jan 29 17:06:13 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Sat Jan 29 17:06:13 2011 +0000

----------------------------------------------------------------------
 License.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/dcbf2273/License.txt
----------------------------------------------------------------------
diff --git a/License.txt b/License.txt
index 08b7172..bb37db3 100644
--- a/License.txt
+++ b/License.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2008-2009 Tim Fletcher <http://tfletcher.com/>
+Copyright (c) 2008-2011 Tim Fletcher <http://tfletcher.com/>
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation


[12/50] git commit: Fix oauth_client for missing content type response headers.

Posted by da...@apache.org.
Fix oauth_client for missing content type response headers.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/e6326987
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/e6326987
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/e6326987

Branch: refs/heads/import
Commit: e63269877da54513436eb59cec0381e8843ba8da
Parents: 9d00161
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Sat Sep 26 15:01:16 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Sat Sep 26 15:01:16 2009 +0100

----------------------------------------------------------------------
 src/oauth_client.erl | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/e6326987/src/oauth_client.erl
----------------------------------------------------------------------
diff --git a/src/oauth_client.erl b/src/oauth_client.erl
index 4b50901..73a7869 100644
--- a/src/oauth_client.erl
+++ b/src/oauth_client.erl
@@ -110,14 +110,18 @@ handle_call({get, URL, Params, ParamsMethod}, _From, State={Consumer, _RParams,
     {ok, Response={{_, Status, _}, Headers, Body}} ->
       case Status of
         200 ->
-          ContentType = proplists:get_value("content-type", Headers, ""),
-          MediaType = hd(string:tokens(ContentType, ";")),
-          case lists:suffix("/xml", MediaType) orelse lists:suffix("+xml", MediaType) of
-            true ->
-              {XML, []} = xmerl_scan:string(Body),
-              {reply, {ok, Headers, XML}, State};
-            false ->
-              {reply, {ok, Headers, Body}, State}
+          case proplists:get_value("content-type", Headers) of
+            undefined ->
+              {reply, {ok, Headers, Body}, State};
+            ContentType ->
+              MediaType = hd(string:tokens(ContentType, ";")),
+              case lists:suffix("/xml", MediaType) orelse lists:suffix("+xml", MediaType) of
+                true ->
+                  {XML, []} = xmerl_scan:string(Body),
+                  {reply, {ok, Headers, XML}, State};
+                false ->
+                  {reply, {ok, Headers, Body}, State}
+              end
           end;
         _ ->
           {reply, Response, State}


[15/50] git commit: Mention that percent encoding/decoding functions are based on those in ibrowse.

Posted by da...@apache.org.
Mention that percent encoding/decoding functions are based on those in ibrowse.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/e8aecf05
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/e8aecf05
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/e8aecf05

Branch: refs/heads/import
Commit: e8aecf057b0a424afcf2ee01449cddbf2ec51af9
Parents: ca45418
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Tue Oct 6 18:35:23 2009 +0100
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Tue Oct 6 18:35:23 2009 +0100

----------------------------------------------------------------------
 README.txt | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/e8aecf05/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index d2ff5f9..0145e45 100644
--- a/README.txt
+++ b/README.txt
@@ -26,6 +26,9 @@ Quick start (client usage):
 
 Thanks to Jason Davies, Paul Bonser, and Roberto Aloi for their patches.
 
+The percent encoding/decoding implementations are based on those found in
+the ibrowse library, written by Chandrashekhar Mullaparthi.
+
 Example client/server code is at http://github.com/tim/erlang-oauth-examples.
 
 Unit tests are at http://github.com/tim/erlang-oauth-tests.


[02/50] git commit: Update README.

Posted by da...@apache.org.
Update README.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/090bebe9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/090bebe9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/090bebe9

Branch: refs/heads/import
Commit: 090bebe9f6e38c75065072e8617fd1ca5471e679
Parents: d8be236
Author: Tim Fletcher <ti...@tfletcher.com>
Authored: Wed Feb 25 20:18:18 2009 +0000
Committer: Tim Fletcher <ti...@tfletcher.com>
Committed: Wed Feb 25 20:18:18 2009 +0000

----------------------------------------------------------------------
 README.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/090bebe9/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index 6c301cb..f8270c4 100644
--- a/README.txt
+++ b/README.txt
@@ -5,9 +5,7 @@ Quick start (client usage):
   $ make
   ...
   $ erl -pa ebin -s crypto -s inets
-  Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [kernel-poll:false]
-
-  Eshell V5.6.5  (abort with ^G)
+  ...
   1> Consumer = {"key", "secret", hmac_sha1}.
   ...
   2> RequestTokenURL = "http://term.ie/oauth/example/request_token.php".
@@ -26,6 +24,8 @@ Quick start (client usage):
   ...
 
 
-Erlang R12B-5 is required for generating RSA-SHA1 signatures.
+Example client/server code: http://github.com/tim/erlang-oauth-examples.
+
+Unit tests: http://github.com/tim/erlang-oauth-tests.
 
-RSA-SHA1 signature verification is not yet implemented.
+Erlang R12B-5 required for RSA-SHA1.


[39/50] git commit: Keep consistent indentation

Posted by da...@apache.org.
Keep consistent indentation


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/3ae1cc7e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/3ae1cc7e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/3ae1cc7e

Branch: refs/heads/import
Commit: 3ae1cc7edf0f3065a7c5f365d95f10bbd1459b45
Parents: ed213dd
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Oct 17 11:57:33 2011 +0100
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Oct 17 11:57:33 2011 +0100

----------------------------------------------------------------------
 src/oauth.erl | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/3ae1cc7e/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index 18c428d..61e4a0a 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -145,20 +145,20 @@ rsa_sha1_verify(Signature, BaseString, Consumer) ->
   Key = read_cert_key(consumer_secret(Consumer)),
   public_key:verify(to_binary(BaseString), sha, base64:decode(Signature), Key).
 
-verify_in_constant_time([X|RestX], [Y|RestY], Result) ->
-    verify_in_constant_time(RestX, RestY, (X bxor Y) bor Result);
-verify_in_constant_time([], [], Result) ->
-    Result == 0.
-
 verify_in_constant_time(<<X/binary>>, <<Y/binary>>) ->
-    verify_in_constant_time(binary_to_list(X), binary_to_list(Y));
+  verify_in_constant_time(binary_to_list(X), binary_to_list(Y));
 verify_in_constant_time(X, Y) when is_list(X) and is_list(Y) ->
-    case length(X) == length(Y) of
-        true ->
-            verify_in_constant_time(X, Y, 0);
-        false ->
-            false
-    end.
+  case length(X) == length(Y) of
+    true ->
+      verify_in_constant_time(X, Y, 0);
+    false ->
+      false
+  end.
+
+verify_in_constant_time([X | RestX], [Y | RestY], Result) ->
+  verify_in_constant_time(RestX, RestY, (X bxor Y) bor Result);
+verify_in_constant_time([], [], Result) ->
+  Result == 0.
 
 signature_base_string(HttpMethod, URL, Params) ->
   uri_join([HttpMethod, uri_normalize(URL), params_encode(Params)]).


[28/50] git commit: Bump version to 1.1.0; at least R14B now required for RSA-SHA1.

Posted by da...@apache.org.
Bump version to 1.1.0; at least R14B now required for RSA-SHA1.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/3bea6126
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/3bea6126
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/3bea6126

Branch: refs/heads/import
Commit: 3bea61266290ee5467f87ab12c5f422401a3f1b7
Parents: 5ee7aa6
Author: Tim Fletcher <ma...@tfletcher.com>
Authored: Mon Jan 24 23:11:03 2011 +0000
Committer: Tim Fletcher <ma...@tfletcher.com>
Committed: Mon Jan 24 23:11:03 2011 +0000

----------------------------------------------------------------------
 README.txt     | 2 +-
 ebin/oauth.app | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/3bea6126/README.txt
----------------------------------------------------------------------
diff --git a/README.txt b/README.txt
index 850fe17..41b923a 100644
--- a/README.txt
+++ b/README.txt
@@ -31,4 +31,4 @@ Example client/server code is at http://github.com/tim/erlang-oauth-examples.
 
 Unit tests are at http://github.com/tim/erlang-oauth-tests.
 
-Erlang R12B-5 or greater is required for RSA-SHA1.
+Erlang/OTP R14B or greater is required for RSA-SHA1.

http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/3bea6126/ebin/oauth.app
----------------------------------------------------------------------
diff --git a/ebin/oauth.app b/ebin/oauth.app
index c0cc08b..0bdb7fa 100644
--- a/ebin/oauth.app
+++ b/ebin/oauth.app
@@ -1,6 +1,6 @@
 {application, oauth, [
   {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "1.0.2"},
+  {vsn, "1.1.0"},
   {modules, [
     oauth,
     oauth_client,


[47/50] git commit: export signature/5

Posted by da...@apache.org.
export signature/5


Project: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/commit/10930511
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/tree/10930511
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-oauth/diff/10930511

Branch: refs/heads/import
Commit: 109305111efd0f181c10819779ea554bb8096063
Parents: f332b77
Author: Benoit Chesneau <bc...@gmail.com>
Authored: Wed Apr 4 02:56:10 2012 +0200
Committer: Benoit Chesneau <bc...@gmail.com>
Committed: Wed Apr 4 02:56:10 2012 +0200

----------------------------------------------------------------------
 src/oauth.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-oauth/blob/10930511/src/oauth.erl
----------------------------------------------------------------------
diff --git a/src/oauth.erl b/src/oauth.erl
index d7257ad..64d5888 100644
--- a/src/oauth.erl
+++ b/src/oauth.erl
@@ -5,7 +5,7 @@
 
 -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_base_string/3, params_encode/1, signature/5]).
 
 -export([plaintext_verify/3, hmac_sha1_verify/6, hmac_sha1_verify/4,
   rsa_sha1_verify/5, rsa_sha1_verify/3]).