Giter VIP home page Giter VIP logo

jwt-bouncer's Introduction

JWT Compatible

JwtBouncer is an abstraction for JWT-based authentication/authorisation.

Usage

Parsing incoming requests

JwtBouncer includes a request parser which accepts a standard Rack request object and provides automated decoding and verification of the JWT.

You can then call various methods on this for authorisation. It's best demonstrated through an example:

require 'jwt_bouncer/request'

r = JwtBouncer::Request.new(request)

# is the token valid
r.authenticated?

# checks whether permissions has this key and it's truthy
r.can?(:update_product)

# who is authenticated, returns a hash of data
r.actor

# access the raw permissions hash
r.permissions

Signing outbound requests

JwtBouncer isn't currently designed to provide extensive JWT signing, however it does provide a small service object for signing outbound requests. This can be useful for test suites where you may want to fake a JWT signed request.

require 'jwt_bouncer/sign_request'

# assuming you're using rspec-mocks here, but this could be a real request
request = double(:request, headers: {})

# some data to pass in
shared_secret = 'leeroy'
permissions = { update_product: true }
actor = { type: 'user', id: 1, name: 'Jenkins' }

# expiry is optional
expiry = Time.now.to_i + 60

# sign the request
JwtBouncer::SignRequest.call request, shared_secret: shared_secret,
                                      permissions: permissions,
                                      actor: actor,
                                      expiry: expiry

# the request will now have the token in the header
request.headers['Authorization'] # => "Bearer ..."

Contributing

Read the development documentation to understand how to work on the library locally.

We welcome pull requests.

jwt-bouncer's People

Contributors

praweb avatar ryantownsend avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

praweb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.