Share feedback
Answers are generated based on the documentation.

Create an authentication token

POST/v2/users/login

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

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: UsersLoginRequest

Schema example

{
  "password": "hunter2",
  "username": "myusername"
}

Response 200

Authentication successful

application/json

Schema: PostUsersLoginSuccessResponse

Schema example

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

Response 401

Authentication failed or second factor required

application/json

Schema: PostUsersLoginErrorResponse

Schema example

{
  "detail": "Incorrect authentication credentials"
}

Referenced schemas

#/components/schemas/PostUsersLoginErrorResponse

#/components/schemas/PostUsersLoginSuccessResponse

#/components/schemas/UsersLoginRequest

Complete operation contract
{
  "description": "Creates and returns a bearer token in JWT format that you can use to\nauthenticate 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": "PostUsersLogin",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/UsersLoginRequest"
        }
      }
    },
    "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/PostUsersLoginErrorResponse"
          }
        }
      },
      "description": "Authentication failed or second factor required"
    }
  },
  "security": [],
  "summary": "Create an authentication token",
  "tags": [
    "authentication"
  ]
}