Skip to content

Commit

Permalink
Fixed merge conflicts; Added new contributor
Browse files Browse the repository at this point in the history
  • Loading branch information
stiang committed Dec 8, 2014
2 parents 8128566 + aa9b318 commit 96b71fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Koa middleware that validates JSON Web Tokens and sets `ctx.state.user`
(by default) if a valid token is provided.

This module lets you authenticate HTTP requests using JSON Web Tokens
This module lets you authenticate HTTP requests using JSON Web Tokens
in your [Koa](http://koajs.com/) (node.js) applications.

See [this article](http://blog.auth0.com/2014/01/07/angularjs-authentication-with-cookies-vs-token/)
See [this article](http://blog.auth0.com/2014/01/07/angularjs-authentication-with-cookies-vs-token/)
for a good introduction.

## Install
Expand All @@ -16,9 +16,9 @@ for a good introduction.
## Usage

The JWT authentication middleware authenticates callers using a JWT
token. If the token is valid, `ctx.state.user` (by default) will be set
with the JSON object decoded to be used by later middleware for
authorization and access control.
token. If the token is valid, `ctx.user` (by default) will be set
with the JSON object decoded to be used by later middleware for
authorization and access control.

## Example

Expand Down Expand Up @@ -66,7 +66,7 @@ app.listen(3000);


Alternatively, you can add the `passthrough` option to always yield next,
even if no valid Authorization header was found:
even if no valid Authorization header was found:
```js
app.use(jwt({ secret: 'shared-secret', passthrough: true }));
```
Expand All @@ -88,7 +88,7 @@ app.use(jwt({ secret: 'shared-secret',
If the JWT has an expiration (`exp`), it will be checked.


This module also support tokens signed with public/private key pairs. Instead
This module also support tokens signed with public/private key pairs. Instead
of a secret, you can specify a Buffer with the public key:
```js
var publicKey = fs.readFileSync('/path/to/public.pub');
Expand All @@ -97,7 +97,7 @@ app.use(jwt({ secret: publicKey }));

## Related Modules

- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) — JSON Web Token signing
- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) — JSON Web Token signing
and verification

Note that koa-jwt exports the `sign`, `verify` and `decode` functions from the above module as a convenience.
Expand All @@ -124,6 +124,7 @@ This code is largely based on [express-jwt](https://github.com/auth0/express-jwt
- [soygul] (https://github.com/soygul)
- [tunnckoCore] (https://github.com/tunnckoCore)
- [getuliojr] (https://github.com/getuliojr)
- [cesarandreu] (https://github.com/cesarandreu)

## License

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(opts) {
if (parts.length == 2) {
scheme = parts[0];
credentials = parts[1];

if (/^Bearer$/i.test(scheme)) {
token = credentials;
}
Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('failure tests', function () {
it('should throw if authorization header is not valid jwt', function(done) {
var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar'}, secret);

var app = koa();

app.use(koajwt({ secret: 'different-shhhh', debug: true }));
Expand All @@ -69,7 +69,7 @@ describe('failure tests', function () {
it('should throw if audience is not expected', function(done) {
var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar', aud: 'expected-audience'}, secret);

var app = koa();

app.use(koajwt({ secret: 'shhhhhh', audience: 'not-expected-audience', debug: true }));
Expand All @@ -84,7 +84,7 @@ describe('failure tests', function () {
it('should throw if token is expired', function(done) {
var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar', exp: 1382412921 }, secret);

var app = koa();

app.use(koajwt({ secret: 'shhhhhh', debug: true }));
Expand All @@ -99,7 +99,7 @@ describe('failure tests', function () {
it('should throw if token issuer is wrong', function(done) {
var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar', iss: 'http://foo' }, secret);

var app = koa();

app.use(koajwt({ secret: 'shhhhhh', issuer: 'http://wrong', debug: true }));
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('success tests', function () {

var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar'}, secret);

var app = koa();

app.use(koajwt({ secret: secret }));
Expand All @@ -165,7 +165,7 @@ describe('success tests', function () {

var secret = 'shhhhhh';
var token = koajwt.sign({foo: 'bar'}, secret);

var app = koa();

app.use(koajwt({ secret: secret, key: 'jwtdata' }));
Expand Down

0 comments on commit 96b71fb

Please sign in to comment.