Firebase Tutorial
Firebase Useful Resources
Selected Reading
- Firebase - Deploying
- Firebase - Security
- Firebase - Offline Capabilities
- Anonymous Authentication
- Firebase - Github Authentication
- Firebase - Twitter Authentication
- Firebase - Facebook Authentication
- Firebase - Google Authentication
- Firebase - Email Authentication
- Firebase - Best Practices
- Firebase - Filtering Data
- Firebase - Queries
- Firebase - Detaching Callbacks
- Firebase - Event Types
- Firebase - Read Data
- Firebase - Write Transactional Data
- Firebase - Write List Data
- Firebase - Write Data
- Firebase - Arrays
- Firebase - Data
- Firebase - Environment Setup
- Firebase - Overview
- Firebase - Home
Firebase Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Firebase - Twitter Authentication
Firebase - Twitter Authentication
In this chapter, we will explain how to use Twitter authentication.
Step 1 - Create Twitter App
You can create Twitter app on this
. Once your app is created cpck on Keys and Access Tokens where you can find API Key and API Secret. You will need this in step 2.Step 2 - Enable Twitter Authentication
In your Firebase dashboard side menu, you need to cpck Auth. Then open SIGN-IN-METHOD tab. Cpck on Twitter to enable it. You need to add API Key and API Secret from the step 1.
Then you would need to copy the callback URL and paste it in your Twitter app. You can find the Callback URL of your Twitter app when you cpck on the Settings tab.
Step 3 - Add Buttons
In this step, we will add two buttons inside the body tag of index.html.
index.html
<button oncpck = "twitterSignin()">Twitter Signin</button> <button oncpck = "twitterSignout()">Twitter Signout</button>
Step 4 - Authentication Functions
Now we can create functions for Twitter authentication.
index.js
var provider = new firebase.auth.TwitterAuthProvider(); function twitterSignin() { firebase.auth().signInWithPopup(provider) .then(function(result) { var token = result.credential.accessToken; var user = result.user; console.log(token) console.log(user) }).catch(function(error) { console.log(error.code) console.log(error.message) }); } function twitterSignout() { firebase.auth().signOut() .then(function() { console.log( Signout successful! ) }, function(error) { console.log( Signout failed! ) }); }
When we start our app, we can sigin or signout by cpcking the two buttons. The console will confirm that the authentication is successful.
Advertisements