gpt4 book ai didi

oauth-2.0 - 获取 OAuthProblemException : invalid_request for Google when using OLTU

转载 作者:行者123 更新时间:2023-12-04 12:21:17 24 4
gpt4 key购买 nike

我正在使用 Apache 的 Oltu 库,并且我正在尝试使用 OAuth2 通过 Google 进行身份验证。这是相关的代码:

OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
OAuthClientRequest clientReq = OAuthClientRequest
.tokenProvider(OAuthProviderType.GOOGLE)
.setClientId("<my-client-id>")
.setClientSecret("<my-client-secret>")
.setRedirectURI("https://test.example.com/oauthtest/oauth/google/auth")
.setCode(oar.getCode())
.setGrantType(GrantType.AUTHORIZATION_CODE)
.buildQueryMessage();

OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

// This call fails with the OAuthProblemException
OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(clientReq,
OAuthJSONAccessTokenResponse.class);

我可以毫无问题地通过 Facebook 进行身份验证,但无论出于何种原因,这都失败了。我可以毫无问题地从 OAuthAuthzResponse 获取代码,所以我知道原始调用正在工作,但此后续调用失败。

编辑:我已经放弃使用 Oltu 并坚持使用 HttpClient 库并手动执行 OAuth 舞蹈的更简单方法。它对我来说效果更好,我会向任何想要可靠地针对多个 OAuth 提供者进行身份验证的人推荐它。只有 Twitter 要求我使用 Scribe .

最佳答案

Google 的 OAuth2 在 HTTP POST 方法的主体中发送参数而不是查询字符串。

尝试用 buildBodyMessage() 方法替换 buildQueryMessage()。

关于oauth-2.0 - 获取 OAuthProblemException : invalid_request for Google when using OLTU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22335307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com