YoyoS
YoyoS

Reputation: 669

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 !

Upvotes: 3

Views: 734

Answers (2)

YoyoS
YoyoS

Reputation: 669

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

Upvotes: 3

jgraft
jgraft

Reputation: 938

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

Upvotes: 1

Related Questions