User authentication mechanism provided in the HTTP communication standard
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :basic_auth
(abridgement)
private
def basic_auth
authenticate_or_request_with_http_basic do |username, password|
username == 'admin' && password == '1111'
end
end
end
Terminal
% vim ~/.zshrc
# .After opening zshrc, type "i" to enter insert mode
# .Added the following description inside zshrc
export BASIC_AUTH_USER='admin'
export BASIC_AUTH_PASSWORD='2222'
#After adding the description, press the esc key to exit insert mode and read ":Type wq to save and exit
# .Reload zshrc and enable the defined environment variables
% source ~/.zshrc
Terminal
$ vim ~/.bash_profile
# .bash_After opening the profile, type "i" to enter insert mode
# .bash_Added the following description inside profile
export BASIC_AUTH_USER='admin'
export BASIC_AUTH_PASSWORD='2222'
#After adding the description, press the esc key to exit insert mode and read ":Type wq to save and exit
# .bash_Reload profile and enable defined environment variables
$ source ~/.bash_profile
Recommended Posts