Twitter oauth1 webview authentication for Flutter

pub

This Flutter package implements the 3-legged oauth authentication flow using webview_flutter.

Getting started

  • Get access to the Twitter API and create a 'Standalone App' in the Twitter developer portal
  • Enable OAuth 1.0a for your app
  • Enter a callback url. This can be any arbitrary url or just the scheme
    • e.g. app://

Usage

final TwitterAuthResult result = await TwitterAuth(
  consumerKey: 'your_consumer_key',
  consumerSecret: 'your_consumer_secret',
  callbackUrl: 'your_callback_url',
).authenticateWithTwitter(
  webviewNavigation: (Widget webview) => Navigator.of(context).push(
    MaterialPageRoute(
      builder: (_) => Scaffold(
        appBar: AppBar(title: const Text('Login')),
        body: webview,
      ),
    ),
  ),
);

result.when(
  success: (String token, String secret, String userId) {
    // user successfully authenticated
  },
  failure: (dynamic e, StackTrace? st) {
    // authentication failed
  },
  cancelled: () {
   // authentication has been cancelled by the user
  },
);

Additional information

For making requests to the Twitter API, check out dart_twitter_api