stackexchange_auth 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

Stack Exchange Authentication #

Authentication for Stack Exchange in Flutter, using OAuth2.0 and V2.2 API.

This is pretty much a carbon copy of this wonderful package with a few adaptations, so props to @ishaanbahal.

So what do I do to use this? #

  • First, register on Stack Exchange here.
  • After that, head to this link to register a new application.
  • You can then get your client_id from your application's overview page.
  • If you wish to set up client side flow, enable both Client Side Flow and Desktop OAuth Redirect Uri options in your application's overview page. You can read more about that on the Desktop Aplications section here.

Cool, how do I use it? #

Here's a piece of code showing how you would implement the client side flow, taken from the example app.

MaterialButton(
    color: Colors.blue,
    onPressed: () async {
        await Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => Scaffold(
                    appBar: AppBar(
                    leading: CloseButton(),
                ),
                body: StackExchangeLoginView(
                    clientId: 'your_client_id',
                    redirectUrl: 'https://stackoverflow.com/oauth/login_success',
                    onError: (String error) {
                        print(error);
                    },
                    onTokenCapture: (token) {
                        print('${token.token} ${token.expiry}');
                        Navigator.pop(context, token);
                    },
                    clientSideFlow: true,
                ))),
        );
    },
    child: Text('Signup/Login', style: TextStyle(color:Colors.white),),
)

For server side token collection, you would have to implement a web server capable of returning the access token.

[0.0.1] - 01/06/2020 #

  • Added ability to signup using Stack Exchange.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:stackexchange_auth/stackexchange_auth.dart';

void main() => runApp(MyApp());

/// This is a client side token collection example, for server side, you need
/// to implement a web server capable of returning the access token.
/// For more info, please visit:
/// https://api.stackexchange.com/docs/authentication
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Stack Exchange Auth Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: _HomeWidget(),
    );
  }
}

class _HomeWidget extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('StackExchange Login Example'),
      ),
      body: Center(
        child: MaterialButton(
          color: Colors.blue,
          onPressed: () async {
            await Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => Scaffold(
                      appBar: AppBar(
                        leading: CloseButton(),
                      ),
                      body: StackExchangeLoginView(
                        clientId: 'your_client_id',
                        redirectUrl: 'https://stackoverflow.com/oauth/login_success',
                        onError: (String error) {
                          print(error);
                        },
                        onTokenCapture: (token) {
                          print('${token.token} ${token.expiry}');
                          Navigator.pop(context, token);
                        },
                        clientSideFlow: true,
                      ))),
            );
          },
          child: Text("Signup/Login", style: TextStyle(color:Colors.white),),
        ),
      ),
    );
  }

}

Use this package as a library

1. Depend on it

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


dependencies:
  stackexchange_auth: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:stackexchange_auth/stackexchange_auth.dart';
  
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]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/models/models.dart.

Run flutter format to format lib/models/models.dart.

Format lib/service/stackexchange_service.dart.

Run flutter format to format lib/service/stackexchange_service.dart.

Format lib/stackexchange_auth.dart.

Run flutter format to format lib/stackexchange_auth.dart.

Format lib/view/stackexchange_view.dart.

Run flutter format to format lib/view/stackexchange_view.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
http ^0.12.0+3 0.12.0+4
uuid ^2.0.4 2.0.4
webview_flutter ^0.3.19+2 0.3.19+9
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
http_parser 3.1.4
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test