Skip to content

Instantly share code, notes, and snippets.

@hchood
Created April 15, 2016 17:37
Show Gist options
  • Save hchood/51c46ebdf0589552235e5ddcaabb3a50 to your computer and use it in GitHub Desktop.
Save hchood/51c46ebdf0589552235e5ddcaabb3a50 to your computer and use it in GitHub Desktop.
# app/models/user.rb
class User < ActiveRecord::Base
# ...
def self.for_authentication(token)
where(authentication_token: token).
where('authentication_token_expires_at > ?', Time.current).
first
end
end
# app/strategies/token_authentication_strategy.rb
class TokenAuthenticationStrategy < Warden::Strategies::Base
# ...
def user
@user ||= User.for_authentication(token)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment