为什么这个刷新令牌请求到auth.docker.io返回404?

时间:2016-11-04 01:32:11

标签: docker refresh token

我正在尝试使用此处记录的api:https://docker.github.io/registry/spec/auth/oauth/

当我按照文档中的描述POST到服务时,它总是返回404。

我使用自己的帐户并使用文档中的确切查询尝试过此操作。

以下是一个例子:

[prompt]$ curl -v \

-H 'Content-Type: application/x-www-form-urlencoded' \
-X POST -d 'grant_type=password&username=johndoe&password=A3ddj3w&service=hub.docker.io&client_id=dockerengine&access_type=offline' \
https://auth.docker.io/token
* Trying 52.5.234.85...
* Connected to auth.docker.io (52.5.234.85) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: *.docker.io
* Server certificate: RapidSSL SHA256 CA - G3
* Server certificate: GeoTrust Global CA
POST /token HTTP/1.1
Host: auth.docker.io
User-Agent: curl/7.43.0
Accept: /
Content-Type: application/x-www-form-urlencoded
Content-Length: 118

upload completely sent off: 118 out of 118 bytes
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Fri, 04 Nov 2016 01:10:14 GMT
< Content-Length: 19
< Strict-Transport-Security: max-age=31536000
< 
404 page not found
Connection #0 to host auth.docker.io left intact

使用活动帐户的凭据时会返回相同的响应。 如果帐户未经过身份验证,我似乎至少应该收到401.

是否不再支持此服务?

我可以使用GET api来获取短期的持票令牌,但我需要一个刷新令牌。 这里记录了GET api:https://docs.docker.com/registry/spec/auth/jwt/

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我先把解决方案放在首位,稍后再提供额外信息。

DOCKER_HUB_USERNAME=$1
DOCKER_HUB_PASSWORD=$2
DOCKER_REPO=$3

AUTH_64=$(echo -n $DOCKER_HUB_USERNAME:$DOCKER_HUB_PASSWORD | base64)

TOKEN=$(curl -s -H "Authorization: Basic $AUTH_64" \
                -H 'Accept: application/json' \
                "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$DOCKER_REPO:pull" | jq -r .token)

curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" \
    "https://index.docker.io/v2/$DOCKER_REPO/tags/list" | jq -r .tags

我做了一些挖掘,发现this answer要求你使用docker登录,这不是我想要的。在查看他正在提取的docker conf文件后,我发现该值是user:pass的base64编码。所以我只是避免尝试获取刷新令牌。

我使用jq来获取json值。 Here is a download link。您可以随意检索它们。我将第二个命令放在一个例子中,尽管这应该适用于the v2 API的任何内容。我想你甚至可以用任何docker注册表替换index.docker.io

哦,如果您需要推送权限,请务必将$DOCKER_REPO:pull更改为$DOCKER_REPO:pull,push