亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

谷歌OAuth在交換一次性代碼時redirect_uri_mismatch刷新令牌

谷歌OAuth在交換一次性代碼時redirect_uri_mismatch刷新令牌

拉莫斯之舞 2022-08-17 10:41:24
我正在實現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").asJavaCollectionval 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”}我甚至嘗試發送實際的“引用”網址。我在這里做錯了什么?
查看完整描述

2 回答

?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

它沒有記錄在案,但是當您使用Google客戶端SDK時,您不會重定向。

SDK 將打開一個新窗口,并使用發布消息與其通信。

如果您設置重定向uri,因為它應該適合您。"postmessage"


查看完整回答
反對 回復 2022-08-17
?
Helenr

TA貢獻1780條經驗 獲得超4個贊

如果您在使用彈出模式時收到該錯誤,則解決方案在前端和后端都具有相同的redirect_uri。


即前部-


const client = google.accounts.oauth2.initCodeClient({

  redirect_uri: 'postmessage',

  some_other_params,

})


client.requestCode()

返回-


export const oauth2Client = new google.auth.OAuth2(

  clientId,

  clientSecret,

  "postmessage"

)


let { tokens } = await oauth2Client.getToken(code)


查看完整回答
反對 回復 2022-08-17
  • 2 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號