인증 토큰 생성

인증 토큰 생성

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

출처: 문서

본문

POST /v2/users/login

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

요청 예시

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

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'

요청과 응답

응답 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"
}

전체 작업 계약

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

참조된 스키마

더 알아보기