Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renamed methods:

 - check_signature to validate_signature
 - check_url_signature to validate_url_signature

Updated tests and docs accordingly

Added short chapter about the HMACSigner class to the readme.
  • Loading branch information...
commit af1974035fff6b8432de52af9593d6773608414c 1 parent 2fa14b9
@Xylakant Xylakant authored
View
10 README.md
@@ -266,13 +266,13 @@ The canonical representation is:
## HMACSigner usage
-The HMACSigner class can be used to validate and generate signatures for a given request.
+The HMACSigner class can be used to validate and generate signatures for a given request. Most methods accept a hash as an intermediate
+representation of the request but some methods accept and operate on full urls.
- h = HMACSigner.new('md5')
- h.generate_signature(canonical_representation, 'secret')
+ h = HMACSigner.new
+ h.sign_url('http://example.org/example.html', 'secret')
+ h.validate_url_signature('http://example.org/example.html?auth[signature]=foo', 'secret')
- h.validated_signature(canonical_representation, signature, 'secret')
-
## Licence
Copyright (c) 2011 Florian Gilcher <florian.gilcher@asquera.de>, Felix Gilcher <felix.gilcher@asquera.de>
View
760 doc/HMACSigner.html
@@ -246,7 +246,7 @@
<li class="public ">
<span class="summary_signature">
- <a href="#check_signature-instance_method" title="#check_signature (instance method)">- (Bool) <strong>check_signature</strong>(signature, params) </a>
+ <a href="#generate_signature-instance_method" title="#generate_signature (instance method)">- (String) <strong>generate_signature</strong>(params) </a>
@@ -260,8 +260,7 @@
<span class="summary_desc"><div class='inline'><p>
-compares the given signature with the signature created from a hash
-representation.
+Generate the signature from a hash representation.
</p>
</div></span>
@@ -271,12 +270,14 @@
<li class="public ">
<span class="summary_signature">
- <a href="#check_url_signature-instance_method" title="#check_url_signature (instance method)">- (Bool) <strong>check_url_signature</strong>(url, secret, opts = {}) </a>
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (HMACSigner) <strong>initialize</strong>(algorithm = &quot;sha1&quot;, default_opts = {}) </a>
</span>
+ <span class="note title constructor">constructor</span>
+
@@ -285,8 +286,7 @@
<span class="summary_desc"><div class='inline'><p>
-convienience method to check the signature of a url with query-based
-authentication.
+create a new HMAC instance.
</p>
</div></span>
@@ -296,7 +296,7 @@
<li class="public ">
<span class="summary_signature">
- <a href="#generate_signature-instance_method" title="#generate_signature (instance method)">- (String) <strong>generate_signature</strong>(params) </a>
+ <a href="#sign_request-instance_method" title="#sign_request (instance method)">- (Object) <strong>sign_request</strong>(url, secret, opts = {}) </a>
@@ -310,7 +310,7 @@
<span class="summary_desc"><div class='inline'><p>
-Generate the signature from a hash representation.
+sign the given request.
</p>
</div></span>
@@ -320,14 +320,12 @@
<li class="public ">
<span class="summary_signature">
- <a href="#initialize-instance_method" title="#initialize (instance method)">- (HMACSigner) <strong>initialize</strong>(algorithm = &quot;sha1&quot;, default_opts = {}) </a>
+ <a href="#sign_url-instance_method" title="#sign_url (instance method)">- (String) <strong>sign_url</strong>(url, secret, opts = {}) </a>
</span>
- <span class="note title constructor">constructor</span>
-
@@ -336,7 +334,7 @@
<span class="summary_desc"><div class='inline'><p>
-create a new HMAC instance.
+convienience method to sign a url for use with query-based authentication.
</p>
</div></span>
@@ -346,7 +344,7 @@
<li class="public ">
<span class="summary_signature">
- <a href="#sign_request-instance_method" title="#sign_request (instance method)">- (Object) <strong>sign_request</strong>(url, secret, opts = {}) </a>
+ <a href="#validate_signature-instance_method" title="#validate_signature (instance method)">- (Bool) <strong>validate_signature</strong>(signature, params) </a>
@@ -360,7 +358,8 @@
<span class="summary_desc"><div class='inline'><p>
-sign the given request.
+compares the given signature with the signature created from a hash
+representation.
</p>
</div></span>
@@ -370,7 +369,7 @@
<li class="public ">
<span class="summary_signature">
- <a href="#sign_url-instance_method" title="#sign_url (instance method)">- (String) <strong>sign_url</strong>(url, secret, opts = {}) </a>
+ <a href="#validate_url_signature-instance_method" title="#validate_url_signature (instance method)">- (Bool) <strong>validate_url_signature</strong>(url, secret, opts = {}) </a>
@@ -384,7 +383,8 @@
<span class="summary_desc"><div class='inline'><p>
-convienience method to sign a url for use with query-based authentication.
+convienience method to check the signature of a url with query-based
+authentication.
</p>
</div></span>
@@ -1114,17 +1114,16 @@
</div>
<div class="method_details ">
- <p class="signature " id="check_signature-instance_method">
+ <p class="signature " id="generate_signature-instance_method">
- - (<tt>Bool</tt>) <strong>check_signature</strong>(signature, params)
+ - (<tt>String</tt>) <strong>generate_signature</strong>(params)
</p><div class="docstring">
<div class="discussion">
<p>
-compares the given signature with the signature created from a hash
-representation
+Generate the signature from a hash representation
</p>
@@ -1136,23 +1135,6 @@
<li>
- <span class='name'>signature</span>
-
-
- <span class='type'>(<tt>String</tt>)</span>
-
-
-
- &mdash;
- <div class='inline'><p>
-the signature to compare with
-</p>
-</div>
-
- </li>
-
- <li>
-
<span class='name'>params</span>
@@ -1173,8 +1155,6 @@
-
-
<h3>Options Hash (<tt>params</tt>):</h3>
<ul class="option">
@@ -1401,13 +1381,13 @@
<li>
- <span class='type'>(<tt>Bool</tt>)</span>
+ <span class='type'>(<tt>String</tt>)</span>
&mdash;
<div class='inline'><p>
-true if the signature matches
+the signature
</p>
</div>
@@ -1421,15 +1401,17 @@
<pre class="lines">
-87
-88
-89</pre>
+61
+62
+63
+64</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 87</span>
+ <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 61</span>
-<span class='kw'>def</span> <span class='id check_signature'>check_signature</span><span class='lparen'>(</span><span class='id signature'>signature</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
- <span class='id signature'>signature</span> <span class='op'>==</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span>
+<span class='kw'>def</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span>
+ <span class='id secret'>secret</span> <span class='op'>=</span> <span class='id params'>params</span><span class='period'>.</span><span class='id delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:secret</span><span class='rparen'>)</span>
+ <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>HMAC</span><span class='period'>.</span><span class='id hexdigest'>hexdigest</span><span class='lparen'>(</span><span class='id algorithm'>algorithm</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id canonical_representation'>canonical_representation</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -1437,17 +1419,16 @@
</div>
<div class="method_details ">
- <p class="signature " id="check_url_signature-instance_method">
+ <p class="signature " id="sign_request-instance_method">
- - (<tt>Bool</tt>) <strong>check_url_signature</strong>(url, secret, opts = {})
+ - (<tt>Object</tt>) <strong>sign_request</strong>(url, secret, opts = {})
</p><div class="docstring">
<div class="discussion">
<p>
-convienience method to check the signature of a url with query-based
-authentication
+sign the given request
</p>
@@ -1468,7 +1449,7 @@
&mdash;
<div class='inline'><p>
-the url to test
+The url of the request
</p>
</div>
@@ -1485,7 +1466,7 @@
&mdash;
<div class='inline'><p>
-the secret used to sign the url
+The shared secret for the signature
</p>
</div>
@@ -1504,7 +1485,7 @@
&mdash;
<div class='inline'><p>
-Options controlling the singature generation
+Options for the signature generation
</p>
</div>
@@ -1523,337 +1504,354 @@
<ul class="option">
<li>
- <span class="name">:auth_param</span>
+ <span class="name">:nonce</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>'auth'</tt>
+ <tt>''</tt>
</span>
&mdash; <div class='inline'><p>
-The name of the authentication param to use for query based authentication
+The nonce to use in the signature
</p>
</div>
</tr>
- </ul>
-
-<h3>Returns:</h3>
-<ul class="return">
-
- <li>
-
-
- <span class='type'>(<tt>Bool</tt>)</span>
-
-
-
- &mdash;
- <div class='inline'><p>
-true if the signature is valid
-</p>
-</div>
-
- </li>
-
-</ul>
-
-</div><table class="source_code">
- <tr>
- <td>
- <pre class="lines">
-
-
-100
-101
-102
-103
-104
-105
-106
-107
-108
-109
-110
-111</pre>
- </td>
- <td>
- <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 100</span>
-
-<span class='kw'>def</span> <span class='id check_url_signature'>check_url_signature</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
- <span class='id opts'>opts</span> <span class='op'>=</span> <span class='id default_opts'>default_opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='rparen'>)</span>
- <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:query_based</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
-
- <span class='id uri'>uri</span> <span class='op'>=</span> <span class='const'>Addressable</span><span class='op'>::</span><span class='const'>URI</span><span class='period'>.</span><span class='id parse'>parse</span><span class='lparen'>(</span><span class='id url'>url</span><span class='rparen'>)</span>
- <span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span>
- <span class='id auth_params'>auth_params</span> <span class='op'>=</span> <span class='id query_values'>query_values</span><span class='period'>.</span><span class='id delete'>delete</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_param</span><span class='rbracket'>]</span><span class='rparen'>)</span>
-
- <span class='id date'>date</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>date</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
- <span class='id nonce'>nonce</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>nonce</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
- <span class='id check_signature'>check_signature</span><span class='lparen'>(</span><span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>signature</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:secret</span> <span class='op'>=&gt;</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='symbol'>:method</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>GET</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:path</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id path'>path</span><span class='comma'>,</span> <span class='symbol'>:date</span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span> <span class='symbol'>:nonce</span> <span class='op'>=&gt;</span> <span class='id nonce'>nonce</span><span class='comma'>,</span> <span class='symbol'>:query</span> <span class='op'>=&gt;</span> <span class='id query_values'>query_values</span><span class='comma'>,</span> <span class='symbol'>:headers</span> <span class='op'>=&gt;</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
-<span class='kw'>end</span></pre>
- </td>
- </tr>
-</table>
-</div>
-
- <div class="method_details ">
- <p class="signature " id="generate_signature-instance_method">
-
- - (<tt>String</tt>) <strong>generate_signature</strong>(params)
-
-
-
-</p><div class="docstring">
- <div class="discussion">
- <p>
-Generate the signature from a hash representation
-</p>
-
-
- </div>
-</div>
-<div class="tags">
- <h3>Parameters:</h3>
-<ul class="param">
-
- <li>
-
- <span class='name'>params</span>
-
-
- <span class='type'>(<tt>Hash</tt>)</span>
-
-
-
- &mdash;
- <div class='inline'><p>
-the parameters to create the representation with
-</p>
-</div>
-
- </li>
-
-</ul>
-
-
-
-
- <h3>Options Hash (<tt>params</tt>):</h3>
- <ul class="option">
-
<li>
- <span class="name">:secret</span>
- <span class="type">(<tt>String</tt>)</span>
+ <span class="name">:date</span>
+ <span class="type">(<tt>String</tt>, <tt>#strftime</tt>)</span>
<span class="default">
+ &mdash; default:
+ <tt>Time.now</tt>
+
</span>
&mdash; <div class='inline'><p>
-The secret to generate the signature with
+The date to use in the signature
</p>
</div>
</tr>
<li>
- <span class="name">:method</span>
- <span class="type">(<tt>String</tt>)</span>
+ <span class="name">:headers</span>
+ <span class="type">(<tt>Hash</tt>)</span>
<span class="default">
+ &mdash; default:
+ <tt>{}</tt>
+
</span>
&mdash; <div class='inline'><p>
-The HTTP Verb of the request
+A list of optional headers to include in the signature
</p>
</div>
</tr>
<li>
- <span class="name">:date</span>
+ <span class="name">:auth_scheme</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
+ &mdash; default:
+ <tt>'HMAC'</tt>
+
</span>
&mdash; <div class='inline'><p>
-The date of the request as it was formatted in the request
+The name of the authorization scheme used in the Authorization header and
+to construct various header-names
</p>
</div>
</tr>
<li>
- <span class="name">:nonce</span>
+ <span class="name">:auth_param</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>''</tt>
+ <tt>'auth'</tt>
</span>
&mdash; <div class='inline'><p>
-The nonce given in the request
+The name of the authentication param to use for query based authentication
</p>
</div>
</tr>
<li>
- <span class="name">:path</span>
+ <span class="name">:auth_header</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
+ &mdash; default:
+ <tt>'Authorization'</tt>
+
</span>
&mdash; <div class='inline'><p>
-The path portion of the request
+The name of the authorization header to use
</p>
</div>
</tr>
<li>
- <span class="name">:query</span>
- <span class="type">(<tt>Hash</tt>)</span>
+ <span class="name">:auth_header_format</span>
+ <span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>{}</tt>
+ <tt>'%{auth_scheme} %{signature}'</tt>
</span>
&mdash; <div class='inline'><p>
-The query parameters given in the request. Must not contain the auth param.
+The format of the authorization header. Will be interpolated with the given
+options and the signature.
</p>
</div>
</tr>
<li>
- <span class="name">:headers</span>
- <span class="type">(<tt>Hash</tt>)</span>
+ <span class="name">:nonce_header</span>
+ <span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>{}</tt>
+ <tt>'X-#{auth_scheme}-Nonce'</tt>
</span>
&mdash; <div class='inline'><p>
-All headers given in the request (optional and required)
+The header name for the request nonce
</p>
</div>
</tr>
<li>
- <span class="name">:auth_scheme</span>
+ <span class="name">:alternate_date_header</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>'HMAC'</tt>
+ <tt>'X-#{auth_scheme}-Date'</tt>
</span>
&mdash; <div class='inline'><p>
-The name of the authorization scheme used in the Authorization header and
-to construct various header-names
+The header name for the alternate date header
</p>
</div>
</tr>
<li>
- <span class="name">:auth_param</span>
- <span class="type">(<tt>String</tt>)</span>
- <span class="default">
+ <span class="name">:query_based</span>
+ <span class="type">(<tt>Bool</tt>)</span>
+ <span class="default">
&mdash; default:
- <tt>'auth'</tt>
+ <tt>false</tt>
</span>
&mdash; <div class='inline'><p>
-The name of the authentication param to use for query based authentication
+Whether to use query based authentication
</p>
</div>
</tr>
<li>
- <span class="name">:auth_header</span>
- <span class="type">(<tt>String</tt>)</span>
+ <span class="name">:use_alternate_date_header</span>
+ <span class="type">(<tt>Bool</tt>)</span>
<span class="default">
&mdash; default:
- <tt>'Authorization'</tt>
+ <tt>false</tt>
</span>
&mdash; <div class='inline'><p>
-The name of the authorization header to use
+Use the alternate date header instead of `Date`
</p>
</div>
</tr>
- <li>
- <span class="name">:auth_header_format</span>
- <span class="type">(<tt>String</tt>)</span>
- <span class="default">
-
- &mdash; default:
- <tt>'%{auth_scheme} %{signature}'</tt>
-
- </span>
- &mdash; <div class='inline'><p>
-The format of the authorization header. Will be interpolated with the given
-options and the signature.
+ </ul>
+
+
+</div><table class="source_code">
+ <tr>
+ <td>
+ <pre class="lines">
+
+
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213</pre>
+ </td>
+ <td>
+ <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 180</span>
+
+<span class='kw'>def</span> <span class='id sign_request'>sign_request</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
+ <span class='id opts'>opts</span> <span class='op'>=</span> <span class='id default_opts'>default_opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='rparen'>)</span>
+
+ <span class='id uri'>uri</span> <span class='op'>=</span> <span class='const'>Addressable</span><span class='op'>::</span><span class='const'>URI</span><span class='period'>.</span><span class='id parse'>parse</span><span class='lparen'>(</span><span class='id url'>url</span><span class='rparen'>)</span>
+ <span class='id headers'>headers</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:headers</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
+
+ <span class='id date'>date</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:date</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>Time</span><span class='period'>.</span><span class='id now'>now</span><span class='period'>.</span><span class='id gmtime'>gmtime</span>
+ <span class='id date'>date</span> <span class='op'>=</span> <span class='id date'>date</span><span class='period'>.</span><span class='id gmtime'>gmtime</span><span class='period'>.</span><span class='id strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%a, %e %b %Y %T GMT</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id date'>date</span><span class='period'>.</span><span class='id respond_to?'>respond_to?</span> <span class='symbol'>:strftime</span>
+
+ <span class='id signature'>signature</span> <span class='op'>=</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='symbol'>:secret</span> <span class='op'>=&gt;</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='symbol'>:method</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>GET</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:path</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id path'>path</span><span class='comma'>,</span> <span class='symbol'>:date</span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span> <span class='symbol'>:nonce</span> <span class='op'>=&gt;</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:query</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span><span class='comma'>,</span> <span class='symbol'>:headers</span> <span class='op'>=&gt;</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:headers</span><span class='rbracket'>]</span><span class='rparen'>)</span>
+
+ <span class='kw'>if</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:query_based</span><span class='rbracket'>]</span>
+ <span class='id auth_params'>auth_params</span> <span class='op'>=</span> <span class='lbrace'>{</span>
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>date</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span>
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>signature</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id signature'>signature</span>
+ <span class='rbrace'>}</span>
+ <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='kw'>unless</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id nil?'>nil?</span>
+
+ <span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span>
+ <span class='id query_values'>query_values</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_param</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span>
+ <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id query_values'>query_values</span>
+ <span class='kw'>else</span>
+ <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_header_format</span><span class='rbracket'>]</span> <span class='op'>%</span> <span class='id opts'>opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='symbol'>:signature</span> <span class='op'>=&gt;</span> <span class='id signature'>signature</span><span class='rbrace'>}</span><span class='rparen'>)</span>
+ <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='kw'>unless</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id nil?'>nil?</span>
+
+ <span class='kw'>if</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:use_alternate_date_header</span><span class='rbracket'>]</span>
+ <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:alternate_date_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id date'>date</span>
+ <span class='kw'>else</span>
+ <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Date</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id date'>date</span>
+ <span class='kw'>end</span>
+ <span class='kw'>end</span>
+
+ <span class='lbracket'>[</span><span class='id headers'>headers</span><span class='comma'>,</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id to_s'>to_s</span><span class='rbracket'>]</span>
+<span class='kw'>end</span></pre>
+ </td>
+ </tr>
+</table>
+</div>
+
+ <div class="method_details ">
+ <p class="signature " id="sign_url-instance_method">
+
+ - (<tt>String</tt>) <strong>sign_url</strong>(url, secret, opts = {})
+
+
+
+</p><div class="docstring">
+ <div class="discussion">
+ <p>
+convienience method to sign a url for use with query-based authentication
</p>
+
+
+ </div>
</div>
- </tr>
+<div class="tags">
+ <h3>Parameters:</h3>
+<ul class="param">
+
+ <li>
- <li>
- <span class="name">:nonce_header</span>
- <span class="type">(<tt>String</tt>)</span>
- <span class="default">
-
- &mdash; default:
- <tt>'X-#{auth_scheme}-Nonce'</tt>
-
- </span>
- &mdash; <div class='inline'><p>
-The header name for the request nonce
+ <span class='name'>url</span>
+
+
+ <span class='type'>(<tt>String</tt>)</span>
+
+
+
+ &mdash;
+ <div class='inline'><p>
+the url to sign
</p>
</div>
- </tr>
- <li>
- <span class="name">:alternate_date_header</span>
- <span class="type">(<tt>String</tt>)</span>
- <span class="default">
-
- &mdash; default:
- <tt>'X-#{auth_scheme}-Date'</tt>
-
- </span>
- &mdash; <div class='inline'><p>
-The header name for the alternate date header
+ </li>
+
+ <li>
+
+ <span class='name'>secret</span>
+
+
+ <span class='type'>(<tt>String</tt>)</span>
+
+
+
+ &mdash;
+ <div class='inline'><p>
+the secret used to sign the url
</p>
</div>
- </tr>
- <li>
- <span class="name">:query_based</span>
- <span class="type">(<tt>Bool</tt>)</span>
- <span class="default">
-
- &mdash; default:
- <tt>false</tt>
-
- </span>
- &mdash; <div class='inline'><p>
-Whether to use query based authentication
+ </li>
+
+ <li>
+
+ <span class='name'>opts</span>
+
+
+ <span class='type'>(<tt>Hash</tt>)</span>
+
+
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
+
+
+ &mdash;
+ <div class='inline'><p>
+Options controlling the singature generation
</p>
</div>
- </tr>
+
+ </li>
+
+</ul>
+
+
+
+
+
+
+
+
+ <h3>Options Hash (<tt>opts</tt>):</h3>
+ <ul class="option">
<li>
- <span class="name">:use_alternate_date_header</span>
- <span class="type">(<tt>Bool</tt>)</span>
+ <span class="name">:auth_param</span>
+ <span class="type">(<tt>String</tt>)</span>
<span class="default">
&mdash; default:
- <tt>false</tt>
+ <tt>'auth'</tt>
</span>
&mdash; <div class='inline'><p>
-Use the alternate date header instead of `Date`
+The name of the authentication param to use for query based authentication
</p>
</div>
</tr>
@@ -1872,7 +1870,7 @@
&mdash;
<div class='inline'><p>
-the signature
+The signed url
</p>
</div>
@@ -1886,17 +1884,23 @@
<pre class="lines">
-61
-62
-63
-64</pre>
+224
+225
+226
+227
+228
+229
+230</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 61</span>
+ <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 224</span>
-<span class='kw'>def</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span>
- <span class='id secret'>secret</span> <span class='op'>=</span> <span class='id params'>params</span><span class='period'>.</span><span class='id delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:secret</span><span class='rparen'>)</span>
- <span class='const'>OpenSSL</span><span class='op'>::</span><span class='const'>HMAC</span><span class='period'>.</span><span class='id hexdigest'>hexdigest</span><span class='lparen'>(</span><span class='id algorithm'>algorithm</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id canonical_representation'>canonical_representation</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span><span class='rparen'>)</span>
+<span class='kw'>def</span> <span class='id sign_url'>sign_url</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
+ <span class='id opts'>opts</span> <span class='op'>=</span> <span class='id default_opts'>default_opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='rparen'>)</span>
+ <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:query_based</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
+
+ <span class='id headers'>headers</span><span class='comma'>,</span> <span class='id url'>url</span> <span class='op'>=</span> <span class='op'>*</span><span class='id sign_request'>sign_request</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span><span class='rparen'>)</span>
+ <span class='id url'>url</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -1904,16 +1908,17 @@
</div>
<div class="method_details ">
- <p class="signature " id="sign_request-instance_method">
+ <p class="signature " id="validate_signature-instance_method">
- - (<tt>Object</tt>) <strong>sign_request</strong>(url, secret, opts = {})
+ - (<tt>Bool</tt>) <strong>validate_signature</strong>(signature, params)
</p><div class="docstring">
<div class="discussion">
<p>
-sign the given request
+compares the given signature with the signature created from a hash
+representation
</p>
@@ -1925,24 +1930,7 @@
<li>
- <span class='name'>url</span>
-
-
- <span class='type'>(<tt>String</tt>)</span>
-
-
-
- &mdash;
- <div class='inline'><p>
-The url of the request
-</p>
-</div>
-
- </li>
-
- <li>
-
- <span class='name'>secret</span>
+ <span class='name'>signature</span>
<span class='type'>(<tt>String</tt>)</span>
@@ -1951,7 +1939,7 @@
&mdash;
<div class='inline'><p>
-The shared secret for the signature
+the signature to compare with
</p>
</div>
@@ -1959,18 +1947,16 @@
<li>
- <span class='name'>opts</span>
+ <span class='name'>params</span>
<span class='type'>(<tt>Hash</tt>)</span>
- <em class="default">(defaults to: <tt>{}</tt>)</em>
-
&mdash;
<div class='inline'><p>
-Options for the signature generation
+the parameters to create the representation with
</p>
</div>
@@ -1983,12 +1969,46 @@
-
-
- <h3>Options Hash (<tt>opts</tt>):</h3>
+ <h3>Options Hash (<tt>params</tt>):</h3>
<ul class="option">
<li>
+ <span class="name">:secret</span>
+ <span class="type">(<tt>String</tt>)</span>
+ <span class="default">
+
+ </span>
+ &mdash; <div class='inline'><p>
+The secret to generate the signature with
+</p>
+</div>
+ </tr>
+
+ <li>
+ <span class="name">:method</span>
+ <span class="type">(<tt>String</tt>)</span>
+ <span class="default">
+
+ </span>
+ &mdash; <div class='inline'><p>
+The HTTP Verb of the request
+</p>
+</div>
+ </tr>
+
+ <li>
+ <span class="name">:date</span>
+ <span class="type">(<tt>String</tt>)</span>
+ <span class="default">
+
+ </span>
+ &mdash; <div class='inline'><p>
+The date of the request as it was formatted in the request
+</p>
+</div>
+ </tr>
+
+ <li>
<span class="name">:nonce</span>
<span class="type">(<tt>String</tt>)</span>
<span class="default">
@@ -1998,22 +2018,34 @@
</span>
&mdash; <div class='inline'><p>
-The nonce to use in the signature
+The nonce given in the request
</p>
</div>
</tr>
<li>
- <span class="name">:date</span>
- <span class="type">(<tt>String</tt>, <tt>#strftime</tt>)</span>
+ <span class="name">:path</span>
+ <span class="type">(<tt>String</tt>)</span>
+ <span class="default">
+
+ </span>
+ &mdash; <div class='inline'><p>
+The path portion of the request
+</p>
+</div>
+ </tr>
+
+ <li>
+ <span class="name">:query</span>
+ <span class="type">(<tt>Hash</tt>)</span>
<span class="default">
&mdash; default:
- <tt>Time.now</tt>
+ <tt>{}</tt>
</span>
&mdash; <div class='inline'><p>
-The date to use in the signature
+The query parameters given in the request. Must not contain the auth param.
</p>
</div>
</tr>
@@ -2028,7 +2060,7 @@
</span>
&mdash; <div class='inline'><p>
-A list of optional headers to include in the signature
+All headers given in the request (optional and required)
</p>
</div>
</tr>
@@ -2157,6 +2189,25 @@
</ul>
+<h3>Returns:</h3>
+<ul class="return">
+
+ <li>
+
+
+ <span class='type'>(<tt>Bool</tt>)</span>
+
+
+
+ &mdash;
+ <div class='inline'><p>
+true if the signature matches
+</p>
+</div>
+
+ </li>
+
+</ul>
</div><table class="source_code">
<tr>
@@ -2164,77 +2215,15 @@
<pre class="lines">
-180
-181
-182
-183
-184
-185
-186
-187
-188
-189
-190
-191
-192
-193
-194
-195
-196
-197
-198
-199
-200
-201
-202
-203
-204
-205
-206
-207
-208
-209
-210
-211
-212
-213</pre>
+87
+88
+89</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 180</span>
+ <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 87</span>
-<span class='kw'>def</span> <span class='id sign_request'>sign_request</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
- <span class='id opts'>opts</span> <span class='op'>=</span> <span class='id default_opts'>default_opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='rparen'>)</span>
-
- <span class='id uri'>uri</span> <span class='op'>=</span> <span class='const'>Addressable</span><span class='op'>::</span><span class='const'>URI</span><span class='period'>.</span><span class='id parse'>parse</span><span class='lparen'>(</span><span class='id url'>url</span><span class='rparen'>)</span>
- <span class='id headers'>headers</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:headers</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
-
- <span class='id date'>date</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:date</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>Time</span><span class='period'>.</span><span class='id now'>now</span><span class='period'>.</span><span class='id gmtime'>gmtime</span>
- <span class='id date'>date</span> <span class='op'>=</span> <span class='id date'>date</span><span class='period'>.</span><span class='id gmtime'>gmtime</span><span class='period'>.</span><span class='id strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%a, %e %b %Y %T GMT</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id date'>date</span><span class='period'>.</span><span class='id respond_to?'>respond_to?</span> <span class='symbol'>:strftime</span>
-
- <span class='id signature'>signature</span> <span class='op'>=</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='symbol'>:secret</span> <span class='op'>=&gt;</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='symbol'>:method</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>GET</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:path</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id path'>path</span><span class='comma'>,</span> <span class='symbol'>:date</span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span> <span class='symbol'>:nonce</span> <span class='op'>=&gt;</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:query</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span><span class='comma'>,</span> <span class='symbol'>:headers</span> <span class='op'>=&gt;</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:headers</span><span class='rbracket'>]</span><span class='rparen'>)</span>
-
- <span class='kw'>if</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:query_based</span><span class='rbracket'>]</span>
- <span class='id auth_params'>auth_params</span> <span class='op'>=</span> <span class='lbrace'>{</span>
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>date</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span>
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>signature</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id signature'>signature</span>
- <span class='rbrace'>}</span>
- <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='kw'>unless</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id nil?'>nil?</span>
-
- <span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span>
- <span class='id query_values'>query_values</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_param</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span>
- <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id query_values'>query_values</span>
- <span class='kw'>else</span>
- <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_header_format</span><span class='rbracket'>]</span> <span class='op'>%</span> <span class='id opts'>opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='symbol'>:signature</span> <span class='op'>=&gt;</span> <span class='id signature'>signature</span><span class='rbrace'>}</span><span class='rparen'>)</span>
- <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span> <span class='kw'>unless</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:nonce</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id nil?'>nil?</span>
-
- <span class='kw'>if</span> <span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:use_alternate_date_header</span><span class='rbracket'>]</span>
- <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:alternate_date_header</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id date'>date</span>
- <span class='kw'>else</span>
- <span class='id headers'>headers</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Date</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id date'>date</span>
- <span class='kw'>end</span>
- <span class='kw'>end</span>
-
- <span class='lbracket'>[</span><span class='id headers'>headers</span><span class='comma'>,</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id to_s'>to_s</span><span class='rbracket'>]</span>
+<span class='kw'>def</span> <span class='id validate_signature'>validate_signature</span><span class='lparen'>(</span><span class='id signature'>signature</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
+ <span class='id signature'>signature</span> <span class='op'>==</span> <span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id params'>params</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -2242,16 +2231,17 @@
</div>
<div class="method_details ">
- <p class="signature " id="sign_url-instance_method">
+ <p class="signature " id="validate_url_signature-instance_method">
- - (<tt>String</tt>) <strong>sign_url</strong>(url, secret, opts = {})
+ - (<tt>Bool</tt>) <strong>validate_url_signature</strong>(url, secret, opts = {})
</p><div class="docstring">
<div class="discussion">
<p>
-convienience method to sign a url for use with query-based authentication
+convienience method to check the signature of a url with query-based
+authentication
</p>
@@ -2272,7 +2262,7 @@
&mdash;
<div class='inline'><p>
-the url to sign
+the url to test
</p>
</div>
@@ -2349,13 +2339,13 @@
<li>
- <span class='type'>(<tt>String</tt>)</span>
+ <span class='type'>(<tt>Bool</tt>)</span>
&mdash;
<div class='inline'><p>
-The signed url
+true if the signature is valid
</p>
</div>
@@ -2369,23 +2359,33 @@
<pre class="lines">
-224
-225
-226
-227
-228
-229
-230</pre>
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111</pre>
</td>
<td>
- <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 224</span>
+ <pre class="code"><span class="info file"># File 'lib/hmac_signer.rb', line 100</span>
-<span class='kw'>def</span> <span class='id sign_url'>sign_url</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
+<span class='kw'>def</span> <span class='id validate_url_signature'>validate_url_signature</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='id opts'>opts</span> <span class='op'>=</span> <span class='id default_opts'>default_opts</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='rparen'>)</span>
<span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:query_based</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
- <span class='id headers'>headers</span><span class='comma'>,</span> <span class='id url'>url</span> <span class='op'>=</span> <span class='op'>*</span><span class='id sign_request'>sign_request</span><span class='lparen'>(</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='id opts'>opts</span><span class='rparen'>)</span>
- <span class='id url'>url</span>
+ <span class='id uri'>uri</span> <span class='op'>=</span> <span class='const'>Addressable</span><span class='op'>::</span><span class='const'>URI</span><span class='period'>.</span><span class='id parse'>parse</span><span class='lparen'>(</span><span class='id url'>url</span><span class='rparen'>)</span>
+ <span class='id query_values'>query_values</span> <span class='op'>=</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id query_values'>query_values</span>
+ <span class='id auth_params'>auth_params</span> <span class='op'>=</span> <span class='id query_values'>query_values</span><span class='period'>.</span><span class='id delete'>delete</span><span class='lparen'>(</span><span class='id opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:auth_param</span><span class='rbracket'>]</span><span class='rparen'>)</span>
+
+ <span class='id date'>date</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>date</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
+ <span class='id nonce'>nonce</span> <span class='op'>=</span> <span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>nonce</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
+ <span class='id validate_signature'>validate_signature</span><span class='lparen'>(</span><span class='id auth_params'>auth_params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>signature</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:secret</span> <span class='op'>=&gt;</span> <span class='id secret'>secret</span><span class='comma'>,</span> <span class='symbol'>:method</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>GET</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:path</span> <span class='op'>=&gt;</span> <span class='id uri'>uri</span><span class='period'>.</span><span class='id path'>path</span><span class='comma'>,</span> <span class='symbol'>:date</span> <span class='op'>=&gt;</span> <span class='id date'>date</span><span class='comma'>,</span> <span class='symbol'>:nonce</span> <span class='op'>=&gt;</span> <span class='id nonce'>nonce</span><span class='comma'>,</span> <span class='symbol'>:query</span> <span class='op'>=&gt;</span> <span class='id query_values'>query_values</span><span class='comma'>,</span> <span class='symbol'>:headers</span> <span class='op'>=&gt;</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -2397,7 +2397,7 @@
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
2  doc/Warden/Strategies/HMACBase.html
@@ -775,7 +775,7 @@
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
4 doc/Warden/Strategies/HMACHeader.html
@@ -530,7 +530,7 @@
</span> <span class='comment'># &quot;Content-MD5&quot; =&gt; &quot;d41d8cd98f00b204e9800998ecf8427e&quot;
</span> <span class='comment'>#}
</span>
- <span class='id hmac'>hmac</span><span class='period'>.</span><span class='id check_signature'>check_signature</span><span class='lparen'>(</span><span class='id given_signature'>given_signature</span><span class='comma'>,</span> <span class='lbrace'>{</span>
+ <span class='id hmac'>hmac</span><span class='period'>.</span><span class='id validate_signature'>validate_signature</span><span class='lparen'>(</span><span class='id given_signature'>given_signature</span><span class='comma'>,</span> <span class='lbrace'>{</span>
<span class='symbol'>:secret</span> <span class='op'>=&gt;</span> <span class='id secret'>secret</span><span class='comma'>,</span>
<span class='symbol'>:method</span> <span class='op'>=&gt;</span> <span class='id request_method'>request_method</span><span class='comma'>,</span>
<span class='symbol'>:date</span> <span class='op'>=&gt;</span> <span class='id request_timestamp'>request_timestamp</span><span class='comma'>,</span>
@@ -620,7 +620,7 @@
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:03 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
4 doc/Warden/Strategies/HMACQuery.html
@@ -494,7 +494,7 @@
<pre class="code"><span class="info file"># File 'lib/strategies/hmac_query_strategy.rb', line 25</span>
<span class='kw'>def</span> <span class='id signature_valid?'>signature_valid?</span>
- <span class='id hmac'>hmac</span><span class='period'>.</span><span class='id check_url_signature'>check_url_signature</span><span class='lparen'>(</span><span class='id request'>request</span><span class='period'>.</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='rparen'>)</span>
+ <span class='id hmac'>hmac</span><span class='period'>.</span><span class='id validate_url_signature'>validate_url_signature</span><span class='lparen'>(</span><span class='id request'>request</span><span class='period'>.</span><span class='id url'>url</span><span class='comma'>,</span> <span class='id secret'>secret</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
@@ -578,7 +578,7 @@
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
2  doc/_index.html
@@ -118,7 +118,7 @@ <h1 class="alphaindex">Alphabetic Index</h1>
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
14 doc/file.README.html
@@ -330,17 +330,17 @@
<h2>HMACSigner usage</h2>
-<p>The HMACSigner class can be used to validate and generate signatures for a given request.</p>
+<p>The HMACSigner class can be used to validate and generate signatures for a given request. Most methods accept a hash as an intermediate
+representation of the request but some methods accept and operate on full urls.</p>
-<pre class="code"><span class='id h'>h</span> <span class='op'>=</span> <span class='const'>HMACSigner</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>md5</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
-<span class='id h'>h</span><span class='period'>.</span><span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id canonical_representation'>canonical_representation</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
-
-<span class='id h'>h</span><span class='period'>.</span><span class='id validated_signature'>validated_signature</span><span class='lparen'>(</span><span class='id canonical_representation'>canonical_representation</span><span class='comma'>,</span> <span class='id signature'>signature</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
+<pre class="code"><span class='id h'>h</span> <span class='op'>=</span> <span class='const'>HMACSigner</span><span class='period'>.</span><span class='id new'>new</span>
+<span class='id h'>h</span><span class='period'>.</span><span class='id sign_url'>sign_url</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://example.org/example.html</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
+<span class='id h'>h</span><span class='period'>.</span><span class='id validate_url_signature'>validate_url_signature</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://example.org/example.html?auth[signature]=foo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
</pre>
<h2>Licence</h2>
-<p>Copyright (c) 2011 Florian Gilcher <a href="&#x6d;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#x66;&#108;&#111;&#114;&#x69;&#x61;&#x6e;&#46;&#x67;&#x69;&#x6c;&#x63;&#x68;&#x65;&#114;&#64;&#x61;&#115;&#113;&#117;&#x65;&#x72;&#x61;&#x2e;&#100;&#x65;">&#102;&#108;&#x6f;&#114;&#x69;&#97;&#110;&#x2e;&#103;&#105;&#108;&#x63;&#104;&#x65;&#x72;&#x40;&#x61;&#115;&#113;&#x75;&#101;&#114;&#x61;&#46;&#100;&#x65;</a>, Felix Gilcher <a href="&#109;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#x66;&#101;&#108;&#105;&#120;&#46;&#103;&#105;&#108;&#99;&#x68;&#101;&#x72;&#64;&#x61;&#x73;&#x71;&#117;&#x65;&#x72;&#x61;&#46;&#x64;&#101;">&#102;&#x65;&#108;&#105;&#x78;&#46;&#x67;&#x69;&#108;&#99;&#x68;&#x65;&#114;&#x40;&#x61;&#115;&#x71;&#117;&#101;&#114;&#x61;&#x2e;&#x64;&#101;</a></p>
+<p>Copyright (c) 2011 Florian Gilcher <a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#58;&#x66;&#x6c;&#x6f;&#114;&#105;&#97;&#110;&#x2e;&#103;&#x69;&#x6c;&#x63;&#x68;&#101;&#114;&#64;&#97;&#115;&#113;&#x75;&#101;&#114;&#97;&#46;&#x64;&#x65;">&#x66;&#x6c;&#x6f;&#114;&#x69;&#97;&#110;&#46;&#103;&#105;&#108;&#x63;&#x68;&#101;&#114;&#64;&#x61;&#x73;&#113;&#117;&#101;&#114;&#97;&#46;&#x64;&#101;</a>, Felix Gilcher <a href="&#109;&#97;&#x69;&#108;&#x74;&#111;&#x3a;&#102;&#x65;&#108;&#x69;&#x78;&#46;&#x67;&#x69;&#x6c;&#99;&#x68;&#x65;&#x72;&#x40;&#x61;&#115;&#113;&#x75;&#101;&#114;&#x61;&#46;&#100;&#101;">&#x66;&#101;&#x6c;&#x69;&#x78;&#x2e;&#103;&#105;&#108;&#99;&#x68;&#x65;&#114;&#64;&#x61;&#x73;&#x71;&#117;&#x65;&#114;&#x61;&#46;&#100;&#x65;</a></p>
<p>Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -363,7 +363,7 @@
</div></div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
14 doc/index.html
@@ -330,17 +330,17 @@
<h2>HMACSigner usage</h2>
-<p>The HMACSigner class can be used to validate and generate signatures for a given request.</p>
+<p>The HMACSigner class can be used to validate and generate signatures for a given request. Most methods accept a hash as an intermediate
+representation of the request but some methods accept and operate on full urls.</p>
-<pre class="code"><span class='id h'>h</span> <span class='op'>=</span> <span class='const'>HMACSigner</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>md5</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
-<span class='id h'>h</span><span class='period'>.</span><span class='id generate_signature'>generate_signature</span><span class='lparen'>(</span><span class='id canonical_representation'>canonical_representation</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
-
-<span class='id h'>h</span><span class='period'>.</span><span class='id validated_signature'>validated_signature</span><span class='lparen'>(</span><span class='id canonical_representation'>canonical_representation</span><span class='comma'>,</span> <span class='id signature'>signature</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
+<pre class="code"><span class='id h'>h</span> <span class='op'>=</span> <span class='const'>HMACSigner</span><span class='period'>.</span><span class='id new'>new</span>
+<span class='id h'>h</span><span class='period'>.</span><span class='id sign_url'>sign_url</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://example.org/example.html</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
+<span class='id h'>h</span><span class='period'>.</span><span class='id validate_url_signature'>validate_url_signature</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://example.org/example.html?auth[signature]=foo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
</pre>
<h2>Licence</h2>
-<p>Copyright (c) 2011 Florian Gilcher <a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#x3a;&#102;&#108;&#111;&#114;&#105;&#x61;&#x6e;&#46;&#x67;&#x69;&#108;&#99;&#x68;&#x65;&#x72;&#x40;&#x61;&#115;&#113;&#117;&#101;&#x72;&#97;&#46;&#x64;&#x65;">&#102;&#x6c;&#x6f;&#x72;&#x69;&#x61;&#x6e;&#x2e;&#103;&#x69;&#x6c;&#x63;&#104;&#101;&#114;&#64;&#97;&#x73;&#113;&#x75;&#101;&#x72;&#x61;&#46;&#x64;&#101;</a>, Felix Gilcher <a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#58;&#102;&#x65;&#x6c;&#x69;&#120;&#x2e;&#x67;&#105;&#108;&#99;&#104;&#101;&#114;&#64;&#97;&#x73;&#113;&#x75;&#x65;&#x72;&#x61;&#46;&#x64;&#x65;">&#x66;&#101;&#x6c;&#105;&#x78;&#x2e;&#x67;&#x69;&#108;&#99;&#104;&#101;&#x72;&#64;&#97;&#x73;&#113;&#117;&#x65;&#x72;&#x61;&#x2e;&#100;&#x65;</a></p>
+<p>Copyright (c) 2011 Florian Gilcher <a href="&#109;&#x61;&#x69;&#108;&#x74;&#111;&#x3a;&#x66;&#x6c;&#x6f;&#x72;&#105;&#x61;&#110;&#46;&#103;&#105;&#x6c;&#x63;&#x68;&#101;&#114;&#x40;&#97;&#115;&#113;&#117;&#101;&#114;&#x61;&#x2e;&#x64;&#101;">&#102;&#x6c;&#x6f;&#114;&#105;&#97;&#x6e;&#46;&#x67;&#x69;&#x6c;&#99;&#104;&#101;&#114;&#x40;&#x61;&#x73;&#x71;&#x75;&#x65;&#x72;&#97;&#x2e;&#x64;&#101;</a>, Felix Gilcher <a href="&#x6d;&#97;&#x69;&#108;&#116;&#x6f;&#58;&#x66;&#x65;&#108;&#x69;&#x78;&#46;&#x67;&#105;&#108;&#x63;&#104;&#101;&#x72;&#x40;&#x61;&#115;&#x71;&#117;&#x65;&#114;&#97;&#46;&#100;&#101;">&#102;&#101;&#x6c;&#105;&#x78;&#46;&#103;&#105;&#108;&#x63;&#104;&#x65;&#x72;&#x40;&#x61;&#x73;&#113;&#117;&#x65;&#x72;&#x61;&#46;&#x64;&#101;</a></p>
<p>Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -363,7 +363,7 @@
</div></div>
<div id="footer">
- Generated on Sat Jul 16 12:30:02 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
42 doc/method_list.html
@@ -73,22 +73,6 @@ <h1 id="full_list_header">Method List</h1>
<li class="r1 ">
- <span class='object_link'><a href="HMACSigner.html#check_signature-instance_method" title="HMACSigner#check_signature (method)">#check_signature</a></span>
-
- <small>HMACSigner</small>
-
- </li>
-
-
- <li class="r2 ">
- <span class='object_link'><a href="HMACSigner.html#check_url_signature-instance_method" title="HMACSigner#check_url_signature (method)">#check_url_signature</a></span>
-
- <small>HMACSigner</small>
-
- </li>
-
-
- <li class="r1 ">
<span class='object_link'><a href="Warden/Strategies/HMACBase.html#debug-instance_method" title="Warden::Strategies::HMACBase#debug (method)">#debug</a></span>
<small>Warden::Strategies::HMACBase</small>
@@ -225,6 +209,14 @@ <h1 id="full_list_header">Method List</h1>
<li class="r2 ">
+ <span class='object_link'><a href="Warden/Strategies/HMACQuery.html#signature_valid%3F-instance_method" title="Warden::Strategies::HMACQuery#signature_valid? (method)">#signature_valid?</a></span>
+
+ <small>Warden::Strategies::HMACQuery</small>
+
+ </li>
+
+
+ <li class="r1 ">
<span class='object_link'><a href="Warden/Strategies/HMACHeader.html#signature_valid%3F-instance_method" title="Warden::Strategies::HMACHeader#signature_valid? (method)">#signature_valid?</a></span>
<small>Warden::Strategies::HMACHeader</small>
@@ -232,8 +224,16 @@ <h1 id="full_list_header">Method List</h1>
</li>
+ <li class="r2 ">
+ <span class='object_link'><a href="Warden/Strategies/HMACHeader.html#valid%3F-instance_method" title="Warden::Strategies::HMACHeader#valid? (method)">#valid?</a></span>
+
+ <small>Warden::Strategies::HMACHeader</small>
+
+ </li>
+
+
<li class="r1 ">
- <span class='object_link'><a href="Warden/Strategies/HMACQuery.html#signature_valid%3F-instance_method" title="Warden::Strategies::HMACQuery#signature_valid? (method)">#signature_valid?</a></span>
+ <span class='object_link'><a href="Warden/Strategies/HMACQuery.html#valid%3F-instance_method" title="Warden::Strategies::HMACQuery#valid? (method)">#valid?</a></span>
<small>Warden::Strategies::HMACQuery</small>
@@ -241,17 +241,17 @@ <h1 id="full_list_header">Method List</h1>
<li class="r2 ">
- <span class='object_link'><a href="Warden/Strategies/HMACQuery.html#valid%3F-instance_method" title="Warden::Strategies::HMACQuery#valid? (method)">#valid?</a></span>
+ <span class='object_link'><a href="HMACSigner.html#validate_signature-instance_method" title="HMACSigner#validate_signature (method)">#validate_signature</a></span>
- <small>Warden::Strategies::HMACQuery</small>
+ <small>HMACSigner</small>
</li>
<li class="r1 ">
- <span class='object_link'><a href="Warden/Strategies/HMACHeader.html#valid%3F-instance_method" title="Warden::Strategies::HMACHeader#valid? (method)">#valid?</a></span>
+ <span class='object_link'><a href="HMACSigner.html#validate_url_signature-instance_method" title="HMACSigner#validate_url_signature (method)">#validate_url_signature</a></span>
- <small>Warden::Strategies::HMACHeader</small>
+ <small>HMACSigner</small>
</li>
View
2  doc/top-level-namespace.html
@@ -94,7 +94,7 @@
</div>
<div id="footer">
- Generated on Sat Jul 16 12:30:03 2011 by
+ Generated on Sat Jul 16 12:39:13 2011 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.7.2 (ruby-1.9.2).
</div>
View
6 lib/hmac_signer.rb
@@ -84,7 +84,7 @@ def generate_signature(params)
# @option params [Bool] :use_alternate_date_header (false) Use the alternate date header instead of `Date`
#
# @return [Bool] true if the signature matches
- def check_signature(signature, params)
+ def validate_signature(signature, params)
signature == generate_signature(params)
end
@@ -97,7 +97,7 @@ def check_signature(signature, params)
# @option opts [String] :auth_param ('auth') The name of the authentication param to use for query based authentication
#
# @return [Bool] true if the signature is valid
- def check_url_signature(url, secret, opts = {})
+ def validate_url_signature(url, secret, opts = {})
opts = default_opts.merge(opts)
opts[:query_based] = true
@@ -107,7 +107,7 @@ def check_url_signature(url, secret, opts = {})
date = auth_params["date"]
nonce = auth_params["nonce"]
- check_signature(auth_params["signature"], :secret => secret, :method => "GET", :path => uri.path, :date => date, :nonce => nonce, :query => query_values, :headers => {})
+ validate_signature(auth_params["signature"], :secret => secret, :method => "GET", :path => uri.path, :date => date, :nonce => nonce, :query => query_values, :headers => {})
end
# generates the canonical representation for a given request
View
2  lib/strategies/hmac_header_strategy.rb
@@ -35,7 +35,7 @@ def signature_valid?
# "Content-MD5" => "d41d8cd98f00b204e9800998ecf8427e"
#}
- hmac.check_signature(given_signature, {
+ hmac.validate_signature(given_signature, {
:secret => secret,
:method => request_method,
:date => request_timestamp,
View
2  lib/strategies/hmac_query_strategy.rb
@@ -23,7 +23,7 @@ def valid?
#
# @return [Bool] true if the request is valid
def signature_valid?
- hmac.check_url_signature(request.url, secret)
+ hmac.validate_url_signature(request.url, secret)
end
# retrieve the authentication information from the request
View
4 test/hmac_test.rb
@@ -69,8 +69,8 @@
topic.sign_url("http://example.org?foo=bar&baz=foobar", "secret", :date => "Mon, 20 Jun 2011 12:06:11 GMT", :nonce => "TESTNONCE")
end.equals("http://example.org?baz=foobar&foo=bar&auth[date]=Mon%2C%2020%20Jun%202011%2012%3A06%3A11%20GMT&auth[signature]=b2c5c7242f664ce18828f108452b437b&auth[nonce]=TESTNONCE")
- asserts("checking a url_signature") { topic.check_url_signature("http://example.org?baz=foobar&foo=bar&auth[date]=Mon%2C%2020%20Jun%202011%2012%3A06%3A11%20GMT&auth[signature]=b2c5c7242f664ce18828f108452b437b&auth[nonce]=TESTNONCE", "secret") }
- denies("checking an invalid url_signature") { topic.check_url_signature("http://example.org?baz=foobar&foo=bar&auth[date]=Mon%2C%2020%20Jun%202011%2012%3A06%3A11%20GMT&auth[signature]=AAc5c7242f664ce18828f108452b437b&auth[nonce]=TESTNONCE", "secret") }
+ asserts("checking a url_signature") { topic.validate_url_signature("http://example.org?baz=foobar&foo=bar&auth[date]=Mon%2C%2020%20Jun%202011%2012%3A06%3A11%20GMT&auth[signature]=b2c5c7242f664ce18828f108452b437b&auth[nonce]=TESTNONCE", "secret") }
+ denies("checking an invalid url_signature") { topic.validate_url_signature("http://example.org?baz=foobar&foo=bar&auth[date]=Mon%2C%2020%20Jun%202011%2012%3A06%3A11%20GMT&auth[signature]=AAc5c7242f664ce18828f108452b437b&auth[nonce]=TESTNONCE", "secret") }
end
Please sign in to comment.
Something went wrong with that request. Please try again.