Any option supported by the get-jwks library can be specified in the jwt.jwks object.
namespace
The JWT namespace option is used to specify the namespace for custom claims used to populate request.user. For more info about this see OIDC Specification.
Since these namespace are URLs, we might want to remove it. If the namespace is specified it will be removed automatically:
In this case, if the token contains a claim https://test.com/email, the plugin will strip the namespace from the claim and populate request.user.email with its value.
Webhook
The plugin can also populate request.user from a webhook.
When a request is received, fastify-user sends a POST to the webhook, replicating the same body and headers, except for:
host
connection
The webhook is expected to return a JSON object with the user information. The plugin will populate request.user with the response body.
In case both jwt and webhook options are specified, the plugin will try to populate request.user from the JWT token first. If the token is not valid, it will try to populate request.user from the webhook.
Custom auth strategies
In case if you want to use your own auth strategy, you can pass it as an option to the plugin. All custom auth strategies should have createSession method, which will be called on every request. This method should set request.user object. All custom strategies will be executed after jwt and webhook strategies.