The purpose of this repository is to replicate Issue 13 on Grape Swagger Rails (see: ruby-grape/grape-swagger-rails#13).
Unforunately, I ripped this from an existing project so there are more dependcies than I would like.
- Rails
- Devise
- Doorkeeper
- wine_bouncer (https://github.com/antek-drzewiecki/wine_bouncer)
- grape-swagger
- grape-swagger-rails
-
git clone https://github.com/whatasunnyday/gsr-api-key && cd gsr-api-key
-
rake db:setup
-- This will create a user with the email grape@swagger.com with the password helloworld. -
curl http://localhost:3000/api/hello
should return{"id":"unauthenticated","message":"Request failed because user is not authenticated."}
-
Next curl oauth endpoint for an access token:
curl -F grant_type=password \
-F username=grape@swagger.com \
-F password=helloworld \
-X POST http://localhost:3000/oauth/token
returns something like this (access token and created_at will be different)
{"access_token":"a7f7eeb0b70a444c3f755475537bbfd0be5bd49a6fe92bf135d518693372d4af","token_type":"bearer","expires_in":7200,"created_at":1439923237}
- To curl with the access token, do the following (replace with your access token):
curl -H "Authorization: Bearer a7f7eeb0b70a444c3f755475537bbfd0be5bd49a6fe92bf135d518693372d4af" \
-X GET http://localhost:3000/api/hello
Should return:
{"hello":"world"}
- We've now confirmed we having a working access token with a protected
end point. Run
bin/rails s
and navigate to http://localhost:3000/swagger. Add the access token from above in api_key field. Click explore. Click hello. The api end point will drop down. Click get and then Try it out! The response will say you are not authenticated.