👻
[メモ]Reactからでもできるfirebase authの認証後にaccess token keyとsecretを抜く方法
参考:公式ドキュメントsignInWithPopup()
で帰ってきたcredentialの中身をそのまま見てもaccess tokenは見当たらないが
const credential = TwitterAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const secret = credential.secret;
で取得できるらしい。
以下公式ドキュメントから引用
import { getAuth, signInWithPopup, TwitterAuthProvider } from "firebase/auth";
const auth = getAuth();
signInWithPopup(auth, provider)
.then((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.
const credential = TwitterAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const secret = credential.secret;
// The signed-in user info.
const user = result.user;
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.customData.email;
// The AuthCredential type that was used.
const credential = TwitterAuthProvider.credentialFromError(error);
// ...
});
Discussion