我正在实现Google OAuth2服务器一次性代码流,如下所述:
https://developers.google.com/identity/sign-in/web/server-side-flow
客户端从谷歌获取代码(在用户完成oauth流后),并将其POST到服务器。
服务器尝试使用以下调用将代码交换为刷新令牌(使用 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”}
重定向Uri与Google云控制台中的>凭据>客户端ID(Web应用程序)>授权重定向URI完全相同。
此外,当我们使用OAuth重定向流时,它已经起作用了,但是当我们切换到POST流时,它停止使用此消息。
我尝试发送一个空的redirectUri(正如我在有关此事的一些答案中看到的那样),但是我得到的:
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request { “error” : “Missing required parameter: redirect_uri”, “error_description” : “Bad Request”}
我甚至尝试发送实际的“引用”网址。
我在这里做错了什么?
千万里不及你
Helenr
相关分类