Created
April 15, 2016 17:31
-
-
Save hchood/734847937ad5c8e3e6a2bc079a25c0fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# routes.rb | |
constraints AuthenticatedConstraint.new do | |
resources :widgets, only: :index | |
end | |
# app/constraints/authenticated_constraint.rb | |
class AuthenticatedConstraint | |
def matches?(request) | |
warden = request.env['warden'] | |
warden && warden.authenticate!(:token_authentication_strategy) | |
end | |
end | |
Warden::Strategies.add(:token_authentication_strategy, | |
TokenAuthenticationStrategy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment