【问题标题】:OAuth2 Playground - Exchange of Token fails with DNS lookup errorOAuth2 Playground - 令牌交换失败并出现 DNS 查找错误
【发布时间】:2016-03-24 05:20:46
【问题描述】:

我正在测试使用 Playground 编写的 OAuth2 服务器。 完整的配置 URL 是here

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

谢谢

【问题讨论】:

    标签: oauth2-playground


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多