ActiveAdmin with http authentication
Contact me at LinkedIn  RailsZilla at Facebook  RailsZilla at twitter   google +1  Contact me at Xing  connect me at github

ActiveAdmin with http authentication

Posted in Rails

Ever asked yourself how to use HTTP Basic authentication with ActiveAdmin?
There are several reasons to use HTTP Basic authentication for your backend. I needed a solution which can be recycled wherever I need a HTTP Basic authentication. I only wanted a central place for User and Password and I wanted just one call wherever I need my authentication.
Lets go …

In your application controller:

1
2
3
4
5
6
7
8
9
#
# app/controllers/application_controller.rb
#
  protected
  def authenticate
    authenticate_or_request_with_http_basic do |username, password|
      username == "admin" && password == "superpassword"
    end
  end

Now you can call …

1
before_filter :authenticate

… whenever you need a HTTP Basic authentication.

In case of ActiveAdmin, let’s call our before_filter like that:

1
2
3
4
5
6
7
8
9
10
#
# config/initializers/active_admin.rb
#
ActiveAdmin.setup do |config|
  ...

  # http auth for admin area
  config.before_filter :authenticate

  ...

Have fun!

Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Please enter a secure code to see if you are a spammer ;-)

 

Copyright © 2011-2017  - RailsZilla – Ruby on Rails tutorials, tips and tricks All rights reserved. | Imprint | Privacy