This documentation site is for the versions of Synapse maintained by the Matrix.org Foundation (github.com/matrix-org/synapse), available under the Apache 2.0 licence.
Synapse comes with a non-standard login type to support
JSON Web Tokens. In general the
documentation for
the login endpoint
is still valid (and the mechanism works similarly to the
token based login).
To log in using a JSON Web Token, clients should submit a /login request as
follows:
The token field should include the JSON web token with the following claims:
A claim that encodes the local part of the user ID is required. By default,
the sub (subject) claim is used, or a custom claim can be set in the
configuration file.
The expiration time (exp), not before time (nbf), and issued at (iat)
claims are optional, but validated if present.
The issuer (iss) claim is optional, but required and validated if configured.
The audience (aud) claim is optional, but required and validated if configured.
Providing the audience claim when not configured will cause validation to fail.
In the case that the token is not valid, the homeserver must respond with
403 Forbidden and an error code of M_FORBIDDEN.
As with other login types, there are additional fields (e.g. device_id and
initial_device_display_name) which can be included in the above request.
The JSON Web Token integration in Synapse uses the
Authlib library, which must be installed
as follows:
The relevant libraries are included in the Docker images and Debian packages
provided by matrix.org so no further action is needed.
If you installed Synapse into a virtualenv, run /path/to/env/bin/pip install synapse[jwt] to install the necessary dependencies.
For other installation mechanisms, see the documentation provided by the
maintainer.
To enable the JSON web token integration, you should then add a jwt_config option
to your configuration file. See the configuration manual for some
sample settings.
You can use the following short Python snippet to generate a JWT
protected by an HMAC.
Take care that the secret and the algorithm given in the header match
the entries from jwt_config above.