Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Token-based rails-api authentication with Devise
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
~> 0.28.0

Runtime

~> 3.5
 Project Readme

THIS PROJECT IS DEPRECATED

devise-rails-api-authentication is not maintained anymore.

DeviseRailsApiAuthentication Build Status

Token-based rails-api authentication with Devise.

Devise does not support token-based authentication anymore and devise_token_auth does not work with rails-api.

It's basically this gist wrapped as a gem with specs.

Installation

Add this line to your application's Gemfile:

gem 'devise_rails_api_authentication'

And then execute:

$ bundle

Or install it yourself as:

$ gem install devise_rails_api_authentication

Usage

First of all make sure you have a model class with authentication_token and email fields. Otherwise create a migration, here's an example for a User model and ActiveRecord:

class AddDeviseToUsers < ActiveRecord::Migration
  def self.change
    add_column :users, :email, :text, null: false, default: ''
    add_index :users, :email, unique: true
    add_column :users, :authentication_token, :text, null: false, default: ''
    add_index :users, :authentication_token, unique: true
  end
end

Next add the following lines to ApplicationController - see source:

class ApplicationController
  include DeviseRailsApiAuthentication::Context

  private def user
    User.where(email: user_email).first
  end
end

and the following line to your model class - see source:

class YourUserModel
  include DeviseRailsApiAuthentication::Authenticatable
end

Once you run the migration, create a new user, and boot up your app, just do:

curl -H "X_USER_EMAIL: <email>" -H "X_USER_TOKEN: <token>" http://<where-your-app-lives>

Contributing

  1. Fork it ( https://github.com/altmetric/devise_rails_api_authentication/fork )
  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

License

This project is released under the MIT license.