はAuthenticate Using Twitter on Web App
1.Handle the sign-in flow with the Firebase SDK
あなたはは、認証プロバイダーの資格情報を取得しようとする必要がある2.Handle the sign-in flow manually
のための2つの方法があります。
Twitterアカウントを使用してFirebaseでユーザーを認証する最も簡単な方法は、Firebase SDKでサインインフローを処理することです。これを行うには、次の手順を実行します。
ステップ1: をTwitterのプロバイダオブジェクトのインスタンスを作成します。
var provider = new firebase.auth.TwitterAuthProvider();
ステップ2: 認証FirebaseとTwitterのプロバイダオブジェクトを使用します。ポップアップウィンドウを開くかサインインページにリダイレクトすることで、自分のTwitterアカウントでサインインするようにユーザーに促すことができます。モバイルデバイスでは、リダイレクト方式が推奨されます。また、あなたがをを使用することができますTwitterのプロバイダーのOAuthトークンを取得できることがわかり
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a the Twitter OAuth 1.0 Access Token and Secret.
// You can use these server side with your app's credentials to access the Twitter API.
var token = result.credential.accessToken;
var secret = result.credential.secret;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
:signInWithPopupを呼び出し、ポップアップウィンドウでサインインしてください
は、Twitter APIを使用して追加データを取得します。
を次に、あなたも呼び出すことでTwitterのプロバイダーのOAuthトークンを取得することができますgetRedirectResultたときに、あなたのページのロード:
人のfirebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a the Twitter OAuth 1.0 Access Token and Secret.
// You can use these server side with your app's credentials to access the Twitter API.
var token = result.credential.accessToken;
var secret = result.credential.secret;
// ...
}
// The signed-in user info.
var user = result.user;
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
返事のおかげで、それはあたりとして(アカウントをリンクするよう助けていません。https://firebase.google.com/docs/auth/web/account-linking#link-auth-provider-あなたがsignInWithRedirectやsignInWithPopupを呼び出すことはありません資格情報ツー・ユーザー・アカウント)、あなたはTwitterでログインしていません。 –