Skip to content

Instantly share code, notes, and snippets.

@hchood
Created April 15, 2016 17:31
Show Gist options
  • Save hchood/734847937ad5c8e3e6a2bc079a25c0fb to your computer and use it in GitHub Desktop.
Save hchood/734847937ad5c8e3e6a2bc079a25c0fb to your computer and use it in GitHub Desktop.
# 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