-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for HTTP Basic auth based on ENV vars (#21)
* Support basic auth based on ENV vars * Update README. * Fix rubocop.
- Loading branch information
1 parent
74183b5
commit 762e103
Showing
2 changed files
with
19 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::Base | ||
before_action :authenticate | ||
protect_from_forgery unless: -> { request.format.json? } | ||
|
||
def authenticate | ||
# rubocop:disable Metrics/LineLength | ||
basic_auth_username = ENV.fetch('BASIC_AUTH_USERNAME', '') | ||
basic_auth_password = ENV.fetch('BASIC_AUTH_PASSWORD', '') | ||
|
||
return true if basic_auth_username.empty? | ||
|
||
authenticate_or_request_with_http_basic('Ciao Application') do |username, password| | ||
username == basic_auth_username && password == basic_auth_password | ||
end | ||
# rubocop:enable Metrics/LineLength | ||
end | ||
end |