Twitter Auth Example
This example demonstrates how to implement a "login with Twitter" button, using a simple backend and the AuthSession module.
The purpose of the backend is to store the Twitter API keys without leaking this in your app. It also uses a node Twitter library called "Twitter Lite" to simplify the API calls.
🚀 How to use
- Create your own Twitter app
- Mark the checkbox
Enable Sign in with Twitter - Add the AuthSession's Callback URL (read more here)
Prepare the backend
- Go to directory
backend - Install with
yarnornpm install - Open
index.jsand replaceconsumer_keyandconsumer_secretwith your Twitter app keys - Run
node index.jsto start the backend
Set up the app
- Install with
yarnornpm install - Open
App.jsand replacerequestTokenURLandaccessTokenURLwith your backend URLs - Run
expo start, try it out
📁 File Structure
Expo Twitter Auth
├── app ➡️ Expo application with Twitter auth
└── backend ➡️ Simple API to fetch request and access tokens
📝 Notes
- Expo AuthSession docs
- Twitter Lite docs
- Login with Twitter guide
- Twitter authentication best practices
AuthSession callback URL
The AuthSession helps you with browser authentication, without the need of an additional server or website. To use this with Twitter authentication flows, we need to tell Twitter that the callback URLs are allowed.
Each Expo user has it's own URL for different projects, the basic structure of this URL is https://auth.expo.io/@your-username/your-expo-app-slug. If you are signed in as awesome-ppl, and your app is called meme-explorer, your URL looks like https://auth.expo.io/@awesome-ppl/meme-explorer.