Skip to content

Commit

Permalink
Added isRevoked type definitions
Browse files Browse the repository at this point in the history
Replaced 2 spaces to 4
  • Loading branch information
ivan.zubok committed Mar 14, 2018
1 parent dbf1dc5 commit 27344cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions lib/get-secret.js
@@ -1,12 +1,11 @@
const { decode } = require('jsonwebtoken');

module.exports = async (provider, token) => {
const decoded = decode(token, { complete: true });

const decoded = decode(token, { complete: true });
if (!decoded || !decoded.header) {
throw new Error('Invalid token');
}

if (!decoded || !decoded.header) {
throw new Error('Invalid token');
}

return provider(decoded.header, decoded.payload);
return provider(decoded.header, decoded.payload);
};
10 changes: 5 additions & 5 deletions lib/index.js
@@ -1,13 +1,13 @@
'use strict';

const unless = require('koa-unless');
const verify = require('./verify');
const getSecret = require('./get-secret');
const resolveAuthHeader = require('./resolvers/auth-header');
const resolveCookies = require('./resolvers/cookie');

module.exports = (opts = {}) => {

const { debug, getToken, isRevoked, key='user', passthrough, tokenKey } = opts;
const { debug, getToken, isRevoked, key = 'user', passthrough, tokenKey } = opts;
const tokenResolvers = [resolveCookies, resolveAuthHeader];

if (getToken && typeof getToken === 'function') {
Expand All @@ -25,8 +25,8 @@ module.exports = (opts = {}) => {
let { state: { secret = opts.secret } } = ctx;

try {
if(typeof secret === 'function') {
secret = await getSecret(secret, token);
if (typeof secret === 'function') {
secret = await getSecret(secret, token);
}

if (!secret) {
Expand All @@ -50,7 +50,7 @@ module.exports = (opts = {}) => {
} catch (e) {
if (!passthrough) {
const msg = debug ? e.message : 'Authentication Error';
ctx.throw(401, msg, {originalError: e});
ctx.throw(401, msg, { originalError: e });
}
}

Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Expand Up @@ -3,7 +3,7 @@
// Definitions by: Bruno Krebs <https://github.com/brunokrebs/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import Koa = require("koa");
import Koa = require('koa');

export = jwt;

Expand All @@ -14,6 +14,7 @@ declare namespace jwt {
secret: string | Buffer;
key?: string;
getToken?(opts: jwt.Options): string;
isRevoked?(ctx: Koa.Context, decodedToken: object, token: string): Promise<boolean>;
passthrough?: boolean;
cookie?: string;
debug?: boolean;
Expand Down

0 comments on commit 27344cc

Please sign in to comment.