From 51b1225fc79b9c24d202efb23a971bfb21540dac Mon Sep 17 00:00:00 2001 From: DMRobertson Date: Tue, 5 Jul 2022 12:25:53 +0000 Subject: deploy: b51a0f4be0287f88a747952fb3cc8132d29df4c8 --- latest/jwt.html | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'latest/jwt.html') diff --git a/latest/jwt.html b/latest/jwt.html index f249c039d6..3477978ca8 100644 --- a/latest/jwt.html +++ b/latest/jwt.html @@ -76,7 +76,7 @@ @@ -177,7 +177,7 @@ Providing the audience claim when not configured will cause validation to fail.< initial_device_display_name) which can be included in the above request.

Preparing Synapse

The JSON Web Token integration in Synapse uses the -PyJWT library, which must be installed +Authlib library, which must be installed as follows:

-

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.

How to test JWT as a developer

Although JSON Web Tokens are typically generated from an external server, the -examples below use PyJWT directly.

+example below uses a locally generated JWT.

  1. Configure Synapse with JWT logins, note that this example uses a pre-shared @@ -211,8 +211,17 @@ secret and an algorithm of HS256:

  2. 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"))
     
  3. -- cgit 1.5.1