0.1.6 • Published 9 years ago

jwt-express-auth v0.1.6

Weekly downloads
24
License
-
Repository
-
Last release
9 years ago

JWT User Authorization Middleware

Add the following to any params that require authorization. The tokenParam must match the name of the user_id in the jwt, not the route param.

    var auth = require('jwt-express-auth');
    router.param('user_id', auth({secret:'secret', tokenParam:'id'}));

To generate a jwt token in Ruby.

    require 'jwt'
    JWT.encode({"id" => 1}, "secret")
    => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCciOjg5fQ.wUlU3JFv-wQYPfa9NRwh06wJWcOtYErRN23iTvMPTIE"

Examples using curl

    curl -X GET -H "Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCciOjg5fQ.wUlU3JFv-wQYPfa9NRwh06wJWcOtYErRN23iTvMPTIE" -H "Cache-Control:no-cache" http://localhost:2014/users/1

Or

    curl -X GET http://localhost:2014/users/1&authorization=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCciOjg5fQ.wUlU3JFv-wQYPfa9NRwh06wJWcOtYErRN23iTvMPTIE

From jquery

$.ajax({
    url: 'http://localhost:2014/users/1',
    headers: {
        'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCciOjg5fQ.wUlU3JFv-wQYPfa9NRwh06wJWcOtYErRN23iTvMPTIE',
        'Cache-Control': 'no-cache'
    }
}).done(function(res) { console.log(res) })

Or

$.get({
    url: 'http://localhost:2014/users/1?authorization=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCciOjg5fQ.wUlU3JFv-wQYPfa9NRwh06wJWcOtYErRN23iTvMPTIE'
}).done(function(res) { console.log(res) })
0.1.6

9 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago