Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api_docs: Document the /fetch-api-key endpoint.
shanukunbe3967202618
diff --git a/templates/zerver/api/dev-fetch-api-key.md b/templates/zerver/api/dev-fetch-api-key.mdindex 61ec78fc752..400d8101d13 100644--- a/templates/zerver/api/dev-fetch-api-key.md+++ b/templates/zerver/api/dev-fetch-api-key.md@@ -1,4 +1,4 @@-# Fetch a development API key+# Fetch an API key (development only){generate_api_description(/dev_fetch_api_key:post)}diff --git a/templates/zerver/api/fetch-api-key.md b/templates/zerver/api/fetch-api-key.mdnew file mode 100644index 00000000000..8580725a53a--- /dev/null+++ b/templates/zerver/api/fetch-api-key.md@@ -0,0 +1,28 @@+# Fetch an API key (production)++{generate_api_description(/fetch_api_key:post)}++## Usage examples++{start_tabs}+{tab|curl}++{generate_code_example(curl)|/fetch_api_key:post|example}++{end_tabs}++## Parameters++{generate_api_arguments_table|zulip.yaml|/fetch_api_key:post}++## Response++### Return values++{generate_return_values_table|zulip.yaml|/fetch_api_key:post}++### Example response++A typical successful JSON response may look like:++{generate_code_example|/fetch_api_key:post|fixture(200)}diff --git a/templates/zerver/help/include/rest-endpoints.md b/templates/zerver/help/include/rest-endpoints.mdindex 9c597f85f1f..87b069f2609 100644--- a/templates/zerver/help/include/rest-endpoints.md+++ b/templates/zerver/help/include/rest-endpoints.md@@ -69,4 +69,6 @@* [Delete an event queue](/api/delete-queue)#### Specialty endpoints-* [Fetch a development API key](/api/dev-fetch-api-key)++* [Fetch an API key (production)](/api/fetch-api-key)+* [Fetch an API key (development only)](/api/dev-fetch-api-key)diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.pyindex 4550433e7d7..421ce4faa3d 100644--- a/zerver/openapi/curl_param_value_generators.py+++ b/zerver/openapi/curl_param_value_generators.py@@ -18,6 +18,7 @@ from zerver.lib.actions import (update_user_presence,)from zerver.lib.events import do_events_register+from zerver.lib.initial_password import initial_passwordfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.models import Client, Message, UserGroup, UserPresence, get_realm@@ -73,6 +74,16 @@ def patch_openapi_example_values(property["example"] = realm_example_values[key]return params, request_body+@openapi_param_value_generator(["/fetch_api_key:post"])+def fetch_api_key() -> Dict[str, object]:+ email = helpers.example_email("iago")+ password = initial_password(email)++ return {+ "username": email,+ "password": password,+ }+@openapi_param_value_generator(["/messages/{message_id}:get", "/messages/{message_id}/history:get","/messages/{message_id}:patch", "/messages/{message_id}:delete"])def iago_message_id() -> Dict[str, object]:diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.pyindex 2ae79f545c7..20fce3063fb 100644--- a/zerver/openapi/markdown_extension.py+++ b/zerver/openapi/markdown_extension.py@@ -260,7 +260,7 @@ def generate_curl_example(endpoint: str, method: str,api_url)]lines.append(" ".join(curl_first_line_parts))- insecure_operations = ['/dev_fetch_api_key:post']+ insecure_operations = ['/dev_fetch_api_key:post', '/fetch_api_key:post']if operation_security is None:if global_security == [{'basicAuth': []}]:authentication_required = Truediff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 7ce371f65b3..6630d77dd0f 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -44,16 +44,38 @@ paths:operationId: fetch_api_keytags: ["authentication"]description: |- Given a username and password, fetch the user's API key.+ This API endpoint is used by clients such as the Zulip mobile and+ terminal apps to implement password-based authentication. Given the+ user's Zulip login credentials, it returns a Zulip API key that the client+ can use to make requests requests as the user.- Used to authenticate the mobile and terminal apps when the server- has EmailAuthBackend or LDAPAuthBackend enabled.+ This endpoint is only useful for Zulip servers/organizations with+ EmailAuthBackend or LDAPAuthBackend enabled.++ The Zulip mobile apps also support SSO/social authentication (GitHub+ auth, Google auth, SAML, etc.) that does not use this endpoint. Instead,+ the mobile apps reuse the web login flow passing the `mobile_flow_otp` in+ a webview, and the credentials are returned to the app (encrypted) via a redirect+ to a `zulip://` URL.++ !!! warn ""+ **Note:** If you signed up using passwordless authentication and+ never had a password, you can [reset your password](/help/change-your-password).++ See the [API keys](/api/api-keys) documentation for+ more details on how to download API key manually.++ In a [Zulip development environment](https://zulip.readthedocs.io/en/latest/development/overview.html),+ see also [the unauthenticated variant](/api/dev-fetch-api-key).parameters:- name: usernamein: querydescription: |The username to be used for authentication (typically, the email- address, but it could be an LDAP username).+ address, but depending on configuration, it could be an LDAP username).++ See the `require_email_format_usernames` parameter documented in+ [GET /server_settings](/api/get-server-settings) for details.schema:type: stringexample: [email protected]@@ -66,9 +88,10 @@ paths:description: |The user's Zulip password (or LDAP password, if LDAP authentication is in use).required: true+ security: []responses:"200":- description: The credentials needed to use the Zulip API.+ description: Valid credentials the client can use to access the Zulip API.content:application/json:schema: