Tok
No-frills token-based authentication for modern Rails applications.
Installation
Tok works with (and is tested against) Rails > 4.0. To install, add this line to your Gemfile:
gem 'tok'
Then run bundle install
. You can always install the gem yourself by executing:
$ gem install tok
Usage
First, run the generator by executing:
$ rails generate tok:install
The generator by default does the following:
- Inserts
Tok::Authentication
intoUser
model (or creates one if not available) - Inserts
Tok::Controller
into yourApplicationController
- Creates a number of default routes
signup
,login
, andlogout
- Creates an initializer at
config/initializers/tok.rb
to allow further configuration
A custom model can be specified by passing --model
(or just -m
) as an option to the generator:
$ rails generate tok:install -m Account
$ rails generate tok:install --model=Account
In this case, the generator will also create a migration in order to create a table with the specified model pluralized.
Next, run migrations by executing:
$ rake db:migrate
Configure
To configure Tok, you can override defaults in your config/initializers/tok.rb
. Be sure to check the initializer for further details into what values are used by default.
# Use the following configuration block to adjust Tok.
Tok.configure do |config|
config.model = Account
config.bcrypt_cost = 8
config.signup_route = "sign_up"
config.login_route = "sign_in"
config.logout_route = "sign_out"
end
Contributing
- Fork it ( https://github.com/[my-github-username]/tok/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