Hensin Belt on Grape API
Hensin Belt is a Grape middleware to connect your API resources with your API authenticator.
Installation
Add this line to your application's Gemfile:
gem 'henshin-belt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install henshin-belt
Usage
Install generator
On your first install, run this generator :
rails g henshin_belt:install
Usage with Grape
You will need to use the middleware in your main API :
use ::HensinBelt::Oauth2
You could also use the helpers :
helpers ::HensinBelt::Helpers
Protecting your endpoint
In your endpoint you need to define which protected endpoint by adding this DSL :
oauth2
oauth2(:email)
Example :
desc "Your protected endpoint"
oauth2
get :protected do
end
desc "Your protected endpoint with defined scope"
oauth2(:email)
get :protected do
end
Nice feature
From your protected endpoint you could get :
resource_token
=> Your access tokenresource_credential
=> Full credentialsresource_owner
=> Current Objectme
=> Current Object