Skip to content
This repository was archived by the owner on Aug 27, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ AuthHMAC.sign! takes a HTTP request object, an access id and a secret key and si
* The access_id is used to identify the secret key that was used to sign the request. Think of it as like a user name, it allows you to hand out different keys to different clients and authenticate each of them individually. The access_id is sent in the clear so you should avoid making it an important string.
* The secret key is the shared secret between the client and the server. You should make this sufficiently random so that is can't be guessed or exposed to dictionary attacks. The follow code will give you a pretty good secret key:

random = File.read('/dev/random', 512)
secret_key = [Digest::SHA2.new(512).digest(random)].pack('m')
random = File.read('/dev/random', 512)
secret_key = [Digest::SHA2.new(512).digest(random)].pack('m')

On the server side you can then authenticate these requests using the AuthHMAC.authenticated? method. This takes the same arguments as the sign! method but returns true if the request has been signed with the access id and secret or false if it hasn't.

If you have more than one set of credentials you might find it useful to create an instance of the AuthHMAC class, passing your credentials as a Hash of access id => secret keys, like so:

@authhmac = AuthHMAC.new('access_id1' => 'secret1', 'access_id2' => 'secret2')
@authhmac = AuthHMAC.new('access_id1' => 'secret1', 'access_id2' => 'secret2')

You can then use the instance methods of the @authhmac object to sign and authenticate requests, for example:

@authhmac.sign!(request, "access_id1")
@authhmac.sign!(request, "access_id1")

will sign +request+ with "access_id1" and it's corresponding secret key. Similarly authentication is done like so:

Expand Down