Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

api docs: Add documentation for JWT API key fetch endpoint.

Dhruv Shetty3ec23e68c34c
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index ea0af096057..47458a56526 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -3033,8 +3033,9 @@ No changes; feature level used for Zulip 7.0 release.
**Feature level 160**
-* `POST /api/v1/jwt/fetch_api_key`: Added new endpoint to fetch API
- keys using JSON Web Token (JWT) authentication.
+* [`POST /api/v1/jwt/fetch_api_key`](/api/jwt-fetch-api-key): Added
+ new endpoint to fetch API keys using JSON Web Token (JWT)
+ authentication.
* `accounts/login/jwt/`: Adjusted format of requests to undocumented,
optional endpoint for JWT authentication log in support.
diff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.md
index 56d75a80829..50c447a542b 100644
--- a/api_docs/include/rest-endpoints.md
+++ b/api_docs/include/rest-endpoints.md
@@ -163,6 +163,7 @@
* [Fetch an API key (production)](/api/fetch-api-key)
* [Fetch an API key (development only)](/api/dev-fetch-api-key)
+* [Fetch an API key (JWT)](/api/jwt-fetch-api-key)
* [Register a logged-in device](/api/register-client-device)
* [Remove a registered device](/api/remove-client-device)
* [Send an E2EE test notification to mobile device(s)](/api/e2ee-test-notify)
diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py
index 5668bd5f53c..c592fac203b 100644
--- a/zerver/openapi/markdown_extension.py
+++ b/zerver/openapi/markdown_extension.py
@@ -275,7 +275,11 @@ def generate_curl_example(
operation_entry = openapi_spec.openapi()["paths"][endpoint][method.lower()]
global_security = openapi_spec.openapi()["security"]
- insecure_operations = ["/dev_fetch_api_key:post", "/fetch_api_key:post"]
+ insecure_operations = [
+ "/dev_fetch_api_key:post",
+ "/fetch_api_key:post",
+ "/jwt/fetch_api_key:post",
+ ]
lines = []
if operation in insecure_operations:
lines.append("```curl")
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py
index 14d3cd08f39..6909b51ea76 100644
--- a/zerver/openapi/test_curl_examples.py
+++ b/zerver/openapi/test_curl_examples.py
@@ -25,6 +25,8 @@ from zerver.openapi.curl_param_value_generators import (
from zerver.openapi.openapi import get_endpoint_from_operationid
UNTESTED_GENERATED_CURL_EXAMPLES = {
+ # Requires organization-specific JWT_AUTH_KEYS configuration.
+ "jwt-fetch-api-key",
# Would need push notification bouncer set up to test the
# generated curl example for the following three endpoints.
"e2ee-test-notify",
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index c6ac087ac31..d23c44950e9 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -104,6 +104,114 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ApiKeyResponse"
+ /jwt/fetch_api_key:
+ post:
+ operationId: jwt-fetch-api-key
+ summary: Fetch an API key (JWT)
+ tags: ["authentication"]
+ description: |
+ This API endpoint is used by clients to implement JSON Web Token
+ (JWT) authentication. Given a JWT identifying a Zulip user, it
+ returns a Zulip API key that the client can use to make requests
+ as the user.
+
+ !!! warn ""
+
+ **Note:** This endpoint is only useful for Zulip servers/organizations
+ with [JSON web token authentication][prod-jwt-auth] enabled.
+
+ See the [API keys](/api/api-keys) documentation for more details
+ on how to manage API keys manually.
+
+ **Changes**: New in Zulip 7.0 (feature level 160).
+
+ [prod-jwt-auth]: https://zulip.readthedocs.io/en/latest/production/authentication-methods.html#json-web-tokens-jwt
+ requestBody:
+ required: true
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ type: object
+ properties:
+ token:
+ description: |
+ A JSON Web Token for the target user.
+
+ The token payload must contain a custom `email` claim with the target
+ user's email address, e.g., `{"email": "<target user email>"}`.
+ type: string
+ example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImhhbWxldEB6dWxpcC5jb20ifQ.EsHxSVt54zPR-ywgPH54TB1FYmrGKsfq7hsQEhp_9w0"
+ include_profile:
+ type: boolean
+ default: false
+ example: false
+ description: |
+ Whether to include a `user` object containing the target
+ user's profile details in the response.
+ required:
+ - token
+ security: []
+ responses:
+ "200":
+ description: Success.
+ content:
+ application/json:
+ schema:
+ allOf:
+ - $ref: "#/components/schemas/JsonSuccessBase"
+ - required:
+ - api_key
+ - email
+ additionalProperties: false
+ properties:
+ result: {}
+ msg: {}
+ ignored_parameters_unsupported: {}
+ api_key:
+ type: string
+ description: |
+ The API key that can be used to authenticate as the requested user.
+ email:
+ type: string
+ description: |
+ The email address of the user who owns the API key.
+ user:
+ description: |
+ Only present if `include_profile` parameter was set to `true`.
+
+ A dictionary with data on the target user.
+ allOf:
+ - $ref: "#/components/schemas/UserBase"
+ - additionalProperties: false
+ properties:
+ user_id: {}
+ delivery_email:
+ nullable: true
+ email: {}
+ full_name: {}
+ date_joined: {}
+ is_active: {}
+ is_owner: {}
+ is_admin: {}
+ is_guest: {}
+ is_bot: {}
+ bot_type:
+ nullable: true
+ bot_owner_id:
+ nullable: true
+ role: {}
+ timezone: {}
+ avatar_url:
+ nullable: true
+ avatar_version: {}
+ is_imported_stub: {}
+ example:
+ {
+ "api_key": "gjA04ZYcqXKalvYMA8OeXSfzUOLrtbZv",
+ "email": "[email protected]",
+ "msg": "",
+ "result": "success",
+ }
/dev_fetch_api_key:
post:
operationId: dev-fetch-api-key
diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py
index 27356a0f6c2..ab66c059dc1 100644
--- a/zerver/tests/test_openapi.py
+++ b/zerver/tests/test_openapi.py
@@ -255,7 +255,6 @@ class OpenAPIArgumentsTest(ZulipTestCase):
"/rest-error-handling",
# Zulip outgoing webhook payload
"/zulip-outgoing-webhook",
- "/jwt/fetch_api_key",
#### Bouncer endpoints
# Higher priority to document
"/remotes/push/e2ee/notify",
@@ -274,6 +273,7 @@ class OpenAPIArgumentsTest(ZulipTestCase):
documented_post_only_endpoints = {
"fetch_api_key",
"dev_fetch_api_key",
+ "jwt/fetch_api_key",
}
# Endpoints where the documentation is currently failing our