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 middleware
use ::HensinBelt::Oauth2
You could also use the helpers :
# use 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
# your code goes here
end
desc "Your protected endpoint with defined scope"
oauth2(:email)
get :protected do
# your code goes here
end
Nice feature
From your protected endpoint you could get :
-
resource_token
=> Your access token -
resource_credential
=> Full credentials -
resource_owner
=> Current Object -
me
=> Current Object