GrapeDeviseTokenAuth
GrapeDeviseTokenAuth gem is a compatability layer between
devise_token_auth and grape. It is useful when mounting a grape API
in a rails application where devise (or devise_token_auth + devise)
is already present. It is reliant on devise_token_auth and devise,
therefore it is not suitable for grape where these are not present.
The majority of the hard work and credit goes to Lyann Dylan Hurley and his fantistic devise_token_auth gem. I merely have ported this to work well with grape.
Installation
Add this line to your application's Gemfile:
gem 'grape_devise_token_auth'
And then execute:
$ bundle
Or install it yourself as:
$ gem install grape_devise_token_auth
Usage
Place this line in an initializer in your rails app or at least somewhere before the grape API will get loaded:
GrapeDeviseTokenAuth.setup!(true)
Within the Grape API:
class Posts < Grape::API
auth :grape_devise_token_auth, resource_class: :user
helpers GrapeDeviseTokenAuth::AuthHelpers
# ...
end
including the helpers line allows you to use methods the current_user and
authenticated? within the API.
The resource class option allows you to specific the scope that will be authenticated, this corresponds to your devise mapping.
All calls will now be authenticated in the above API via rack middleware.
Testing and Example
Currently I am using this repo to test this gem, eventually I plan on
migrating the tests into the grape_devise_token_auth repo. For now though, I
refer you to that repo for how to integrate with an existing devise and
devise_token_auth repo.
Development
After checking out the repo, run bin/setup to install dependencies. Then, 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 to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
- Fork it ( https://github.com/[my-github-username]/grape_devise_token_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