README.md in grape-jwt-authentication-1.0.1 vs README.md in grape-jwt-authentication-1.1.0

- old
+ new

@@ -1,20 +1,22 @@ ![grape-jwt-authentication](doc/assets/project.png) -[![Build Status](https://api.travis-ci.org/hausgold/grape-jwt-authentication.svg)](https://travis-ci.org/hausgold/grape-jwt-authentication) +[![Build Status](https://travis-ci.org/hausgold/grape-jwt-authentication.svg?branch=master)](https://travis-ci.org/hausgold/grape-jwt-authentication) [![Gem Version](https://badge.fury.io/rb/grape-jwt-authentication.svg)](https://badge.fury.io/rb/grape-jwt-authentication) [![Maintainability](https://api.codeclimate.com/v1/badges/446f3eff18bebff9c174/maintainability)](https://codeclimate.com/github/hausgold/grape-jwt-authentication/maintainability) -[![Test Coverage](https://codeclimate.com/github/hausgold/grape-jwt-authentication/badges/coverage.svg)](https://codeclimate.com/github/hausgold/grape-jwt-authentication/coverage) +[![Test Coverage](https://api.codeclimate.com/v1/badges/446f3eff18bebff9c174/test_coverage)](https://codeclimate.com/github/hausgold/grape-jwt-authentication/test_coverage) +[![API docs](https://img.shields.io/badge/docs-API-blue.svg)](https://www.rubydoc.info/gems/grape-jwt-authentication) This gem is dedicated to easily integrate a JWT authentication to your [Grape](https://github.com/ruby-grape/grape) API. The real authentication functionality must be provided by the user and this makes this gem highy flexible on the JWT verification level. - [Installation](#installation) - [Usage](#usage) - [Grape API](#grape-api) + - [Helpers](#helpers) - [Configuration](#configuration) - [Authenticator](#authenticator) - [Malformed token handling](#malformed-token-handling) - [Failed authentication handling](#failed-authentication-handling) - [RSA public key helper](#rsa-public-key-helper) @@ -70,10 +72,46 @@ auth :jwt end end ``` +#### Helpers + +The inclusion of the `Grape::Jwt::Authentication` inserts some helpers to +access the parsed and original JWT. This can be handy when you need to work +with the JWT payload or perform some extra calculations with the expiration +date of it. The following example demonstrated the usage of the helpers. + +```ruby +module UserApi + class ApiV1 < Grape::API + # All your fancy Grape API stuff [..] + version 'v1', using: :path + + resource :payload do + desc 'A JWT payload echo service.' + get do + # The parsed JWT which has an accessible payload (RecursiveOpenStruct) + { payload: request_jwt.payload.to_h } + end + end + + resource :token do + desc 'A JWT echo service.' + get do + # The original JWT parsed from the HTTP authorization header + { token: original_request_jwt } + end + end + + # Enable JWT authentication on this API + include Grape::Jwt::Authentication + auth :jwt + end +end +``` + ### Configuration This gem is quite customizable and flexible to fulfill your needs. You can make use of some parts and leave other if you do not care about them. We are not going to force the way how to verify JWT or work with them. Here comes a @@ -374,11 +412,11 @@ ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run -`rake spec` to run the tests. You can also run `bin/console` for an interactive -prompt that will allow you to experiment. +`bundle exec rake spec` to run the tests. 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