Skip to content

Instantly share code, notes, and snippets.

@vilusa
Created November 15, 2019 14:44
Show Gist options
  • Save vilusa/a149bea1a95ec578783d430ffbee9b99 to your computer and use it in GitHub Desktop.
Save vilusa/a149bea1a95ec578783d430ffbee9b99 to your computer and use it in GitHub Desktop.
Rails Basic Authentication
# BasicAuth Concern
include BasicAuthentication
# 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
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