0

我有以下请求从 Docker Hub API 获取不记名令牌,然后将该令牌用于对给定端点的 GET 请求:

#!/usr/bin/env bash

raw_token="$(curl https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/ubuntu:list)";
token="$(node -pe "JSON.parse('$raw_token').token")"
curl -i -H "Authorization: Bearer $token" https://registry-1.docker.io/v2/library/ubuntu/tags/list

如果我运行它,我会收到此错误:

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/ubuntu:pull",error="insufficient_scope"
Date: Wed, 20 Jun 2018 08:02:24 GMT
Content-Length: 157
Strict-Transport-Security: max-age=31536000

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"library/ubuntu","Action":"pull"}]}]}

有谁知道我如何提出正确的请求并获得正确的令牌?

4

1 回答 1

0

当您获得令牌时,您指定 scope=repository:library/ubuntu:list。当你使用令牌时,它说你需要 scope="repository:library/ubuntu:pull"。

于 2018-06-23T14:37:55.000 回答