Last active
September 29, 2017 11:20
-
-
Save jakubriedl/1de31bc6c438fa65842c92b6aa2b753a to your computer and use it in GitHub Desktop.
JWT oidc tokens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simplified version how we inject JWT AccessToken into panva/oidc-provider | |
const provider = new Provider(...) | |
function getTokenData () { | |
const authorization = _.get(this, 'claims._authorization', {}) | |
return { | |
...authorization, | |
...(_.omit(this, ['claims'])) | |
} | |
} | |
function save () { | |
const expiresIn = this.expiresIn || this.constructor.expiresIn | |
const data = this.getTokenData() | |
const tokenValue = JWT.sign(data, jwtSecret, { | |
expiresIn, | |
issuer: provider.issuer, | |
}) | |
provider.emit('token.issued', this) | |
return tokenValue | |
} | |
function find (tokenValue, options = {}) { | |
try { | |
return JWT.verify(tokenValue, jwtSecret, options) | |
} catch (err) { | |
throw new InvalidTokenError() | |
} | |
} | |
function bind (token) { | |
provider[token].prototype.find = find | |
provider[token].prototype.save = save | |
provider[token].prototype.getTokenData = getTokenData | |
return { bind } | |
} | |
bind('AccessToken').bind('ClientCredentials') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment