mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
Add a JWT-based LDAP/AD authenticator.
This commit is contained in:
parent
11ad1ffc38
commit
697e552ef0
6 changed files with 342 additions and 1 deletions
33
lib/util/jwtutil.js
Normal file
33
lib/util/jwtutil.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
var assert = require('assert')
|
||||
var jws = require('jws')
|
||||
|
||||
module.exports.encode = function(options) {
|
||||
assert.ok(options.payload, 'payload required')
|
||||
assert.ok(options.secret, 'secret required')
|
||||
|
||||
return jws.sign({
|
||||
header: {
|
||||
alg: 'HS256'
|
||||
, exp: Date.now() + 24 * 3600
|
||||
}
|
||||
, payload: options.payload
|
||||
, secret: options.secret
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.decode = function(payload, secret) {
|
||||
if (!jws.verify(payload, secret)) {
|
||||
return null
|
||||
}
|
||||
|
||||
var decoded = jws.decode(payload, {
|
||||
json: true
|
||||
})
|
||||
, exp = decoded.header.exp
|
||||
|
||||
if (exp && exp <= Date.now()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return decoded.payload
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue