Share feedback
Answers are generated based on the documentation.

Second factor authentication

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.

Connection and access

API connection and authentication guidance

https://hub.docker.com — Docker HUB API

No HTTP authentication requirement is declared for this operation. Transport access controls can still apply.

Parameters

No parameters are declared.

Request and responses

Request

Login details.

application/json

Schema: Users2FALoginRequest

Schema example

{
  "code": "123456",
  "login_2fa_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

Response 200

Authentication successful

application/json

Schema: PostUsersLoginSuccessResponse

Schema example

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

Response 401

Authentication failed

application/json

Schema: PostUsers2FALoginErrorResponse

Schema example

{
  "detail": "Incorrect authentication credentials"
}

Referenced schemas

#/components/schemas/PostUsers2FALoginErrorResponse

#/components/schemas/PostUsersLoginSuccessResponse

#/components/schemas/Users2FALoginRequest

Complete operation contract
{
  "description": "When a user has two-factor authentication (2FA) enabled, this is the second call to perform after `/v2/users/login` call.\n\nCreates and returns a bearer token in JWT format that you can use to authenticate with Docker Hub APIs.\n\nThe returned token is used in the HTTP Authorization header like `Authorization: Bearer {TOKEN}`.\n\nMost Docker Hub APIs require this token either to consume or to get detailed information. For example, to list images in a private repository.\n",
  "operationId": "PostUsers2FALogin",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/Users2FALoginRequest"
        }
      }
    },
    "description": "Login details.",
    "required": true
  },
  "responses": {
    "200": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/PostUsersLoginSuccessResponse"
          }
        }
      },
      "description": "Authentication successful"
    },
    "401": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/PostUsers2FALoginErrorResponse"
          }
        }
      },
      "description": "Authentication failed"
    }
  },
  "security": [],
  "summary": "Second factor authentication",
  "tags": [
    "authentication-api"
  ]
}