auth: Add JWT-based user API key fetch.

This adds a new endpoint /jwt/fetch_api_key that accepts a JWT and can
be used to fetch API keys for a certain user. The target realm is
inferred from the request and the user email is part of the JWT.

A JSON containing an user API key, delivery email and (optionally)
raw user profile data is returned in response.
The profile data in the response is optional and can be retrieved by
setting the POST param "include_profile" to "true" (default=false).

Co-authored-by: Mateusz Mandera <mateusz.mandera@zulip.com>
This commit is contained in:
Alessandro Toppi
2022-09-13 17:39:18 +02:00
committed by Tim Abbott
parent 7c7ca61e9f
commit ff89590558
8 changed files with 267 additions and 4 deletions

View File

@@ -534,6 +534,27 @@ SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
## "example.com"), otherwise leave this as None.
# SSO_APPEND_DOMAIN = None
## JWT authentication.
##
## JWT authentication is supported both to transparently log users
## into Zulip or to fetch users' API keys. The JWT secret key and
## algorithm must be configured here.
##
## See https://zulip.readthedocs.io/en/latest/production/authentication-methods.html#jwt
# JWT_AUTH_KEYS: Dict[str, Any] = {
# # Subdomain for which this JWT configuration will apply.
# "zulip": {
# # Shared secret key used to validate jwt tokens, which should be stored
# # in zulip-secrets.conf and is read by the get_secret call below.
# # The key needs to be securely, randomly generated. Note that if you're
# # using the default HS256 algorithm, per RFC 7518, the key needs
# # to have at least 256 bits of entropy.
# "key": get_secret("jwt_auth_key"),
# # Algorithm with which the JWT token are signed.
# "algorithms": ["HS256"],
# }
# }
################
## Service configuration