Project

au_pair

0.01
No commit activity in last 3 years
No release in over 3 years
AuPair provides token-based authentication and versioning for Rails API applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

AuPair

AuPair provides token-based authentication and versioning for Rails API applications.

Installation

In your Gemfile:

gem 'au_pair'

API Authentication

AuPair's authentication functionality allows you to limit access to your API to those clients that provide registered names and associated tokens through their request, either via headers or path variables.

For header-based authentication, clients must set the x-api-vendor and x-api-token headers.

For path-based authentication, clients pass in api_token and api_vendor parameters through the request.

To set up tokens, create a configuration file in config/initializers/au_pair.rb to specify client apps and their associated auth tokens:

AuPair.configure do |config|

  config.tokens = {
    'my_sample_app' => '12345'
  }

end

(Note that for security reasons, you probably want to read in the tokens from an environment variable as opposed to storing them in your source code.)

Then in your application controller, or in individual controllers if you want to limit authentication to certain actions:

class ApplicationController < ActionController::Base
  include AuPair::Authenticates
  before_filter :authenticate!
end

Even after including the above code, you may optionally disable authentication. This may be useful if you didn't want authentication to occur in certain environments. To do so, simply add the following to your config:

AuPair.configure do |config|

  # config.tokens = ...

  config.authentication_disabled = true #or read from an environment variable

end

API Versioning Support

Specify groups of routes per API version In your routes file:

constraints(AuPair::ApiConstraint.new('v1')) do
  resources :widgets
end

Client apps can then specify the API version that they want to use by passing in an x-api-version header or an api_version URL parameter.

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 new Pull Request