easy_oauth 1.0.0

Words

Flutter OAuth #

Another Flutter OAuth package for simplifying OAuth operations

Originally tested with small collection of services such as:

If there is an issue with a specific service you are trying to work with, feel free to file an issue. :)

Authorizing an application #

Performing authorization for an API is pretty easy, in most cases you just need to do the following:

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, Your Applications Client ID, Your Applications 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, when using the Spotify API you need to set the contentType to 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 (yet!). For example, when using the GitHub API you may send a state string and scopes to request 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 services may require you to send a custom header, such as Authorization.
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 may simply call the performAuthorization() method like so to retrieve a Token:

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

Installing #

Add the following you your pubspec.yaml dependancies:

dependencies:
  easy_oauth: "^1.0.0"

Thanks to #

Kevin Seqaud for his awesome blog post on Flutter OAuth

The Flutter Webview plugin, which carrys this library on it's back.

Use this package as a library

1. Depend on it

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


dependencies:
  easy_oauth: ^1.0.0

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

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

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Health issues and suggestions

Document public APIs. (-1 points)

79 out of 79 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/auth_code_information.dart.

Run flutter format to format lib/auth_code_information.dart.

Format lib/flutter_auth.dart.

Run flutter format to format lib/flutter_auth.dart.

Format lib/model/config.dart.

Run flutter format to format lib/model/config.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

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

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

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 easy_oauth.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_webview_plugin ^0.3.7 0.3.9+1
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7 1.1.8
path 1.6.4
pedantic 1.9.0
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