This gem provides a mechanism for authenticating via Ex Libris' Patron Directory Services (PDS) and provides hooks for making authorization decisions based on the user information provided by PDS. It leverages the authlogic gem and depends on a User-like model.
Generate User-like model:
rails generate model User username:string email:string firstname:string \ lastname:string mobile_phone:string crypted_password:string password_salt:string \ session_id:string persistence_token:string login_count:integer last_request_at:string \ current_login_at:string last_login_at:string last_login_ip:string current_login_ip:string \ user_attributes:text refreshed_at:datetime
Generate UserSession model
rails generate authlogic:session user_session
Create UserSessions controller
rails generate controller UserSessions –no-assets –no-helper
Mixin authpds methods into UserSessionsController
class UserSessionsController < ApplicationController require 'authpds'
Mixin authpds methods into ApplicationController
class ApplicationController < ActionController::Base
protect_from_forgery require 'authpds' include ::::
The Authpds gem mixes in callbacks to Authlogic for persisting sessions based on a valid PDS handle.
The module extends Authlogic and should be compatible with Authlogic configuation. It also provides hooks for custom functionality. The documentation below describes the hooks available for overriding, PDS config methods and further details about the module.
Config Options Available
Base pds url
Name of the system
Does the system allow anonymous access?
Mapping of PDS attributes to record attributes
Custom redirect logout url
Custom url to redirect to in case of system outage
PDS user method to call to identify record
Querystring parameter key for the institution value in this system
URL name for validation action in routes
Hooks Available for Overriding
Allows for more complex logic in determining what should be used as the record identifier.
Defaults to what was set in the pds_record_identifier config.
If there is no PDS handle, can we redirect to PDS to establish a SSO session based on some other information?
Allows for additions to the authorization decision
Allows for additional attributes to be stored in the record
Indicates when the record information should be refreshed. Defaults to one week ago.
Further Implementation Details
Persisting a Session in AuthLogic
When persisting a Session, Authlogic attempts to create the Session based on information available without having to perform an actual login by calling the :persisting? method. Authologic provides several callbacks from the :persisting? method, e.g. :before_persisting, :persist, :after_persisting. We're using the :persist callback and setting it to :persist_session.
Access to the controller in Session
The class that Session extends, Authologic::Session::Base, has an explicit handle to the current controller via the instance method :controller. This gives our custom instance methods access to cookies, session information, loggers, etc. and also allows them to perform redirects and renders.
:before_login vs. :login_url
:before_login allows for customized processing before the SessionController invokes a redirect or render to a /login page. It is is fully generic and can be used for any custom purposes. :login_url is specific for the case of logging in from a remote sytem. The two methods can be used in conjuction, but any redirects or renders performed in :before_login, will supercede a redirect to :login_url.