angel_auth_twitter 2.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 50

auth_twitter #

angel_auth strategy for Twitter login.

See the example;

2.0.0 #

  • Angel 2 + Dart 2 suppport.
  • Use package:twitter instead of package:twit.
  • Add TwitterAuthorizationException.
  • Add onError callback.

example/main.dart

import 'dart:convert';
import 'dart:io';
import 'package:angel_auth/angel_auth.dart';
import 'package:angel_auth_twitter/angel_auth_twitter.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';

class _User {
  final String handle;

  _User(this.handle);

  Map<String, dynamic> toJson() => {'handle': handle};
}

main() async {
  var app = Angel();
  var http = AngelHttp(app);
  var auth = AngelAuth<_User>(
    jwtKey: 'AUTH_TWITTER_SECRET',
    allowCookie: false,
    serializer: (user) async => user.handle,
    deserializer: (screenName) async {
      // Of course, in a real app, you would fetch
      // user data, but not here.
      return _User(screenName.toString());
    },
  );

  auth.strategies['twitter'] = TwitterStrategy(
    ExternalAuthOptions(
      clientId: Platform.environment['TWITTER_CLIENT_ID'] ??
          'qlrBWXneoSYZKS2bT4TGHaNaV',
      clientSecret: Platform.environment['TWITTER_CLIENT_SECRET'] ??
          'n2oA0ZtR7TzYincpMYElRpyYovAQlhYizTkTm2x5QxjH6mLVyE',
      redirectUri: Platform.environment['TWITTER_REDIRECT_URI'] ??
          'http://localhost:3000/auth/twitter/callback',
    ),
    (twit, req, res) async {
      var response = await twit.twitterClient
          .get('https://api.twitter.com/1.1/account/verify_credentials.json');
      var userData = json.decode(response.body) as Map;
      return _User(userData['screen_name'] as String);
    },
    (e, req, res) async {
      // When an error occurs, i.e. the user declines to approve the application.
      if (e.isDenial) {
        res.write("Why'd you say no???");
      } else {
        res.write("oops: ${e.message}");
      }
    },
  );

  app
    ..fallback(auth.decodeJwt)
    ..get('/', auth.authenticate('twitter'));

  app
    ..get(
      '/auth/twitter/callback',
      auth.authenticate(
        'twitter',
        AngelAuthOptions(
          callback: (req, res, jwt) {
            return res.redirect('/home?token=$jwt');
          },
        ),
      ),
    );

  app.get(
    '/home',
    chain([
      requireAuthentication<_User>(),
      (req, res) {
        var user = req.container.make<_User>();
        res.write('Your Twitter handle is ${user.handle}');
        return false;
      },
    ]),
  );

  app.logger = Logger('angel_auth_twitter')
    ..onRecord.listen((rec) {
      print(rec);
      if (rec.error != null) print(rec.error);
      if (rec.stackTrace != null) print(rec.stackTrace);
    });

  await http.startServer('127.0.0.1', 3000);
  print('Listening at ${http.uri}');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angel_auth_twitter: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angel_auth_twitter/angel_auth_twitter.dart';
  
Version Uploaded Documentation Archive
2.0.0 Apr 11, 2019 Go to the documentation of angel_auth_twitter 2.0.0 Download angel_auth_twitter 2.0.0 archive
1.0.2 Mar 17, 2017 Go to the documentation of angel_auth_twitter 1.0.2 Download angel_auth_twitter 1.0.2 archive
1.0.1 Feb 25, 2017 Go to the documentation of angel_auth_twitter 1.0.1 Download angel_auth_twitter 1.0.1 archive
1.0.0 Dec 23, 2016 Go to the documentation of angel_auth_twitter 1.0.0 Download angel_auth_twitter 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Apr 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, other

Primary library: package:angel_auth_twitter/angel_auth_twitter.dart with components: io.

Health suggestions

Fix lib/angel_auth_twitter.dart. (-0.50 points)

Analysis of lib/angel_auth_twitter.dart reported 1 hint:

line 104 col 9: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
angel_auth ^2.0.0 2.1.5
angel_framework ^2.0.0-alpha 2.0.0-rc.8
http >=0.11.0 <0.13.0 0.11.3+17 0.12.0+2
path ^1.0.0 1.6.2
twitter ^1.0.0 1.0.0
Transitive dependencies
angel_container 1.0.4
angel_http_exception 1.1.0
angel_model 1.0.2
angel_route 3.0.6
async 2.2.0
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.11
combinator 1.1.0
convert 2.1.1
crypto 2.0.6
dart2_constant 1.0.2+dart2
file 5.0.7
http2 1.0.0
http_parser 3.1.3
http_server 0.9.8+1
intl 0.15.8
matcher 0.12.5
merge_map 1.0.2
meta 1.1.7
mime 0.9.6+2
mock_request 1.0.5
oauth 0.4.0
pointycastle 1.0.1
quiver 2.0.3
quiver_hashcode 2.0.0
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
tuple 1.0.2
typed_data 1.1.6
uuid 2.0.1
Dev dependencies
logging ^0.11.0 0.11.3+2
pedantic ^1.0.0 1.5.0