Created
May 30, 2014 17:22
-
-
Save mupkoo/9e7b28753c75fbcabf95 to your computer and use it in GitHub Desktop.
HTTP Auth for Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include HttpAuthConcern | |
# the rest of your code | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HttpAuthConcern | |
extend ActiveSupport::Concern | |
included do | |
before_action :http_authenticate | |
end | |
def http_authenticate | |
return true unless Rails.env == 'production' | |
authenticate_or_request_with_http_basic do |username, password| | |
username == 'username' && password == 'password' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment