# Create an authentication token


[API catalog](/reference/api/) · [Docker Hub overview](/reference/api/hub/latest/) · [Product manual](https://docs.docker.com/docker-hub/) · [OpenAPI specification](/reference/api/hub/latest.yaml)

API version: 2-beta



`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}`.

_**As of September 16, 2024, this route requires a personal access token (PAT) instead of a password if your organization has SSO enforced.**_


  Deprecated: Use [Create access token](/reference/api/hub/latest/operations/AuthCreateAccessToken/) instead.



Deprecated operation.

## Connection and access

[API connection and authentication guidance](/reference/api/hub/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": "p@ssw0rd",
  "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": "p@ssw0rd",
  "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
{
  "deprecated": true,
  "description": "Creates 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\n_**As of September 16, 2024, this route requires a personal access token (PAT) instead of a password if your organization has SSO enforced.**_\n\n\n  Deprecated: Use [Create access token](#tag/authentication-api/operation/AuthCreateAccessToken) instead.\n\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-api"
  ]
}
```

## Referenced schemas

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

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

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




