0

我正在测试使用 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 可以在本地服务器上执行,那将非常有用。请问有谁知道我们如何做到这一点?

谢谢

4

1 回答 1

0

OAuth 2.0 Playground 在服务器端发出身份验证代码交换请求,因为通常 OAuth 服务器不允许对此请求的 CORS 请求(至少对于身份验证代码流,它们不应允许 CORS 请求)。

您可以做的是将您的本地服务公开给外部/互联网。为此,您可以使用ngroklocaltunnel之类的服务,您将获得本地服务的公共 URL,您可以使用该 URL 设置 Playground。

于 2016-03-29T21:55:29.820 回答