How should one program a Sign In with Twitter feature using firebase_auth and Flutter?
I see a few examples using flutter_twitter_login or flutter_twitter, however they use a now Deprecated API and folks complain about Apple Store Rejection.
Firebase Auth offers a TwitterAuthProvider, but the following code remains incomplete:
final AuthCredential credential = TwitterAuthProvider.getCredential(
authToken: twitterAccessToken,
authTokenSecret: twitterAccessTokenSecret,
);
final AuthResult result = await auth.signInWithCredential(credential);
4
Answers
I was able to solve this using 3 resources:
Ultimately, I was able to completely remove the flutter_twitter package, yet still support Sign in with Twitter.
Similar to the
CustomWebView
outlined in the Facebook solution, I created aTwitterLoginScreen
like:Then, the
AuthCredential
result from this screen can be passed to FirebaseAuth.signInWithCredential.They have shared a common sample in the home page itself, only the ‘sign in provider’ changes, rest is same for all (google, fb and twitter). the result has a user property which will return the user details, check with the below code
To sign in with Twitter do the following:
Use
twitterlogin
and pass the consumer key and consumer secret key, then use the methodgetCredential()
andsignInWithCredential
to log in.This worked for me. (Referred from https://firebase.flutter.dev/docs/auth/social#twitter)
This wasn’t working initially for me.
Things I had to change in order for this to work.