-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80648f2
commit ed68359
Showing
2 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Add Avo behind Basic Authentication | ||
|
||
Because in Rails we commonly do that using a static function on the controller we need to [safely extend the controller](https://avohq.io/blog/safely-extend-a-ruby-on-rails-controller) to contain that function. | ||
|
||
In actuality we will end up with something that behaves like this: | ||
|
||
```ruby{2} | ||
class Avo::ApplicationController < ::ActionController::Base | ||
http_basic_authenticate_with name: "adrian", password: "password" | ||
# More methods here | ||
end | ||
``` | ||
|
||
## Safely add it to Avo | ||
|
||
We described the process in depth in [this article](https://avohq.io/blog/safely-extend-a-ruby-on-rails-controller) so let's get down to business. | ||
|
||
1. Add the `BasicAuth` concern | ||
1. The concern will prepend the basic auth method | ||
1. `include` that concern to Avo's `ApplicationController` | ||
|
||
```ruby{8,20} | ||
# app/controllers/concerns/basic_auth.rb | ||
module BasicAuth | ||
extend ActiveSupport::Concern | ||
# Aiuthentication strategy came from this article | ||
# https://dev.to/kevinluo201/setup-a-basic-authentication-in-rails-with-http-authentication-388e | ||
included do | ||
http_basic_authenticate_with name: "adrian", password: "password" | ||
end | ||
end | ||
# config/initializers/avo.rb | ||
Avo.configure do |config| | ||
# Avo configuration | ||
end | ||
# Add this to include it to Avo's ApplicationController | ||
Rails.configuration.to_prepare do | ||
# Add basic authentication to Avo | ||
Avo::ApplicationController.include BasicAuth | ||
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