.. meta:: :robots: nosnippet .. _data-api-authenticate-requests: ============================== Authenticate Data API Requests ============================== .. contents:: On this page :local: :backlinks: none :depth: 2 :class: singlecol Overview -------- Data API endpoints generally require that incoming requests include authentication information for the user calling the endpoint. This lets the endpoint enforce rules and validate document schemas for each request. Requests must include authentication data in specific request headers. App Services uses the following process to authenticate a given request: 1. Check for an ``Authorization`` header. If it's present, try to use :ref:`Bearer Authentication `. The header must contain a valid user access token. If the token is invalid, the request fails. 2. If the ``Authorization`` header is not present or does not use the "Bearer" scheme, check for :ref:`Credential Headers `. The headers must contain valid Email/Password, API Key, or Custom JWT credentials for an App user. .. note:: You must :ref:`enable an authentication provider ` before users can authenticate with it. .. _data-api-bearer-authentication: Bearer Authentication --------------------- The Data API supports Bearer Authentication, which lets you authenticate a request by including a valid user access token in the request's ``Authorization`` header. To learn how to get and manage an access token, see :ref:`Manage User Sessions `. The Authorization header uses the following format: .. code-block:: text Authorization: Bearer For example, the following request uses Bearer Authentication: .. literalinclude:: /data-api/snippets/generated-endpoints.snippet.auth-bearer.sh :language: bash :emphasize-lines: 4 .. include:: /includes/bearer-auth-performance.rst .. include:: /includes/dont-use-api-key-in-browsers.rst .. include:: /includes/bearer-auth-is-useful.rst .. note:: For security reasons, App Services does not return detailed Bearer Authentication errors to the client app. If you are having problems with Bearer Authentication, check the :ref:`Application Logs `. .. _data-api-credential-headers: Credential Headers ------------------ You can authenticate a Data API request by including the user's login credentials in the request headers. The exact headers to include depend on the authentication provider. Credential headers are useful for: - requests sent from a server-side application - requests sent from a command-line tool - manual or test requests sent from an HTTPS client like Postman .. important:: You cannot use credential headers to authenticate requests sent from a web browser due to :wikipedia:`Cross-Origin Resource Sharing ` restrictions. Instead, to authenticate Data API requests from a browser, use :ref:`Bearer Authentication `. Email/Password ~~~~~~~~~~~~~~ To authenticate a Data API request as an :ref:`email/password ` user, include the user's credentials in the request's ``email`` and ``password`` headers. .. literalinclude:: /data-api/snippets/generated-endpoints.snippet.auth-emailPassword.sh :language: bash :emphasize-lines: 4-5 API Key ~~~~~~~ To authenticate a Data API request with an :ref:`API Key `, include the API key in the request's ``apiKey`` header. .. literalinclude:: /data-api/snippets/generated-endpoints.snippet.auth-apiKey.sh :language: bash :emphasize-lines: 4 .. include:: /includes/dont-use-api-key-in-browsers.rst Custom JWT ~~~~~~~~~~ To authenticate a Data API request as a :ref:`Custom JWT ` user, include the JWT string in the request's ``jwtTokenString`` header. .. literalinclude:: /data-api/snippets/generated-endpoints.snippet.auth-jwtTokenString.sh :language: bash :emphasize-lines: 4