Created
September 2, 2021 14:18
-
-
Save vilusa/4a7b6e3d24344c805098de64e141e31e to your computer and use it in GitHub Desktop.
Rails Basich Authentication Concern
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
# frozen_string_literal: true | |
module BasicAuthentication | |
extend ActiveSupport::Concern | |
included do | |
before_action :basic_authenticate | |
end | |
private | |
def basic_authenticate | |
return unless ENV['BASIC_AUTH_IS_ACTIVE'].present? | |
authenticate_or_request_with_http_basic do |username, password| | |
username == ENV.fetch("BASIC_AUTH_USERNAME") { "username" } && password == ENV.fetch("BASIC_AUTH_PASSWORD") { "password" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment