Giter Site home page Giter Site logo

devise-ios-rails's Introduction

Devise iOS Rails Backend

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".

Requirements

Name Version
Ruby 2.1.5
Rails 4.1.8
Devise
Simple Token Authentication
Active Model Serializers

Setup

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 with devise_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

Facebook

To sign in using Facebook include DeviseIosRails::Oauth in your model after the devise method:

class User < ActiveRecord::Base
  acts_as_token_authenticatable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  include DeviseIosRails::OAuth
end

Add required fields to the model (keep in mind that you might not get e-mail address from the provider):

class AddOauthToUsers < ActiveRecord::Migration
  def change
    add_column :users, :uid, :string
    add_column :users, :provider, :string
    add_column :users, :oauth_token, :string

    change_column :users, :email, :string, :null => true

    add_index :users, [:uid, :provider], unique: true
  end
end

And update routes:

devise_scope :user do
  post 'auth/facebook', to: 'devise_ios_rails/oauth#facebook'
end

Example app

Testing

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 command bundle 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.

Contribution

First, thank you for contributing!

Here's a few guidelines to follow:

You can also read our blog post announcing devise-iOS for simplified auth.

Copyright 2014-2015 © Netguru, released under the New BSD License

devise-ios-rails's People

Contributors

grosshei avatar jeffleeismyhero avatar testbrian avatar

Watchers

 avatar  avatar

Forkers

jeffleeismyhero

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.