-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,15 +38,33 @@ JWT.decode = function (jwt, options) { | |
return payload; | ||
}; | ||
|
||
var payload_options = [ | ||
'expiresIn', | ||
'notBefore', | ||
'expiresInMinutes', | ||
'expiresInSeconds', | ||
'audience', | ||
'issuer', | ||
'subject', | ||
'jwtid' | ||
]; | ||
|
||
JWT.sign = function(payload, secretOrPrivateKey, options, callback) { | ||
options = options || {}; | ||
payload = typeof payload === 'object' ? xtend(payload) : payload; | ||
var header = {}; | ||
|
||
if (typeof payload === 'object') { | ||
header.typ = 'JWT'; | ||
payload = xtend(payload); | ||
} else { | ||
var invalid_option = payload_options.filter(function (key) { | ||
return typeof options[key] !== 'undefined'; | ||
})[0]; | ||
|
||
console.warn('invalid "' + invalid_option + '" option for ' + (typeof payload) + ' payload'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
carlnordenfelt
|
||
} | ||
|
||
|
||
header.alg = options.algorithm || 'HS256'; | ||
|
||
if (options.headers) { | ||
|
This has been causing some confusion for my team and it took a bit of troubleshooting to find that the problem was not actually a problem.
It outputs the console.warn even if there are no options (or only undefined options) specified.
A nice improvement to this would be: