Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@madtrick
Created October 19, 2012 08:43
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save madtrick/3916999 to your computer and use it in GitHub Desktop.
Save madtrick/3916999 to your computer and use it in GitHub Desktop.
Example module to perform remote authentication with Devise
module Devise
module Models
module RemoteAuthenticatable
extend ActiveSupport::Concern
#
# Here you do the request to the external webservice
#
# If the authentication is successful you should return
# a resource instance
#
# If the authentication fails you should return false
#
def remote_authentication(authentication_hash)
# Your logic to authenticate with the external webservice
end
module ClassMethods
####################################
# Overriden methods from Devise::Models::Authenticatable
####################################
#
# This method is called from:
# Warden::SessionSerializer in devise
#
# It takes as many params as elements had the array
# returned in serialize_into_session
#
# Recreates a resource from session data
#
def serialize_from_session(id)
resource = self.new
resource.id = id
resource
end
#
# Here you have to return and array with the data of your resource
# that you want to serialize into the session
#
# You might want to include some authentication data
#
def serialize_into_session(record)
[record.id]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment