-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KBP-178 #time 2h - Implement basic authentication was done
- Loading branch information
hamdibayhan
committed
Dec 6, 2017
1 parent
251a5e9
commit 1b48709
Showing
11 changed files
with
109 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cybele | ||
module Helpers | ||
module BasicAuthentication | ||
def configure_basic_authentication | ||
create_basic_authentication_files | ||
add_to_settings_yml | ||
add_to_dotenv_files | ||
include_basic_authentication_module | ||
configure_app_name(['config/settings.yml']) | ||
end | ||
|
||
private | ||
|
||
def create_basic_authentication_files | ||
# Initialize file | ||
template 'basic_authentication/basic_authentication.rb', | ||
'app/controllers/concerns/basic_authentication.rb', | ||
force: true | ||
end | ||
|
||
def add_to_settings_yml | ||
# Add basic authentication settings to the config/settings.yml file | ||
append_file 'config/settings.yml', | ||
template_content('basic_authentication/basic_authentication_settings.yml.erb') | ||
end | ||
|
||
def add_to_dotenv_files | ||
# Add basic authentication env to the all env files | ||
append_file('env.sample', template_content('basic_authentication/no_basic_authentication.erb')) | ||
append_file('.env.local', template_content('basic_authentication/no_basic_authentication.erb')) | ||
append_file('.env.staging', template_content('basic_authentication/yes_basic_authentication.erb')) | ||
append_file('.env.production', template_content('basic_authentication/no_basic_authentication.erb')) | ||
end | ||
|
||
def include_basic_authentication_module | ||
inject_into_file 'app/controllers/application_controller.rb', | ||
template_content('basic_authentication/include_module.rb'), | ||
after: 'class ApplicationController < ActionController::Base' | ||
end | ||
end | ||
end | ||
end |
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module BasicAuthentication | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_filter :authenticate | ||
end | ||
|
||
private | ||
|
||
def authenticate | ||
if ENV['BASIC_AUTH_IS_ACTIVE'] == 'yes' | ||
authenticate_or_request_with_http_basic do |username, password| | ||
username == Settings.basic_auth.username && password == Settings.basic_auth.password | ||
end | ||
end | ||
end | ||
|
||
end |
3 changes: 3 additions & 0 deletions
3
templates/basic_authentication/basic_authentication_settings.yml.erb
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
basic_auth: | ||
username: <%= app_name %> | ||
password: <%= app_name %> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
include BasicAuthentication |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
BASIC_AUTH_IS_ACTIVE=no |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
BASIC_AUTH_IS_ACTIVE=yes |