Skip to content

adhearsion/mojo-auth.rb

Repository files navigation

Gem Version Build Status Dependency Status Code Climate Coverage Status Inline docs

mojo_auth

MojoAuth is a set of standard approaches to cross-app authentication based on Hash-based Message Authentication Codes (HMAC), inspired by "A REST API For Access To TURN Services".

Installation

Add this line to your application's Gemfile:

gem 'mojo_auth'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mojo_auth

Usage

require 'mojo_auth'

# Generate a shared secret
secret = MojoAuth.create_secret
  # => "XyD+xeJHivzbOUe3vwdU6Z5vDe/vio34MxKX8HYViR0+p4t/NzaIpbK+9VwX\n5qHCj7m4f7UNRXgOJPXzn6MT0Q=="

# Create temporary credentials
credentials = MojoAuth.create_credentials(id: 'foobar', secret: secret)
  # => {:username=>"1411837760:foobar", :password=>"wb6KxLj6NXcUaqNb1SlHH1V3QHw="}

# Test credentials
MojoAuth.test_credentials({username: "1411837760:foobar", password: "wb6KxLj6NXcUaqNb1SlHH1V3QHw="}, secret: secret)
  # => "foobar"
MojoAuth.test_credentials({username: "1411837760:foobar", password: "wrongpassword"}, secret: secret)
  # => false

# 1 day later
MojoAuth.test_credentials({username: "1411837760:foobar", password: "wb6KxLj6NXcUaqNb1SlHH1V3QHw="}, secret: secret)
  # => false

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request