Add this line to your application's Gemfile:
gem 'auth0_current_user'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install auth0_current_user
After including the gem in your Gemfile, run rails g auth0_current_user:install
to install the initializer. This configuration of the gem is dependant on a couple of attributes:
client_id
- This is the client id for your tenant. It is used to facilitate redirecting to the
/authorize
endpoint inWebSecured
when the user's session has expired or is non-existant
- This is the client id for your tenant. It is used to facilitate redirecting to the
auth0_domain
- This is the domain from setting up your Auth0 application.
auth0_audience
- This is the api identifier that you chose when creating your api(M2M) application
authenticated_klass
- Defaults to
User
, but if you have a different model name for the class that will be logging in and being authenticate, be sure to change that in the initializer. - accepted values are symbols or strings
- :user, 'user', :User, 'User'
- :my_user, 'my_user', :MyUser, 'MyUser'
- Defaults to
To take advantage of the Auth0 authentication there are two flows you can use by simply including the relevant module in which ever controller you wish to lockdown.
-
Web
a.
include Auth0CurrentUser::WebSecured
-
Api
a.
include Auth0CurrentUser::ApiSecured
In either case, you will have access to the current_user
method. The WebSecured
will check for current_user
or session['userinfo']
and the ApiSecured
will check against the JsonWebToken being passed in.
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/auth0_current_user. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Auth0CurrentUser project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.