simple_auth_flutter 2.0.0

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

Simple Auth Pub 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 Flutter adapter for the port of Clancey.SimpleAuth to Dart, (simple_auth)[https://github.com/Clancey/simple_auth]

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.

Flutter Setup

Import package:simple_auth/simple_auth.dart and package:simple_auth_flutter/simple_auth_flutter.dart Call SimpleAuthFlutter.init(); in your Main.Dart. Now simple_auth can automatically present your login UI.

Redirect

Google requires the following redirect: com.googleusercontent.apps.YOUR_CLIENT_ID

Simple Auth by default uses SFSafari on iOS and Chrome Tabs on Android.

This means normal http redirects cannot work. You will need to register a custom scheme for your app as a redirect. For most providers, you can create whatever you want. i.e. com.myapp.foo:/redirct

Android Manifest

you would then add the following to your Android manifest

<activity android:name="clancey.simpleauth.simpleauthflutter.SimpleAuthCallbackActivity" >
    <intent-filter android:label="simple_auth">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.myapp.foo" />
    </intent-filter>
</activity>

iOS

on iOS you need the following in your app delegate.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    return [SimpleAuthFlutterPlugin checkUrl:url];
}

For iOS 11 and higher, you don't need to do anything else. On older iOS versions the following is required in the info.plist

	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>com.myapp.foo</string>
			</array>
			<key>CFBundleURLName</key>
			<string>myappredirect</string>
		</dict>
	</array>
	

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 api.getCurrentUserInfo();

For more examples, check out the example project

Contributor

TODO

  • Add more documentation
  • Add native flutter providers for google

[2.0] - 11-09-2018

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

[1.0.7] - 09-26-2018

  • Fixed Canceling with Embedded Browser on iOS
  • Now works properly with Swift Flutter apps

[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.3] - 08-30-2018

  • Updated dependencies

[1.0.2] - 08-30-2018

  • Updated dependencies

[1.0.1] - 07-30-2018

  • OAuth Bug fix

[0.0.1] - 07-05-2018

  • Initial release of Simple Auth

example/README.md

example

A new Flutter project.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  simple_auth_flutter: ^2.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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:simple_auth_flutter/simple_auth_flutter.dart';
  
Version Uploaded Documentation Archive
2.0.0 Nov 9, 2018 Go to the documentation of simple_auth_flutter 2.0.0 Download simple_auth_flutter 2.0.0 archive
1.0.7 Sep 27, 2018 Go to the documentation of simple_auth_flutter 1.0.7 Download simple_auth_flutter 1.0.7 archive
1.0.6 Sep 5, 2018 Go to the documentation of simple_auth_flutter 1.0.6 Download simple_auth_flutter 1.0.6 archive
1.0.5 Sep 4, 2018 Go to the documentation of simple_auth_flutter 1.0.5 Download simple_auth_flutter 1.0.5 archive
1.0.4 Sep 4, 2018 Go to the documentation of simple_auth_flutter 1.0.4 Download simple_auth_flutter 1.0.4 archive
1.0.3 Aug 30, 2018 Go to the documentation of simple_auth_flutter 1.0.3 Download simple_auth_flutter 1.0.3 archive
1.0.2 Aug 30, 2018 Go to the documentation of simple_auth_flutter 1.0.2 Download simple_auth_flutter 1.0.2 archive
1.0.1 Jul 30, 2018 Go to the documentation of simple_auth_flutter 1.0.1 Download simple_auth_flutter 1.0.1 archive
1.0.0 Jul 30, 2018 Go to the documentation of simple_auth_flutter 1.0.0 Download simple_auth_flutter 1.0.0 archive
0.0.1 Jul 5, 2018 Go to the documentation of simple_auth_flutter 0.0.1 Download simple_auth_flutter 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
85
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]
92
Learn more about scoring.

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

  • Dart: 2.1.0-dev.7.1.flutter-b99bcfd309
  • pana: 0.12.5
  • Flutter: 0.10.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
flutter 0.0.0
simple_auth ^2.0.0 2.0.0
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http 0.12.0
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8