Skip to content

Supported ORM ODM OxM

Gonzalo Bulnes Guilpain edited this page Sep 3, 2015 · 1 revision

Support exists for ActiveRecord and Mongoid. Experimental support exists for Neo4j.

ActiveRecord

Available since: v1.0.0

Any models which inherits from ActiveModel::Base can act as token authenticatable:

class User < ActiveRecord::Base
  acts_as_token_authenticatable

  # Note: you can include any module you want. If available,
  # token authentication will be performed before any other
  # Devise authentication method.
  #
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :invitable, :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable,
         :lockable

  # ...
end

If the model or models you chose have no :authentication_token attribute, add them one (with an index):

rails g migration add_authentication_token_to_users authentication_token:string:index
rake db:migrate

Mongoid

Available since: v1.6.0

Any kind of Mongoid::Document can act as token authenticatable:

# app/models/user.rb

class User
  include Mongoid::Document
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  ## Token Authenticatable
  acts_as_token_authenticatable
  field :authentication_token

  # ...
end

Neo4j

Experimental: see #98 for details

It allows any kind of Neo4j::ActiveNode to acts as token authenticatable.