1
1
var jws = require ( 'jws' ) ;
2
2
3
- var JsonWebTokenError = module . exports . JsonWebTokenError = require ( './lib/JsonWebTokenError' ) ;
4
- var TokenExpiredError = module . exports . TokenExpiredError = require ( './lib/TokenExpiredError' ) ;
3
+ var JWT = module . exports ;
5
4
6
- module . exports . decode = function ( jwt , options ) {
5
+ var JsonWebTokenError = JWT . JsonWebTokenError = require ( './lib/JsonWebTokenError' ) ;
6
+ var TokenExpiredError = JWT . TokenExpiredError = require ( './lib/TokenExpiredError' ) ;
7
+
8
+
9
+ JWT . decode = function ( jwt , options ) {
7
10
options = options || { } ;
8
11
var decoded = jws . decode ( jwt , options ) ;
9
12
if ( ! decoded ) { return null ; }
@@ -18,7 +21,7 @@ module.exports.decode = function (jwt, options) {
18
21
}
19
22
} catch ( e ) { }
20
23
}
21
-
24
+
22
25
//return header if `complete` option is enabled. header includes claims
23
26
//such as `kid` and `alg` used to select the key within a JWKS needed to
24
27
//verify the signature
@@ -32,7 +35,7 @@ module.exports.decode = function (jwt, options) {
32
35
return payload ;
33
36
} ;
34
37
35
- module . exports . sign = function ( payload , secretOrPrivateKey , options ) {
38
+ JWT . sign = function ( payload , secretOrPrivateKey , options ) {
36
39
options = options || { } ;
37
40
38
41
var header = ( ( typeof options . headers === 'object' ) && options . headers ) || { } ;
@@ -81,7 +84,7 @@ module.exports.sign = function(payload, secretOrPrivateKey, options) {
81
84
return signed ;
82
85
} ;
83
86
84
- module . exports . verify = function ( jwtString , secretOrPublicKey , options , callback ) {
87
+ JWT . verify = function ( jwtString , secretOrPublicKey , options , callback ) {
85
88
if ( ( typeof options === 'function' ) && ! callback ) {
86
89
callback = options ;
87
90
options = { } ;
@@ -160,7 +163,7 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
160
163
var payload ;
161
164
162
165
try {
163
- payload = module . exports . decode ( jwtString ) ;
166
+ payload = JWT . decode ( jwtString ) ;
164
167
} catch ( err ) {
165
168
return done ( err ) ;
166
169
}
0 commit comments