From 7c4175958c531ffbe65295ba111e5f0eebe7974b Mon Sep 17 00:00:00 2001 From: DMRobertson Date: Wed, 15 Jun 2022 16:45:50 +0000 Subject: deploy: 7d99414edf2c5c7e602a88c72245add665e6afb4 --- develop/jwt.html | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'develop/jwt.html') diff --git a/develop/jwt.html b/develop/jwt.html index b7219d8202..ce47f9db88 100644 --- a/develop/jwt.html +++ b/develop/jwt.html @@ -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.4.1