# Create an authentication token


[API catalog](/reference/api/) · [Publisher analytics overview](/reference/api/dvp/latest/) · [Product manual](https://docs.docker.com/docker-hub/repos/manage/trusted-content/insights-analytics/) · [OpenAPI specification](/reference/api/dvp/latest.yaml)

API version: 1.0.0



`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](/reference/api/dvp/latest/#authentication)


Server: `https://hub.docker.com`

Effective security: alternatives are OR; schemes within an alternative are AND. An empty array declares no HTTP authentication requirement.

```json
[]
```
## Example request

Replace placeholders and provide the required credentials or request body.

```console
curl \
  --request POST \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "password": "hunter2",
  "username": "myusername"
}' \
  'https://hub.docker.com/v2/users/login'
```

## Parameters

## Request and responses

### Request  application/json

Login details.


Schema:

```json
{
  "$ref": "#/components/schemas/UsersLoginRequest"
}
```




Schema example:
```json
{
  "password": "hunter2",
  "username": "myusername"
}
```


### Response 200 application/json

Authentication successful


Schema:

```json
{
  "$ref": "#/components/schemas/PostUsersLoginSuccessResponse"
}
```




Schema example:
```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}
```


### Response 401 application/json

Authentication failed or second factor required


Schema:

```json
{
  "$ref": "#/components/schemas/PostUsersLoginErrorResponse"
}
```




Schema example:
```json
{
  "detail": "Incorrect authentication credentials"
}
```


## Complete operation contract

```json
{
  "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"
  ]
}
```

## Referenced schemas

- [#/components/schemas/PostUsersLoginErrorResponse](/reference/api/dvp/latest/schemas/PostUsersLoginErrorResponse/)

- [#/components/schemas/PostUsersLoginSuccessResponse](/reference/api/dvp/latest/schemas/PostUsersLoginSuccessResponse/)

- [#/components/schemas/UsersLoginRequest](/reference/api/dvp/latest/schemas/UsersLoginRequest/)




