Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apipie with Devise authentication

I just made a cool API and documented it with Apipie. The problem is my doc page is public and I would like it to use my authentication system already in place.

I'm using Devise and I don't really now how to do it.

Here is what I found about apipie authentication on github page:

Create a /config/initializers/apipie.rb with:

Apipie.configure do |config|
  config.authenticate = Proc.new do
     authenticate_or_request_with_http_basic do |username, password|
       username == "test" && password == "supersecretpassword"
    end
  end
end

I would like to avoid basic auth. How could I extend the ApipiesController to use my Devise authentication ?

Thanks !

like image 794
YoyoS Avatar asked May 21 '26 09:05

YoyoS


2 Answers

Someone already answered me on github.

It was as simple as

config.authenticate = Proc.new do
  authenticate_admin_user!
end

https://github.com/Apipie/apipie-rails/issues/349

like image 106
YoyoS Avatar answered May 22 '26 21:05

YoyoS


You could do something like this to redirect to home page unless they are signed in.

  config.authenticate = Proc.new do 
    redirect_to '/' unless current_user
  end
like image 42
jgraft Avatar answered May 22 '26 23:05

jgraft