Installation
- In your Gemfile add line
gem 'proxy_auth'
- Run
bundle install
- Set config/secrets.yml:
#!bash proxy: token: SECRET_TOKEN url: http://HOST:PORT service: name: SERVICE_NAME url: http://SERVICE_HOST:SERVICE_PORT version: API_VERSION
- Initialize with command
rails generate proxy_auth:install
- Secure your application. In file app/controllers/application_controller.rb ``` #!ruby before_action :authenticate
protected
def authenticate authenticate_token || render_unauthorized end
def authenticate_token authenticate_with_http_token do |token| ProxyAuth::Token.instance.valid? token end end
def render_unauthorized render json: 'Bad credentials', status: 401 end
6. Add management routes
!ruby
mount ProxyAuth::Engine => '/proxy'
7. Restart your Rails application.
8. Rake task for reconnecting to proxy: ```rake proxy_auth:register_service```