features.registration
This content is for v8.x. Switch to the latest version for up-to-date documentation.
Dynamic Client Registration 1.0 and RFC7591 - OAuth 2.0 Dynamic Client Registration Protocol
Enables Dynamic Client Registration.
default value:
{ enabled: false, idFactory: [Function: idFactory], // see expanded details below initialAccessToken: false, issueRegistrationAccessToken: true, policies: undefined, secretFactory: [AsyncFunction: secretFactory] // see expanded details below}(Click to expand) features.registration options details
idFactory
Section titled “idFactory”Function used to generate random client identifiers during dynamic client registration
default value:
function idFactory(ctx) { return nanoid();}initialAccessToken
Section titled “initialAccessToken”Enables registration_endpoint to check a valid initial access token is provided as a bearer token during the registration call. Supported types are
stringthe string value will be checked as a static initial access tokenbooleantrue/false to enable/disable adapter backed initial access tokens
default value:
false(Click to expand) To add an adapter backed initial access token and retrive its value
new (provider.InitialAccessToken)({}).save().then(console.log);issueRegistrationAccessToken
Section titled “issueRegistrationAccessToken”Boolean or a function used to decide whether a registration access token will be issued or not. Supported values are
trueregistration access tokens is issuedfalseregistration access tokens is not issued- function returning true/false, true when token should be issued, false when it shouldn’t
default value:
true(Click to expand) To determine if a registration access token should be issued dynamically
// @param ctx - koa request contextasync issueRegistrationAccessToken(ctx) { return policyImplementation(ctx)}policies
Section titled “policies”define registration and registration management policies applied to client properties. Policies are sync/async functions that are assigned to an Initial Access Token that run before the regular client property validations are run. Multiple policies may be assigned to an Initial Access Token and by default the same policies will transfer over to the Registration Access Token. A policy may throw / reject and it may modify the properties object.
recommendation: referenced policies must always be present when encountered on a token, an AssertionError will be thrown inside the request context if it is not, resulting in a 500 Server Error.
recommendation: the same policies will be assigned to the Registration Access Token after a successful validation. If you wish to assign different policies to the Registration Access Token
// inside your final ran policyctx.oidc.entities.RegistrationAccessToken.policies = ['update-policy'];default value:
undefined(Click to expand) To define registration and registration management policies
To define policy functions configure features.registration to be an object like so:
{ enabled: true, initialAccessToken: true, // to enable adapter-backed initial access tokens policies: { 'my-policy': function (ctx, properties) { // @param ctx - koa request context // @param properties - the client properties which are about to be validated // example of setting a default if (!('client_name' in properties)) { properties.client_name = generateRandomClientName(); } // example of forcing a value properties.userinfo_signed_response_alg = 'RS256'; // example of throwing a validation error if (someCondition(ctx, properties)) { throw new errors.InvalidClientMetadata('validation error message'); } }, 'my-policy-2': async function (ctx, properties) {}, },}An Initial Access Token with those policies being executed (one by one in that order) is created like so
new (provider.InitialAccessToken)({ policies: ['my-policy', 'my-policy-2'] }).save().then(console.log);secretFactory
Section titled “secretFactory”Function used to generate random client secrets during dynamic client registration
default value:
async function secretFactory(ctx) { const bytes = Buffer.allocUnsafe(64); await randomFill(bytes); return base64url.encodeBuffer(bytes);}