Gem that updates devise to work with external clients. Specially created to work with devise for iOS.
It currently implements authentication only with a "simple token authentication".
Name | Version |
---|---|
Ruby | 2.1.5 |
Rails | 4.1.8 |
Devise | |
Simple Token Authentication | |
Active Model Serializers |
With a working devise environment, the only thing you need to do is:
- add gem to the Gemfile
gem 'devise-ios-rails'
- run bundler to install the gem
bundle install
- setup devise like you would normally do (check the installation guide)
- in your routes change
devise_for ModelName
withdevise_ios_rails_for ModelName
(ModelName is usually User) - authentication is handled by user token which is generated for each user during the registration process.
To make it work you need to run migration that adds authentication_token
column to your Devise model.
If your ModelName is User
then the migration should look like this:
class AddUniqueTokenToUser < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, unique: true
end
end
Don't forget about rake db:migrate
.
-To protect actions to only registered users, add acts_as_token_authentication_handler_for User
in your controller:
class SecretSpacesController < ApplicationController
acts_as_token_authentication_handler_for User
end
- If you want to skip authentication for some actions add
skip_before_filter :authenticate_user_from_token!, only: [:action]
in your controller
class SecretSpacesController < ApplicationController
acts_as_token_authentication_handler_for User
skip_before_filter :authenticate_user_from_token!, only: [:new]
end
In order to run tests, first you need setup the gem locally.
- clone the repo to your machine
git clone https://github.com/netguru/devise-ios-rails.git
- go inside gems directory
cd devise-ios-rails
and run bundle commandbundle install
- now you need to setup your environment variables. You can simply just copy over
.env.sample
to.env
. It should look more or less like this:
DOMAIN_NAME='localhost:3000'
DOMAIN_URL='http://localhost:3000'
SECRET_KEY_BASE='a_very_long_string'
DEFAULT_SENDER='[email protected]'
then you can run your tests by typing rspec
.
First, thank you for contributing!
Here's a few guidelines to follow:
- we follow Ruby Style Guide.
- you can use rubocop which can be easily integrated with popular editors. (our rubocop config)
- write tests
- make sure the entire test suite passes
- make sure rubocop passes our config
- open a pull request on GitHub
- squash your commits after receiving feedback
You can also read our blog post announcing devise-iOS for simplified auth.
Copyright 2014-2015 © Netguru, released under the New BSD License