Skip to content

Instantly share code, notes, and snippets.

@vilusa
Created September 2, 2021 14:18
Show Gist options
  • Save vilusa/4a7b6e3d24344c805098de64e141e31e to your computer and use it in GitHub Desktop.
Save vilusa/4a7b6e3d24344c805098de64e141e31e to your computer and use it in GitHub Desktop.
Rails Basich Authentication Concern
# 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