Created
November 15, 2019 14:44
-
-
Save vilusa/a149bea1a95ec578783d430ffbee9b99 to your computer and use it in GitHub Desktop.
Rails Basic Authentication
This file contains hidden or 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
# BasicAuth Concern | |
include BasicAuthentication |
This file contains hidden or 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
# frozen_string_literal: true | |
module BasicAuthentication | |
extend ActiveSupport::Concern | |
included do | |
before_action :authenticate | |
end | |
private | |
def authenticate | |
return unless ENV['BASIC_AUTH_IS_ACTIVE'].present? | |
authenticate_or_request_with_http_basic do |username, password| | |
username == ENV['BASIC_AUTH_USERNAME'] && password == ENV['BASIC_AUTH_PASSWORD'] | |
end | |
end | |
end |
This file contains hidden or 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
heroku config:set BASIC_AUTH_IS_ACTIVE=yes BASIC_AUTH_USERNAME=kemal BASIC_AUTH_PASSWORD=kemal -a vilusa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment