Available languages: [Python](https://databento.com/docs/api-live/message-flows/authentication.python.md) · [C++](https://databento.com/docs/api-live/message-flows/authentication.cpp.md) · [Rust](https://databento.com/docs/api-live/message-flows/authentication.rust.md) · [Raw](https://databento.com/docs/api-live/message-flows/authentication.raw.md)

Source: https://databento.com/docs/api-live/message-flows/authentication


# Authentication

The authentication message flow is initiated by the gateway.

The gateway will send a [greeting message](https://databento.com/docs/api-live/gateway-control-messages/greeting-message.md) followed by a
[challenge request](https://databento.com/docs/api-live/gateway-control-messages/challenge-request.md).

The client must then issue an [authentication request](https://databento.com/docs/api-live/client-control-messages/authentication-request.md),
which the gateway will respond to with an [authentication response](https://databento.com/docs/api-live/gateway-control-messages/authentication-response.md)

## Example

For the purpose of this example, assume the API key is `db-89s9vCvwDDKPdQJ5Pb30Fyj9mNUM6`.

When connecting to the gateway, the gateway will send two messages:

`lsg_version=0.2.0\n`

`cram=j5pwMHz6vwXruJM4cOwQrQeQE0bImIzT\n`

To generate the response, the client first concatenates the `cram` value and their API key in the format `$cram|$key`.

In this example, this would be `j5pwMHz6vwXruJM4cOwQrQeQE0bImIzT|db-89s9vCvwDDKPdQJ5Pb30Fyj9mNUM6`.

The concatenated string is then hashed with [SHA-256](https://en.wikipedia.org/wiki/SHA-2).
In this example, it produces `6d3c875bb9f8cf503c3ed83ee5f476a3ad53f0c67706c51cf42d2db5ad8ff5a9`.

This result is then concatenated with the last five bytes of the API key (also referred to as the `bucket_id`) in the format `$auth-$bucket_id`.

With this, the authentication response string is generated as `6d3c875bb9f8cf503c3ed83ee5f476a3ad53f0c67706c51cf42d2db5ad8ff5a9-mNUM6`.

The client then sends the authentication message containing this string to the gateway:

`auth=6d3c875bb9f8cf503c3ed83ee5f476a3ad53f0c67706c51cf42d2db5ad8ff5a9-mNUM6|dataset=GLBX.MDP3|encoding=dbn|ts_out=0\n`

If the key is valid, the gateway will reply with a successful response:
`success=1|session_id=135567\n`
