# Create access 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/auth/token`

Creates and returns a short-lived access token in JWT format for use as a bearer when calling Docker APIs.

If successful, the access token returned should be used in the HTTP Authorization header like 
`Authorization: Bearer {access_token}`.

_**If your organization has SSO enforced, you must use a personal access token (PAT) instead of a password.**_


## 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 '{
  "identifier": "myusername",
  "secret": "dckr_pat_124509ugsdjga93"
}' \
  'https://hub.docker.com/v2/auth/token'
```

## Parameters

## Request and responses

### Request  application/json




Schema:

```json
{
  "description": "Request to create access token",
  "examples": [
    {
      "identifier": "myusername",
      "secret": "dckr_pat_124509ugsdjga93"
    }
  ],
  "properties": {
    "identifier": {
      "description": "The identifier of the account to create an access token for. If using a password or personal access token,\nthis must be a username. If using an organization access token, this must be an organization name.\n",
      "example": "myusername",
      "type": "string"
    },
    "secret": {
      "description": "The secret of the account to create an access token for. This can be a password, personal access token, or\norganization access token.\n",
      "example": "dckr_pat_124509ugsdjga93",
      "type": "string"
    }
  },
  "required": [
    "identifier",
    "secret"
  ],
  "type": "object"
}
```




Schema example:
```json
{
  "identifier": "myusername",
  "secret": "dckr_pat_124509ugsdjga93"
}
```


### Response 200 application/json

Token created


Schema:

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




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


### Response 401 application/json

Authentication failed


Schema:

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




error:
```json
{
  "errinfo": null,
  "message": "unauthorized"
}
```


## Complete operation contract

```json
{
  "description": "Creates and returns a short-lived access token in JWT format for use as a bearer when calling Docker APIs.\n\nIf successful, the access token returned should be used in the HTTP Authorization header like \n`Authorization: Bearer {access_token}`.\n\n_**If your organization has SSO enforced, you must use a personal access token (PAT) instead of a password.**_\n",
  "operationId": "AuthCreateAccessToken",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "description": "Request to create access token",
          "examples": [
            {
              "identifier": "myusername",
              "secret": "dckr_pat_124509ugsdjga93"
            }
          ],
          "properties": {
            "identifier": {
              "description": "The identifier of the account to create an access token for. If using a password or personal access token,\nthis must be a username. If using an organization access token, this must be an organization name.\n",
              "example": "myusername",
              "type": "string"
            },
            "secret": {
              "description": "The secret of the account to create an access token for. This can be a password, personal access token, or\norganization access token.\n",
              "example": "dckr_pat_124509ugsdjga93",
              "type": "string"
            }
          },
          "required": [
            "identifier",
            "secret"
          ],
          "type": "object"
        }
      }
    }
  },
  "responses": {
    "200": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/AuthCreateTokenResponse"
          }
        }
      },
      "description": "Token created"
    },
    "401": {
      "$ref": "#/components/responses/unauthorized",
      "description": "Authentication failed"
    }
  },
  "security": [],
  "summary": "Create access token",
  "tags": [
    "authentication-api"
  ]
}
```

## Referenced schemas

- `#/components/responses/unauthorized`

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




