在交换刷新令牌的一次性代码时,Google OAuth redirect_uri_mismatch

问题描述 投票:1回答:1

我正在实施Google OAuth2服务器一次性代码流,如下所述:

https://developers.google.com/identity/sign-in/web/server-side-flow

客户端从谷歌获取代码(在用户完成oauth流程后),并将其发送到服务器。

服务器尝试使用此调用交换代码以使用刷新令牌(使用Java SDK):

val authorizationScopes = Seq(GmailScopes.GMAIL_READONLY, GmailScopes.GMAIL_SEND, "email").asJavaCollection

val googleAuthorizationCodeFlow = new GoogleAuthorizationCodeFlow.Builder(
      GoogleNetHttpTransport.newTrustedTransport(),
      JacksonFactory.getDefaultInstance,
      googleAppInfo.googleClientId,
      googleAppInfo.googleClientSecret,
      authorizationScopes)
  .setTokenServerUrl(new GenericUrl(googleAppInfo.tokenServerUrl))
  .setAccessType("offline")
  .build()

val googleTokenResponse: GoogleTokenResponse = googleAuthorizationCodeFlow
  .newTokenRequest(code)
  .setRedirectUri(redirectUri)
  .execute()

我明白了:

com.google.api.client.auth.oauth2.TokenResponseException:400 Bad Request {“error”:“redirect_uri_mismatch”,“error_description”:“Bad Request”}

redirectUri与Google云控制台>凭证>客户端ID(Web应用程序)>授权重定向URI完全相同。

此外,它在我们使用OAuth重定向流时已经有效,但是当我们切换到POST流时,它停止使用此消息。

我尝试发送一个空的redirectUri(正如我在一些关于此事的答案中看到的那样),但是我得到了:

com.google.api.client.auth.oauth2.TokenResponseException:400错误请求{“错误”:“缺少必需参数:redirect_uri”,“error_description”:“错误请求”}

我甚至尝试发送实际的'referer'网址。

我在这做错了什么?

java scala google-oauth2
1个回答
0
投票

它没有记录,但是当您使用Google客户端SDK时,您不会重定向。

SDK打开一个新窗口并使用post message与之通信。

如果你将重定向uri设置为"postmessage"它应该适合你。

© www.soinside.com 2019 - 2024. All rights reserved.