enigma

DESCRIPTION:

Key/secret authentication for your web services

FEATURES/PROBLEMS:

  • I just started implementing this today, so it’s really not ready for use. I would love your opinions about the current API and possible improvements.

SYNOPSIS:

Let’s say you have a web service endpoint coded in Sinatra that says “Hello, world”:

# app.rb
get '/' do
  "Hello, world!"
end

Enigma will allow you to authenticate the service using a key/secret scheme:

>> Enigma.generate_key
=> "03637dee19a1c96c1547f8834ca5e96c"
>> Enigma.generate_secret
=> "1f430a0481601697898a566ae54fde5a"

# app.rb

Enigma.find_secret do |key|
  # Usually, you'd have these stored in your database. 
  # For this example, we'll just return the secret if we have a matching
  # key.
  if key == "03637dee19a1c96c1547f8834ca5e96c"
    return "1f430a0481601697898a566ae54fde5a"
  end
end

get '/' do
  if (params = Enigma.authenticate(params))
    "Hello, world."
  else
    "Not authorized."
  end
end

It provides a wrapper for the rest-client gem which properly encodes URI parameters on the query string for consumption by Enigma:

# client.rb

client = Enigma::Client.new(
  "03637dee19a1c96c1547f8834ca5e96c",
  "1f430a0481601697898a566ae54fde5a"
)

client.get("http://localhost:4567").body
=> "Hello, world."

The Enigma.authenticate method returns the unencoded parameters if the authentication is successful; otherwise it returns nil.

REQUIREMENTS:

  • ezcrypto

INSTALL:

sudo gem install enigma

LICENSE:

(The MIT License)

Copyright © 2010 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.