lucky-basic-auth v0.2.1
lucky-basic-auth
Adds some basic auth in to your lucky app using a pipe instead of HTTP Handler
Installation
Requires Lucky v0.17 or later
- Add the dependency to your
shard.yml
:
dependencies:
lucky-basic-auth:
github: jwoertink/lucky-basic-auth
- Run
shards install
Usage
Require the shard
# in src/shards.cr
require "lucky-basic-auth"
Include it in your main BrowserAction
# in src/actions/browser_action.cr
abstract class BrowserAction < Lucky::Action
include Lucky::ProtectFromForgery
# include it
include Lucky::BasicAuthPipe
# use it
basic_auth
end
Or, you can also make a subclass to handle auths
# src/actions/authorized_action.cr
abstract class AuthorizedAction < BrowserAction
include Lucky::BasicAuthPipe
basic_auth
end
class MyAction < AuthorizedAction
get "/admin/my_action" do
plain_text "I'm secure!"
end
end
Call the basic_auth
to enable.
# in src/actions/whatever/your_action.cr
class Whatever::YourAction < BrowserAction
basic_auth
#...
end
This method requires 2 ENV
variables to exist. This will check for the username and password to match these variables.
ENV["AUTH_USERNAME"]
ENV["AUTH_PASSWORD"]
If you need more control over how the values are checked (e.g. lookup from a database, or check role authorization), you can pass a proc.
# in src/actions/whatever/your_action.cr
class Whatever::YourAction < BrowserAction
basic_auth ->(user, pass) {
user == MY_USERNAME_THING && pass == MY_PASSWORD_CHECKER
}
#...
end
This gives you the option to set different user and pass per action if you want.
Development
write specs
Contributing
- Fork it (https://github.com/jwoertink/lucky-basic-auth/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Jeremy Woertink - creator and maintainer
Repository
lucky-basic-auth
Owner
Statistic
- 1
- 1
- 0
- 1
- 0
- over 3 years ago
- December 10, 2018
License
MIT License
Links
Synced at
Sun, 22 Dec 2024 05:16:35 GMT
Languages