flutter_app_auth_wrapper 0.1.1+3

pub package

flutter_app_auth_wrapper #

The package wraps App Auth, an OAuth 2.0 client for native iOS and Android app development, into Flutter. You can use the package to implements Oauth2 Authentication Code Flow in your Flutter app.

Usage #

Start oauth flow

FlutterAppAuthWrapper.startAuth(
                      AuthConfig(
                        clientId: clientId,
                        clientSecret: clientSecret,
                        redirectUrl: redirectURL,
                        state: "login",
                        prompt: "consent",
                        endpoint: 
                        AuthEndpoint(auth: authEndpoint, token: tokenEndpoint),
                        scopes: [
                          "user_account_status",
                          "user_territory",
                          "user_profile"
                        ],
                      ),
                    );

Listen result event by FlutterAppAuthWrapper.eventStream().

StreamBuilder(
                initialData: "init state",
                stream: FlutterAppAuthWrapper.eventStream(),
                builder: (context, snapshot) {
                  if (snapshot.hasError) {
                    var error = snapshot.error as PlatformException;
                    return Text("[Error] ${error.message}: ${error.details}");
                  } else {
                    return Text(snapshot.data.toString());
                  }
                },
              )

Setting Up #

Android #

Only support AndroidX.

Add following properties into gradle.properties to enable AndroidX support.

android.enableJetifier=true
android.useAndroidX=true

You need to do additional configuration in your AndroidManifest.xml to let your app to accept the net.openid.appauth.RedirectUriReceiverActivity and github.showang.flutterappauthwrapper.OAuthActivity intent. For example:

<application
    xmlns:tools="http://schemas.android.com/tools">
    
    ...

    <activity
        android:name="net.openid.appauth.RedirectUriReceiverActivity"
        tools:node="replace">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="ACCEPTED_HOST"
                android:scheme="YOUR_APP_SCHEME" />
        </intent-filter>


    </activity>

    <activity
        android:name="github.showang.flutterappauthwrapper.OAuthActivity"
        android:configChanges="orientation|screenSize"
        android:theme="@style/Theme.AppCompat.Translucent" />    
</application> 

Add translucent theme style to res/values.

<style name="Theme.AppCompat.Translucent" parent="@style/Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Replace ACCEPTED_HOST and YOUR_APP_SCHEME depends on your app's definition.

For further information, please visit the page of AppAuth Android.

iOS #

You need to add your own custom URL scheme to the Info.plist file.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleIdentifier</key>
        <string></string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>your_custom_url_scheme</string>
        </array>
    </dict>
</array>

You also need to let the app delegate to handle incoming open URL requests for devices running iOS 9 or prior versions, if you want to support them.

override func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    if (SwiftFlutterAppAuthWrapperPlugin.authFlow?.resumeExternalUserAgentFlow(with: url) ?? false) {
        SwiftFlutterAppAuthWrapperPlugin.authFlow = nil
        return true
    }

    return false
}

For further information, please visit the page of AppAuth iOS.

Use this package as a library #

1. Depend on it #

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

dependencies:
  flutter_app_auth_wrapper: {last_version}

2. Install it #

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or 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:flutter_app_auth_wrapper/flutter_app_auth_wrapper.dart';

0.0.1 #

  • TODO: Describe initial release.

example/README.md

flutter_app_auth_wrapper_example #

Demonstrates how to use the flutter_app_auth_wrapper plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_app_auth_wrapper: ^0.1.1+3

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_app_auth_wrapper/flutter_app_auth_wrapper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

39 out of 39 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.

Maintenance suggestions

The package description is too short. (-20 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.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin