我創(chuàng)建了一個 Google 登錄按鈕:<!DOCTYPE html><html><head> <title>Google Auth Demo</title> <meta name="google-signin-client_id" content="xxxx.apps.googleusercontent.com"> <script src="https://apis.google.com/js/platform.js" async defer></script> <script> function signOut() { gapi.auth2.getAuthInstance().signOut().then(function() { console.log('user signed out') })}; function onSignIn(googleUser) { console.log(googleUser.getBasicProfile()); } </script></head><body> <h1>Welcome to the Demo</h1> <div class="g-signin2" data-onsuccess="onSignIn" data-ux_mode="redirect" ></div> <button onclick="signOut()" >Sign out</button></body></html>我將參數(shù)從 popup 更改為data-ux_mode="redirect". 如何在https://console.developer.googleAuthorized redirect URIs上配置該字段或更改我的應(yīng)用程序的其他內(nèi)容,以便我可以在本地主機(jī)上使用它?我在這里找到了一個關(guān)閉的問題:https://github.com/google/google-api-javascript-client/issues/288#issuecomment-289064472。那么它可以用于實(shí)現(xiàn)代碼驗(yàn)證按鈕 Google 示例而無需打開彈出窗口嗎?
1 回答

拉風(fēng)的咖菲貓
TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個贊
您需要添加授權(quán)域并使用此 URL 將 URI 重定向到您的客戶端 ID 或 API 密鑰
https://console.cloud.google.com/apis/credentials?project={YOUR-GOOGLE-CLOUD-PROJECT-NAME}
基本上在 GCP 控制臺中,左側(cè)導(dǎo)航欄上轉(zhuǎn)到 API 和服務(wù)。在那里查找您在項(xiàng)目中使用的 oAuth2.0 客戶端 ID。單擊它后,您將看到一個配置授權(quán)重定向 URI 和授權(quán) JavaScript 來源的界面
編輯:在查看鏈接的 github 問題(順便說一下,該問題仍然處于開放狀態(tài))時,無法使用重定向 UX 將令牌獲取到本地計算機(jī)。他們計劃將來支持它,但目前僅適用于彈出方法。
您好@Jeevsxp,如果沒有彈出窗口,則無法獲取授權(quán)碼。這是一個安全限制:離線代碼將允許您在服務(wù)器中獲取refresh_token,這使您可以隨時獲取新的access_token。為此,需要用戶明確同意
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消