From 7c4175958c531ffbe65295ba111e5f0eebe7974b Mon Sep 17 00:00:00 2001
From: DMRobertson initial_device_display_name
) which can be included in the above request.
The JSON Web Token integration in Synapse uses the
-PyJWT
library, which must be installed
+Authlib
library, which must be installed
as follows:
matrix.org
so no further action is needed.
If you installed Synapse into a virtualenv, run /path/to/env/bin/pip install synapse[pyjwt]
to install the necessary dependencies.
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 an jwt_config
section
+
To enable the JSON web token integration, you should then add a jwt_config
section
to your configuration file (or uncomment the enabled: true
line in the
existing section). See sample_config.yaml for some
sample settings.
Although JSON Web Tokens are typically generated from an external server, the -examples below use PyJWT directly.
+example below uses a locally generated JWT.Configure Synapse with JWT logins, note that this example uses a pre-shared @@ -211,8 +211,17 @@ secret and an algorithm of HS256:
Generate a JSON web token:
-$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
-eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
+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.
+from authlib.jose import jwt
+
+header = {"alg": "HS256"}
+payload = {"sub": "user1", "aud": ["audience"]}
+secret = "my-secret-token"
+result = jwt.encode(header, payload, secret)
+print(result.decode("ascii"))