[英]Using both Google Signin and Firebase auth require login twice?
我遇到了一些令人困惑的問題:
我在我的應用程序Firebase
來存儲用戶數據等,並保護用戶的數據我使用Google Authentication
的構建。 我認識到我可以在這個signIn過程中定義scopes
,用戶可以/應該允許,但我注意到你不能要求所有的Google Scopes / Services,(所有的都有Firebase
內置的功能)
所以我必須使用Google JS Library
進行身份驗證,以訪問存儲在Google
上的其余用戶數據(我希望在我的Web應用程序中顯示用戶)。
如果Google signin popup
顯示兩次 ,一次授權給Firebase
,另一次授權給Google API's
,可能會有點令人困惑。
我的問題是,有沒有辦法,可能會在Firebase signin process
移交access_token
(反之亦然),我沒有用戶登錄兩次 , Google popup
窗口只出現一次 ?
您可以使用從Google身份驗證中獲取的令牌調用authWithOAuthToken
:請參閱https://www.firebase.com/docs/web/api/firebase/authwithoauthtoken.html 。 從那里:
此方法接受OAuth憑據的單個字符串參數(例如OAuth 2.0承載訪問令牌)或對象(例如一組OAuth 1.0a憑證)。 使用OAuth令牌登錄Facebook,GitHub和Google只需要一個字符串訪問令牌:
// Authenticate with Facebook using an existing OAuth 2.0 access token
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithOAuthToken("facebook", "<ACCESS-TOKEN>", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
來自文檔的示例使用Facebook,但同樣適用於Google令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.