Oauth 获取承载令牌后无法发出get请求-401错误“;“范围不足”;

Oauth 获取承载令牌后无法发出get请求-401错误“;“范围不足”;,oauth,bearer-token,dockerhub,docker-api,Oauth,Bearer Token,Dockerhub,Docker Api,我有以下请求从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 -

我有以下请求从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"}]}]}

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

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

出于绝望,我在Github上提交了一个问题:以下是我能找到的最相关的文档: