Project

faye-jwt

0.0
No commit activity in last 3 years
No release in over 3 years
A gem that provides authentication by JWT(json web token) with faye.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

>= 0
 Project Readme

faye-jwt

Build Status Coverage Status

A gem that provides authentication by JWT(json web token) with faye.

Installation

Add this line to your application's Gemfile:

gem 'faye-jwt'

And then execute:

$ bundle

Or install it yourself as:

$ gem install faye-jwt

Usage

faye-jwt will authenicate all requests by access token. If the access token can not be decoded, it will fail to authenicate.

Server

For faye-rails, set up faye server in you initializers config, eg. initializers/faye.rb

Rails.application.config.middleware.use FayeRails::Middleware do
  add_extension(FayeJwt::Server.new('YOUR SECRET'))
  # others...
end

You can use jwt to generate access token and export it.

access_token = JWT.encode({:maybe => :userinfo}, 'YOUR SECRET')

Payload and Header

You can implement your custom server extension. You will get the decoded payload and header if you add your extension after faye-jwt.

class MyServer
  def incoming(message, callback)
    message['jwt']['payload'] # {"maybe" => "userinfo"}
    message['jwt']['header'] # eg. {"typ"=>"JWT", "alg"=>"HS256"}
    callback.call(message)
  end
end

And modify config

Rails.application.config.middleware.use FayeRails::Middleware do
  add_extension(FayeJwt::Server.new('YOUR SECRET'))
  add_extension(MyServer.new)
  # others...
end

JavaScript Client

Require javascripts

//= require faye
//= require faye-jwt

Add extension

var client = new Faye.Client('/faye'); // Your faye path
client.addExtension(new FayeJWT.Client(access_token));

Ruby Client

client = Faye::Client.new('http://localhost:3000/faye')
client.add_extension(FayeJwt::Client.new(access_token))

License

The gem is available as open source under the terms of the MIT License.

Contact

The project's website is located at https://github.com/emn178/faye-jwt
Author: Chen, Yi-Cyuan (emn178@gmail.com)