Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krzyzak/mini_auth
https://github.com/krzyzak/mini_auth
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/krzyzak/mini_auth
- Owner: krzyzak
- License: mit
- Created: 2014-08-06T14:24:48.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-06T14:51:07.000Z (over 10 years ago)
- Last Synced: 2023-03-13T11:35:53.329Z (almost 2 years ago)
- Language: Ruby
- Size: 137 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MiniAuth
Bullshit–free authentication library, which ain’t smarter than you.
## Synopsis
Add this line to your application's Gemfile:
gem 'mini_auth'
Configure your login strategies:
```ruby
MiniAuth.configure do |c|
c.token_strategy = ->(controller) do
controller.authenticate_with_http_token do |token, options|
User.find_by_token(token)
end
end
# c.cookie_strategy = ->(cookies){ User.find(cookies[:user_id]) }
c.custom_strategy = ->(params){ User.first if params[:request].env["PATH_INFO"] == "something_crazy" }
end
```By default `current_user` helper returns instance of `MiniAuth::NullUser`, but guess what? You can customise it!(eg. if you want to return instance of your custom `Guest` class) – just add
```ruby
MiniAuth.configure do |c|
c.null_user = Guest.new
end
```Add `before_action :require_user!` everywhere you want to require that user is logged in. `MiniAuth::Error::NotLoggedIn` will be raised, if user is not logged in.
If you want to ensure that user is activated, you can add to your config:
```ruby
MiniAuth.configure do |c|
c.activation_check = ->(user){ user.active? }
end
````MiniAuth::Error::NotActivated` will be raised if user is not active
## Contributing
1. Fork it ( https://github.com/[my-github-username]/mini_auth/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request