flutter_generic_oauth 1.0.2

This library has been forked from HithereJoe. As the library was unfortunately deprecated, we updated it to Dart 2. The following ReadMe is from the original contributors.

Flutter OAuth #

A Flutter OAuth package for performing user authentication for your apps.

I've tested this with a small collection of APIs (Buffer, Strava, Unsplash and GitHub). If there is an issue with an API you are trying to work with, please file an issue :)

Authorizing an application #

Performing authorization for an API is straight forward using this library. In most cases you will just be able to use the following approach:

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    "https://unsplash.com/oauth/authorize",
    "https://unsplash.com/oauth/token",
    "YOUR_CLIENT_ID",
    "YOUR_CLIENT_SECRET",
    "http://localhost:8080",
    "code"));

This allows you to pass in an Authorization URL, Token request URL, Client ID, Client Secret, Redirect URL and the response type. This should satisfy most requests, but if not then you can pass in other optional parameters for:

  • contentType - This allows you to change the content type for the request. For example, for Spotify API authorization you need to use "application/x-www-form-urlencoded"
final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    contentType: "application/x-www-form-urlencoded"));
  • parameters - Add your own parameters that this library may not support out-of-the-box. For example, with the GitHub API you can send a state string and scopes to gain authorization for
Map<String, String> customParameters = {"state": "SOME_RANDOM_SECURE_STRING", "scope": "public_repo"};

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    parameters: customParameters));
  • headers - Some APIs require you to send custom headers, such as an Authorization Header. Use this parameter if you require this
Map<String, String> headers = {"Authorization": "Basic SOME_BASE_64_STRING"};

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    headers: headers));

Then once you have an OAuth instance, you can simply call the performAuthorization() method like so to retrieve a Token instance:

Token token = await flutterOAuth.performAuthorization();
String accessToken = token.accessToken;

Installing #

Add the following you your pubspec.yaml dependancies:

dependencies:
  flutter_oauth: "^0.0.1"

Thanks to #

Kevin Seqaud for his awesome blog post on Flutter OAuth https://medium.com/@segaud.kevin/facebook-oauth-login-flow-with-flutter-9adb717c9f2e

The author, Hadrien Lejard, behind the:

The Gitter-Dart repo, where a lot of this library was influenced

and the Flutter Webview plugin, which this library uses

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_generic_oauth: ^1.0.2

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:flutter_generic_oauth/lib/auth_code_information.dart';
import 'package:flutter_generic_oauth/lib/facebook/facebook.dart';
import 'package:flutter_generic_oauth/lib/facebook/facebook_state.dart';
import 'package:flutter_generic_oauth/lib/flutter_auth.dart';
import 'package:flutter_generic_oauth/lib/model/config.dart';
import 'package:flutter_generic_oauth/lib/oauth.dart';
import 'package:flutter_generic_oauth/lib/oauth_token.dart';
import 'package:flutter_generic_oauth/lib/token.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
45
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

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

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.36 points)

89 out of 91 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/lib/auth_code_information.dart.

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

Format lib/lib/facebook/facebook.dart.

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

Format lib/lib/facebook/facebook_state.dart.

Run flutter format to format lib/lib/facebook/facebook_state.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/lib/flutter_auth.dart (Run flutter format to format lib/lib/flutter_auth.dart.)
  • lib/lib/model/config.dart (Run flutter format to format lib/lib/model/config.dart.)
  • lib/lib/oauth.dart (Run flutter format to format lib/lib/oauth.dart.)
  • lib/lib/oauth_token.dart (Run flutter format to format lib/lib/oauth_token.dart.)
  • lib/lib/token.dart (Run flutter format to format lib/lib/token.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (flutter_facebook_login, http).

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://codeing.io was unreachable.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_generic_oauth.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

The package description is too short. (-5 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0-dev.9.4 <3.0.0
flutter 0.0.0
flutter_facebook_login ^1.1.1 1.2.0 2.0.1
flutter_webview_plugin ^0.3.0+2 0.3.8
http ^0.11.3+13 0.11.3+17 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8