Authentication
Public

Retrieve an OAuth access token, to be used for authentication of 'private' requests.

📖 Related Article: Authentication

Authentication Methods:

Three methods of authentication are supported (selected with grant_type):

  • client_credentials - Using the client id and client secret that can be found on the API page on the website. This is the simplest method, suitable for server-to-server applications and quick setup.

  • client_signature - Enhanced security method using a cryptographic signature instead of sending the client secret directly. The signature is calculated over <timestamp>\n<nonce>\n<data> (the three values joined with line-feed characters, timestamp exactly as sent). Keys with a shared secret use an HMAC-SHA256 signature encoded as hexadecimal; asymmetric (RSA / Ed25519) keys use a digital signature over the same string encoded as URL-safe base64 without padding. This method requires client_id, timestamp and signature; nonce and data are optional (nonce is strongly recommended for replay protection). See the Client Signature (WebSocket) guide for detailed signature calculation instructions.

  • refresh_token - Using a refresh token that was received from an earlier invocation. This allows you to obtain a new access token without re-supplying your Client ID and Client Secret. Best for long-lived sessions, token renewal, and avoiding re-authentication.

Refresh token behavior:

  • Every successful refresh issues a new access token and a new refresh token, and invalidates the previously issued token pair. Always store the newest refresh_token; reusing an older one fails with -32602 (invalid token), which also affects concurrent refreshes with the same token.
  • The scope parameter is ignored for this grant type: the new tokens keep the scope, session and lifetime of the original token.
  • A token with connection scope is bound to the connection it was issued on and cannot be refreshed or used from another connection.

Scope behavior (client_credentials and client_signature):

  • Without a session: or connection scope item, a WebSocket request gets a connection scope token. An HTTP (REST) request gets a session scope token with a generated rest-... session name, unless connection was requested explicitly.
  • connection and session:name cannot be combined (-32602).
  • Requested permission scopes (trade, wallet, account, block_trade, block_rfq) never exceed the permissions of the API key: higher levels are silently reduced to the key's level, and permission scopes that are not requested inherit the key's permissions. This is not reported as an error.

Response:

The response will contain an access token, expiration period (number of seconds that the token is valid) and a refresh token that can be used to get a new set of tokens. Over WebSocket, a successful call also authenticates the current connection, so later private requests on it need no access_token.

Errors (JSON-RPC error.code):

  • 13004 invalid_credentials - unknown client_id, wrong client_secret, invalid signature, or client_id longer than 16 bytes.
  • 13009 unauthorized - timestamp outside the allowed window, nonce longer than 128 bytes or already used, connecting IP not in the key's IP whitelist (reason: bad_ip).
  • -32602 Invalid params - missing required parameter for the chosen grant_type, unknown grant_type, invalid scope, or an invalid / expired / already-replaced refresh_token (including session_not_found).

Try in API console

get/public/auth

Request

  • Base URL
    https://test.deribit.com/api/v2
  • URL
    https://test.deribit.com/api/v2/public/auth
  • Auth
    none declared

Query parameters

grant_type'client_credentials' | 'client_signature' | 'refresh_token' required
Example:client_credentials

Method of authentication

client_idstring
Example:fo7WAPRm4P

Required for grant types client_credentials and client_signature. Maximum length is 16 bytes.

client_secretstring
Example:W0H6FJW4IRPZ1MOQ8FP6KMC5RZDUUKXS

Required for grant type client_credentials.

refresh_tokenstring

Required for grant type refresh_token. The token pair it belongs to is replaced by the new tokens returned (see above).

timestampinteger

Required for grant type client_signature.

Time when the request was generated, in milliseconds since the UNIX epoch. Must be within ±60 seconds (±60,000 ms) of the server time, otherwise the request is rejected with error 13009 (unauthorized).

signaturestring

Required for grant type client_signature.

Signature calculated over <timestamp>\n<nonce>\n<data>:

  • Shared-secret API keys: HMAC-SHA256 with the client secret as key, encoded as hexadecimal (letter case is ignored).
  • Asymmetric (RSA / Ed25519) API keys: digital signature made with your private key (SHA-256), encoded as URL-safe base64 without padding.

An invalid signature is rejected with error 13004 (invalid_credentials).

noncestring

Optional for grant type client_signature, but strongly recommended. Defaults to an empty string.

User-generated random string, up to 128 bytes. A non-empty nonce can be used only once for the same client_id and timestamp (a repeat is rejected with 13009). With an empty or omitted nonce the timestamp window is still enforced but replay detection is not.

datastring

Optional for grant type client_signature. Defaults to an empty string.

Contains any user specific value; it is part of the signed string.

statestring

Will be passed back in the response.

scopestring
Example:connection

Describes type of the access for assigned token. Ignored for grant type refresh_token.

Possible values:

  • connection
  • session:name (names longer than 64 bytes are truncated)
  • trade:[read, read_write, none]
  • wallet:[read, read_write, none]
  • account:[read, read_write, none]
  • block_trade:[read, read_write, none]
  • block_rfq:[read, read_write, none]
  • expires:NUMBER
  • ip:ADDR

connection and session:name are mutually exclusive. Permission scopes cannot exceed the permissions of the API key.

Details are elucidated in Access scope

Response

Success response

jsonrpc'2.0' required

The JSON-RPC version (2.0)

idinteger

The id that was sent in the request

Example response

{
  "result": {
    "access_token": "843SehgeX5n6XxEU4XbABx4Cny5Akai5iHiJePTsvUw7",
    "expires_in": 31536000,
    "refresh_token": "6faf8L36JdaSqsjCEEiwqifPpj6JB18RWwiWHrsGTZ91",
    "mandatory_tfa_status": "enabled"
  }
}

Changes

    • info

      the query request parameter client_id became optional

    • info

      the query request parameter client_secret became optional

    • info

      the query request parameter refresh_token became optional

    • info

      the query request parameter signature became optional

    • info

      the query request parameter timestamp became optional

    • info

      added the optional property / to the response with the status

    • info

      added the optional property / to the response with the status