Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created November 30, 2011 17:41
Show Gist options
  • Save cadwallion/1409963 to your computer and use it in GitHub Desktop.
Save cadwallion/1409963 to your computer and use it in GitHub Desktop.
Writing custom warden strategies
# For more information on Warden strategies, read this: https://github.com/hassox/warden/wiki/Strategies
class SuperCoolWardenStrategy
def valid?
# you have access to env and request
# return true/false if this is strategy should run or not
# if it returns false, it will move onto the next strategy in the list
# defaults to true if you don't write this method
end
def authenticate!
# again, this has access to env and request
# write your authentication logic
# call `success!(user)` to set the user object
# call `fail!` to fail login explicitly
# to move on to the next strategy, you can explicitly call `pass` or just do nothing
end
end
Warden::Strategies.add(:super_cool_strat, SuperCoolWardenStrategy)
warden.authenticate! :super_cool_strat, :sso_auth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment