2016-05-24 18 views
0

firebaseを通じてウェブサイトのユーザー認証にツイッターアカウントをリンクすることをサポートしたいと考えています。つまり、次のリンクに従って、認証プロバイダの資格情報を取得する必要があります。Firebase認証 - Twitterアカウントを接続する

https://firebase.google.com/docs/auth/web/account-linking#link-auth-provider-credentials-to-a-user-account

ドキュメントでは、Google、Facebookや電子メールを表示します。しかし、私はそうここAPIを見て...ツイッターを使いたい:

https://firebase.google.com/docs/reference/js/firebase.auth.TwitterAuthProvider#TwitterAuthProvider

は私がコールする必要があります...私は本当に置く必要がありますか問題がある

var credential = firebase.auth.TwitterAuthProvider.credential(token,secret); 

プレーヤテキストのjavascriptのtwitter auth secret?明らかに、これはセキュリティリスクのようですか?

答えて

-1

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を使用して追加データを取得します。

    • signInWithRedirectを呼び出し、サインインページにリダイレクトしてサインインするには:

      firebase.auth().signInWithRedirect(provider);

    を次に、あなたも呼び出すことで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; 
        // ... 
    }); 
    
+1

返事のおかげで、それはあたりとして(アカウントをリンクするよう助けていません。https://firebase.google.com/docs/auth/web/account-linking#link-auth-provider-あなたがsignInWithRedirectやsignInWithPopupを呼び出すことはありません資格情報ツー・ユーザー・アカウント)、あなたはTwitterでログインしていません。 –

関連する問題