Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication at the route level #783

Closed
ShootingStarr opened this issue Jun 28, 2016 · 3 comments
Closed

Authentication at the route level #783

ShootingStarr opened this issue Jun 28, 2016 · 3 comments

Comments

@ShootingStarr
Copy link

Hey guys, in Device we have this method:

# config/routes.rb
authenticate :user do
  mount Sidekiq::Web => '/sidekiq'
end

https://github.com/mperham/sidekiq/wiki/Monitoring#authentication

Do we have similar method in Sorcery?

@Ch4s3
Copy link
Contributor

Ch4s3 commented Jun 28, 2016

create lib/auth_constraint.rb

class AdminConstraint
  def matches?(request)
    return false unless request.session[:user_id]
    user = User.find request.session[:user_id]
    user && user.root?
  end
end

Then in your routes:

  mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new

or something like this. Check the wiki https://github.com/NoamB/sorcery/wiki/Routes-Constraints

@ShootingStarr
Copy link
Author

@Ch4s3 thx

@hendricius
Copy link

Is there a way to do this without a constraint? Or is this best practice? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants