I really got excited seeing the latest update to the Flutter Firebase Auth plugin which adds support for Twitter and decided to try it out.
But before we begin, I have made the following assumptions
- Flutter has been installed on your computer. If in need of help the Flutter team have detailed step-by-step articles on how to get this done.
- Created a Twitter app. For more details visit Twitters app page
- You have created a firebase project with support for both Android and iOS. If in need of help this article explains the steps.
- Enabled Twitter authentication for your Firebase project. You can do this by following step 5 of Before you begin section here
- Downloaded and added both
google-services.jsonfiles to Runner directory for iOS and
In order to achieve our purpose, the below plugins (listed in
pubspec.yaml) were used
firebase_auth: '^0.5.9'//we need to get a FirebaseUser
google_sign_in: '^3.0.3' //not really needed
flutter_twitter_login: "^1.1.0" //helps with Twitter OAuth dance
Authenticating With Twitter
First we get a
final TwitterLogin twitterLogin = new TwitterLogin( consumerKey: Strings.twitterApiKey,
Second, we get the
TwitterSession. This also using
_twitterLoginResult = await twitterLogin.authorize();
_currentUserTwitterSession = _twitterLoginResult.session;
_twitterLoginStatus = _twitterLoginResult.status;
TwitterSession to retrieve token and secret needed by
Now that we have our
TwitterSession, our third step will be to get a
FirebaseUser provided Twitter login was successful.
AuthCredential _authCredential = TwitterAuthProvider.getCredential(
authToken: _currentUserTwitterSession?.token ?? '',
authTokenSecret: _currentUserTwitterSession?.secret ?? ''
_currentUser = await _firebaseAuth.signInWithCredential(
Not to worry, I did not forget our iOS friends
And this wraps the end of my very first post. Looking forward to the next one already 😃.
Whoops!! Here is the complete code on GitHuB.