[英]How to get providers access tokens from Firebase authenticated user?
我正在使用Firebase對GitHub,Twitter和Facebook進行身份驗證,我知道我可以在進行身份驗證時獲取提供者訪問令牌
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Facebook Access Token. You can use it to access the Facebook API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}
然而,在使用React Router 4進行身份驗證后,我將用戶重定向到安全區域,在這個安全區域我需要檢索提供者訪問令牌,以便我可以訪問GitHub,Twitter和Facebook API(對於Twitter我也需要獲得“秘密”)串)。
我可以在安全區域中設置一個身份驗證狀態觀察器(下面)以獲取基本用戶詳細信息,甚至是用戶已鏈接的提供者,但是這不會為我提供連接到相應提供者API所需的訪問令牌
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var providerData = user.providerData;
// ...
}
我應該提一下,我允許用戶鏈接多個身份驗證提供程序,因此我需要所有訪問令牌( https://firebase.google.com/docs/auth/web/account-linking )
謝謝
很遺憾,Firebase Auth不會為用戶管理OAuth訪問令牌。 OAuth通過彈出/重定向登錄后,將返回訪問令牌,但之后不會再返回新的訪問令牌。 如果您需要此功能,則需要使用Facebook / Google等原生SDK登錄用戶,然后使用OAuth憑證登錄FireInwithCredential。 這些SDK將為您管理OAuth令牌,並在到期時使用新的訪問令牌更新您。 如果您認為這是Firebase應支持的重要功能,請提出您的情況並提交功能請求。 您可以使用Firebase論壇: https ://groups.google.com/forum/#!forum / firebase-talk或通過Firebase官方支持渠道申請。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.