액세스 토큰 생성

액세스 토큰 생성

Docker API를 호출할 때 bearer로 쓸 수 있는 단기(short-lived) 액세스 토큰을 JWT 형식으로 만들어 반환해요. 성공하면 반환된 액세스 토큰을 HTTP Authorization 헤더에 사용해요.

출처: 문서

본문

POST /v2/auth/token

액세스 토큰 생성 작업이에요. Docker API를 호출할 때 bearer로 쓸 수 있는 단기(short-lived) 액세스 토큰을 JWT 형식으로 만들어 반환해요. 성공하면 반환된 액세스 토큰을 HTTP Authorization 헤더에 사용해요.

요청 예시

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

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'

요청과 응답

응답 200 Token created

Schema:

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

Schema example:

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

응답 401 Authentication failed

Schema:

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

error:

{
  "errinfo": null,
  "message": "unauthorized"
}

전체 작업 계약

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

참조된 스키마

더 알아보기