simple_auth 2.0.5

  • Readme
  • Changelog
  • Installing
  • 83

Simple Auth for Dart/Flutter #

Most apps need to make API calls. Every API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authentication into the API so you dont need to deal with it.

This is a port of Clancey.SimpleAuth for Dart and Flutter

The network/api part including the generator was based off of Chopper by Hadrien Lejard

iOS: Build status

Android: Build status

Providers #

Current Built in Providers #

  • Azure Active Directory
  • Amazon
  • Dropbox
  • Facebook
  • Github
  • Google
  • Instagram
  • Linked In
  • Microsoft Live Connect
  • And of course any standard OAuth2/Basic Auth server.

Usage #

var api = new simpleAuth.GoogleApi(
      "google", "client_id",clientSecret: "clientSecret",
      scopes: [
        "https://www.googleapis.com/auth/userinfo.email",
        "https://www.googleapis.com/auth/userinfo.profile"
      ]);
var request = new Request(HttpMethod.Get, "https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
var userInfo = await api.send<UserInfo>(request);

That's it! If the user is not logged in, they will automatically be prompted. If their credentials are cached from a previous session, the api call proceeds! Expired tokens even automatically refresh.

Serialization #

Json objects will automatically serialize if you conform to JsonSerializable

If you use the generator and you objects have the factory factory JsonSerializable.fromJson(Map<String, dynamic> json) your api calls will automatically Serialize/Deserialize

Or you can pass your own Converter to the api and handle conversion yourself.

Generator #

Dart #

pub run build_runner build

flutter #

flutter packages pub run build_runner build

Add the following to your pubspec.yaml

dev_dependencies:
  simple_auth_generator: 
  build_runner: ^0.8.0

The Generator is not required, however it will make things magical.

@GoogleApiDeclaration("GoogleTestApi","client_id",clientSecret: "client_secret", scopes: ["TestScope", "Scope2"])
abstract class GoogleTestDefinition {
  @Get(url: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json")
  Future<Response<GoogleUser>> getCurrentUserInfo();
}

will generate a new Api for you that is easy to use!

var api = new GoogleTestApi("google");
var user = await getCurrentUserInfo();

For more examples, check out the example project

Auth Storage and Show Authenticator #

If you are using the simple_auth_flutter plugin this is handled for you. Ignore this section unless you want to override default behavior.

If you do not implement your own Auth Storage, tokens are only stored in memory and do not persist through sessions.

You need to implement the ShowAuthenticator callback to present the login UI.

[2.0.5] - 04-28-2019

  • Bug fixes. Thanks @sjmcdowall

[2.0.4] - 02-28-2019

  • Added Azure A2D V2

[2.0.1] - 01-28-2019

  • Fixed Dropbox and Azure API, ForcesInstagram to use the embeded browsers

[2.0] - 11-09-2018

  • The rest of the providers now require a redirect
  • Cleaned up dependencies

[1.0.7] - 09-26-2018

  • Fixed remaining provider logins

[1.0.6] - 09-04-2018

  • Removed remaining redirect. Code Formatting.

[1.0.4] - 09-04-2018

  • Breaking Change: Redirects are now required. This prevents user error.
  • Fixed crash in Google Auth.

[1.0.2] - 08-30-2018

  • Fixed crash in Microsoft Live and Azure Auth

[1.0.1] - 07-30-2018

  • OAuth Bug fix

[0.0.1] - 07-05-2018

  • Initial release of Simple Auth

Use this package as a library

1. Depend on it

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


dependencies:
  simple_auth: ^2.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:simple_auth/simple_auth.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
77
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:simple_auth/simple_auth.dart.

Health suggestions

Fix lib/src/annotations.dart. (-11.33 points)

Analysis of lib/src/annotations.dart reported 24 hints, including:

line 22 col 22: Use = to separate a named parameter from its default value.

line 86 col 19: Use = to separate a named parameter from its default value.

line 102 col 19: Use = to separate a named parameter from its default value.

line 118 col 19: Use = to separate a named parameter from its default value.

line 134 col 19: Use = to separate a named parameter from its default value.

Fix lib/src/oauth/oauthApi.dart. (-5.36 points)

Analysis of lib/src/oauth/oauthApi.dart reported 11 hints, including:

line 72 col 11: DO use curly braces for all flow control structures.

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

line 84 col 7: DO use curly braces for all flow control structures.

line 86 col 7: DO use curly braces for all flow control structures.

line 88 col 7: DO use curly braces for all flow control structures.

Fix lib/src/basic/basicAuthApi.dart. (-1.99 points)

Analysis of lib/src/basic/basicAuthApi.dart reported 4 hints:

line 43 col 7: DO use curly braces for all flow control structures.

line 45 col 7: DO use curly braces for all flow control structures.

line 47 col 7: DO use curly braces for all flow control structures.

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

Fix additional 8 files with analysis or formatting issues. (-6.49 points)

Additional issues in the following files:

  • lib/src/providers/google.dart (3 hints)
  • lib/src/api/authenticatedApi.dart (2 hints)
  • lib/src/api/webAuthenticator.dart (2 hints)
  • lib/src/request.dart (2 hints)
  • lib/src/basic/basicAuthAccount.dart (1 hint)
  • lib/src/oauth/oauthApiKeyApi.dart (1 hint)
  • lib/src/providers/facebook.dart (1 hint)
  • lib/src/providers/github.dart (1 hint)

Maintenance suggestions

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 simple_auth.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.0.0-dev <3.0.0
http >=0.11.0 <0.13.0 0.12.0+2
meta ^1.1.2 1.1.7
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.3.0