-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: draft implementation of IETF JWT Access Token profile
- Loading branch information
Showing
20 changed files
with
621 additions
and
85 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,46 @@ | ||
const { strict: assert } = require('assert'); | ||
|
||
const JWT = require('../../helpers/jwt'); | ||
const instance = require('../../helpers/weak_cache'); | ||
const ctxRef = require('../ctx_ref'); | ||
|
||
const jwt = require('./jwt'); | ||
const opaque = require('./opaque'); | ||
const paseto = require('./paseto'); | ||
|
||
const JWT_REGEX = /^(?:[a-zA-Z0-9-_]+\.){2}[a-zA-Z0-9-_]+$/; | ||
|
||
module.exports = (provider) => { | ||
const formats = { | ||
jwt: jwt(provider), | ||
opaque: opaque(provider), | ||
paseto: paseto(provider), | ||
}; | ||
|
||
return { | ||
generateTokenId(...args) { | ||
const resolver = instance(provider).dynamic[this.constructor.name]; | ||
const format = resolver(ctxRef.get(this), this); | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
this.format = format; | ||
return formats[format].generateTokenId.apply(this, args); | ||
}, | ||
async getValueAndPayload(...args) { | ||
const { format } = this; | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].getValueAndPayload.apply(this, args); | ||
}, | ||
getTokenId(...args) { | ||
let format; | ||
const [value] = args; | ||
if (value && (value.length === 27 || value.length === 43)) { | ||
format = 'opaque'; | ||
} else if (value.startsWith('v2.public.')) { | ||
format = 'paseto'; | ||
} else if (JWT_REGEX.test(value)) { | ||
format = 'jwt'; | ||
module.exports = (provider, formats) => ({ | ||
generateTokenId(...args) { | ||
const resolver = instance(provider).dynamic[this.constructor.name]; | ||
const format = resolver(ctxRef.get(this), this); | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
this.format = format; | ||
return formats[format].generateTokenId.apply(this, args); | ||
}, | ||
async getValueAndPayload(...args) { | ||
const { format } = this; | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].getValueAndPayload.apply(this, args); | ||
}, | ||
getTokenId(...args) { | ||
let format; | ||
const [value] = args; | ||
if (value && (value.length === 27 || value.length === 43)) { | ||
format = 'opaque'; | ||
} else if (value.startsWith('v2.public.')) { | ||
format = 'paseto'; | ||
} else if (JWT_REGEX.test(value)) { | ||
if (JWT.header(value).typ === 'at+jwt') { | ||
format = 'jwt-ietf'; | ||
} else { | ||
format = 'opaque'; | ||
format = 'jwt'; | ||
} | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].getTokenId.apply(this, args); | ||
}, | ||
async verify(...args) { | ||
const format = args[1].format || (args[1].jwt ? 'jwt' : args[1].paseto ? 'paseto' : 'opaque'); // eslint-disable-line no-nested-ternary | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].verify.apply(this, args); | ||
}, | ||
}; | ||
}; | ||
} else { | ||
format = 'opaque'; | ||
} | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].getTokenId.apply(this, args); | ||
}, | ||
async verify(...args) { | ||
const format = args[1].format || (args[1].jwt ? 'jwt' : args[1]['jwt-ietf'] ? 'jwt-ietf' : args[1].paseto ? 'paseto' : 'opaque'); // eslint-disable-line no-nested-ternary | ||
assert(formats[format] && format !== 'dynamic', 'invalid format resolved'); | ||
return formats[format].verify.apply(this, args); | ||
}, | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
const instance = require('../../helpers/weak_cache'); | ||
|
||
const opaque = require('./opaque'); | ||
const jwt = require('./jwt'); | ||
const jwtIetf = require('./jwt_ietf'); | ||
const paseto = require('./paseto'); | ||
const dynamic = require('./dynamic'); | ||
|
||
module.exports = { | ||
dynamic, | ||
jwt, | ||
paseto, | ||
opaque, | ||
module.exports = (provider) => { | ||
const result = { | ||
opaque: opaque(provider), // no dependencies | ||
}; | ||
|
||
result.jwt = jwt(provider, result); // depends on opaque | ||
result.paseto = paseto(provider, result); // depends on opaque | ||
|
||
if (instance(provider).configuration('features.ietfJWTAccessTokenProfile.enabled')) { | ||
result['jwt-ietf'] = jwtIetf(provider, result); // depends on opaque and jwt | ||
} | ||
|
||
result.dynamic = dynamic(provider, result); // depends on all | ||
|
||
return result; | ||
}; |
This file contains 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
Oops, something went wrong.