Files
examples/with-twitter-auth
2020-05-14 09:09:25 -07:00
..
2020-05-14 08:45:14 -07:00
2020-05-14 08:45:14 -07:00
2020-05-14 08:45:14 -07:00
2020-05-14 08:45:14 -07:00
2020-05-14 09:09:25 -07:00

Twitter Auth Example

Supports Expo iOS Supports Expo Android Supports Expo Web

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 yarn or npm install
  • Open index.js and replace consumer_key and consumer_secret with your Twitter app keys
  • Run node index.js to start the backend

Set up the app

  • Install with yarn or npm install
  • Open App.js and replace requestTokenURL and accessTokenURL with 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

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.

Read more about AuthSession here