Second factor authentication Run in API Explorer

POST /v2/users/2fa-login

When a user has two-factor authentication (2FA) enabled, this is the second call to perform after /v2/users/login call.

Creates and returns a bearer token in JWT format that you can use to authenticate with Docker Hub APIs.

The returned token is used in the HTTP Authorization header like Authorization: Bearer {TOKEN}.

Most Docker Hub APIs require this token either to consume or to get detailed information. For example, to list images in a private repository.

application/json

Body Required

Login details.

  • login_2fa_token string Required

    The intermediate 2FA token returned from /v2/users/login API.

  • code string Required

    The Time-based One-Time Password of the Docker Hub account to authenticate with.

Responses

  • 200 application/json

    Authentication successful

    Hide response attribute Show response attribute object
    • token string

      Created authentication token. This token can be used in the HTTP Authorization header as a JWT to authenticate with the Docker Hub APIs.

  • 401 application/json

    Authentication failed

    Hide response attribute Show response attribute object
    • detail string

      Description of the error.

POST /v2/users/2fa-login
curl \
 --request POST 'https://hub.docker.com/v2/users/2fa-login' \
 --header "Content-Type: application/json" \
 --data '{"login_2fa_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c","code":123456}'
Request examples
{
  "login_2fa_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  "code": 123456
}
Response examples (200)
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}
Response examples (401)
{
  "detail": "Incorrect authentication credentials"
}