인증 토큰 생성

인증 토큰 생성

Docker Hub API를 인증할 때 쓸 JWT 형식의 bearer 토큰을 만들어 반환해요. 반환된 토큰은 Authorization: Bearer ***처럼 HTTP Authorization 헤더에 사용해요.

출처: 문서

본문

POST /v2/users/login

인증 토큰 생성 작업이에요. Docker Hub API를 인증할 때 쓸 JWT 형식의 bearer 토큰을 만들어 반환해요. 반환된 토큰은 Authorization: Bearer ***처럼 HTTP Authorization 헤더에 사용해요.

요청 예시

실행 전에 자리 표시자를 바꾸고 필요 자격 증명이나 요청 바디를 채워야 해요.

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'

요청과 응답

응답 200 Authentication successful

Schema:

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

Schema example:

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

응답 401 Authentication failed or second factor required

Schema:

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

Schema example:

{
  "detail": "Incorrect authentication credentials"
}

전체 작업 계약

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

참조된 스키마

더 알아보기