我正在测试使用 Playground 编写的 OAuth2 服务器。完整的配置 URL 在这里。
第 1 步(授权授予)完美运行。在 Chrome 中我可以看到这个请求:
GET https://localhost:8080/oauth2/api/authorize?scope=fp&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&response_type=code&client_id=acme1&access_type=offline
第 2 步(令牌交换)失败并显示:
POST /oauth2/api/token HTTP/1.1
Host: localhost:8080
Content-length: 153
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
code=2l0vf6n&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=acme1&client_secret=secret&scope=&grant_type=authorization_code
HTTP/1.1 400 Bad Request
Content-length: 115
Content-type: text/plain
An error occured while connecting to the server: DNS lookup failed for URL: https://localhost:8080/oauth2/api/token
查看网络我可以看到:
POST https://developers.google.com/oauthplayground/exchangeAuthCode
有了这个身体:
{"token_uri":"https://localhost:8080/oauth2/api/token","client_id":"acme1","client_secret":"secret","code":"5kns7"}
这是它的预期工作方式吗?OAuth 服务器交互,至少对于令牌交换,必须在公共网络上?
如果步骤 2 可以在本地服务器上执行,那将非常有用。请问有谁知道我们如何做到这一点?
谢谢