A devise extension for remote user authentication.
Add to Gemfile:
gem 'devise-remote-user'
Then
bundle install
Sorry, there are no generators yet, so ...
- Add
:remote_user_authenticatable
symbol todevise
statement in user model, before other authentication strategies (e.g.,:database_authenticatable
). - Add
before_action :authenticate_user!
to ApplicationController, if not already present. This ensures that remote user is logged in locally (via database).
Configuration options:
env_key
- String/Proc (optional, default:'REMOTE_USER'
). Request environment key for the remote user id. Also may be set to a Proc that receives|env|
and returns a String.attribute_map
- Hash (optional, default:{}
). Map of User model attributes to request environment keys for updating the local user when auto-creation is enabled.auto_create
- Boolean (optional, default:false
). Whether to auto-create a local user from the remote user attributes. Note: Also requires adding the Warden callbacks as shown below.auto_update
- Boolean (optional, default:false
). Whether to auto-update authenticated user attributes from remote user attributes.login_url
- String/Proc (optional, default:nil
). If set, the authentication strategy will redirect to the URL if there is not a remotely authenticated user set in the request env (viaenv_key
, above). May be set to a Proc that receives|env|
and returns a String.logout_url
- String (optional, default:'/'
). For redirecting to a remote user logout URL after signing out of the Rails application. IncludeDeviseRemoteUser::ControllerBehavior
in your application controller to enable (by overriding Devise'safter_sign_out_path_for
).
Set options in a Rails initializer (e.g., config/intializers/devise.rb
):
require 'devise_remote_user'
DeviseRemoteUser.configure do |config|
config.env_key = 'REMOTE_USER'
config.auto_create = true
config.auto_update = true
config.attribute_map = { email: 'mail' }
config.logout_url = "http://example.com/logout"
config.login_url = Proc.new { |env| "http://example.com/login?return_to=#{env["REQUEST_URI"]}" }
end
rake spec
runs the test suite.