【问题标题】:Google OAuth2 PlayGround returns "Unauthorized Client"Google OAuth2 PlayGround 返回“未经授权的客户端”
【发布时间】:2014-02-18 14:53:57
【问题描述】:
    clientId = xxxxxx
    clientSecret = xxxxxxxx
    applicationHost = xxxxxxxxx

我的授权码请求:

   OAuthClientRequest oAuthClientRequest = OAuthClientRequest
                .authorizationProvider(OAuthProviderType.GOOGLE)
                .setResponseType("code")
                .setClientId(clientId)
                .setParameter("access_type", "online")
                .setRedirectURI(applicationHost + "auth/google/callback")
                .setScope("https://www.googleapis.com/auth/plus.login")
                .buildQueryMessage();

        response.sendRedirect(oAuthClientRequest.getLocationUri());

我正在获得一个授权码。但是每当我使用此代码发送对 access_token 的请求时,我都会收到错误消息。 (代码 400)

我的 access_token 请求:

    OAuthClientRequest oAuthClientRequest = OAuthClientRequest
            .tokenProvider(OAuthProviderType.GOOGLE)
            .setGrantType(GrantType.AUTHORIZATION_CODE)
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .setParameter("access_type", "online")
            .setRedirectURI(applicationHost + "auth/google/callback")
            .setCode(code)
            .buildQueryMessage();

    GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(
            oAuthClientRequest, GitHubTokenResponse.class);
    return oAuthResponse.getAccessToken();

OAuth2 Playground 响应:

    HTTP/1.1 400 Bad Request
    Alternate-protocol: 443:quic
    Content-length: 37
    X-xss-protection: 1; mode=block
    X-content-type-options: nosniff
    X-google-cache-control: remote-fetch
    -content-encoding: gzip
    Server: GSE
    Via: HTTP/1.1 GWA
    Pragma: no-cache
    Cache-control: no-cache, no-store, max-age=0, must-revalidate
    Date: Mon, 17 Feb 2014 09:03:52 GMT
    X-frame-options: SAMEORIGIN
    Content-type: application/json
    Expires: Fri, 01 Jan 1990 00:00:00 GMT
    {
       "error": "unauthorized_client"
    }

请帮帮我。提前致谢。

【问题讨论】:

标签: java web-applications oauth-2.0 google-oauth oauth2client


【解决方案1】:

您正在从您的应用程序中获取一个身份验证代码(即客户端 ID XXXXX)并将其粘贴到另一个应用程序(客户端 ID 为 YYYYY 的 oauth Playground)并期望它能够正常工作?

那是行不通的。

如果您进入 Gear 选项并输入您的应用程序的凭据,它可能会起作用。但我有点困惑你为什么要这样做。您要解决的问题是什么?

这个答案可能对How do I authorise an app (web or installed) without user intervention? (canonical ?)有帮助

【讨论】:

  • 我基本上想用授权码生成一个演示访问令牌。即使我运行我的代码(检查 access_token 请求部分)并发送一个 http 请求,我仍然会收到错误代码 400。
  • 我的目标是让用户能够通过 facebook、google、twitter 等登录。我已经在 facebook 上取得了成功,但 Google 出了点问题。
  • 哦,非常感谢 Oauth 游乐场链接。它缺少我自己的配置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-27
  • 1970-01-01
  • 2019-07-13
  • 2013-09-05
  • 2014-11-18
相关资源
最近更新 更多