silent_auth 0.0.8

  • Readme
  • Changelog
  • Installing
  • 49

silent_auth #

silent_auth is a package that enables seamless user experience for single page web applications using OAuth 2.0 - OpenID Connect with the implicit flow. More information can be found at Silent Authentication.

In summary, this package

  • Performs login by redirecting user to an identity server's authorize endpoint
  • Performs logout by redirecting user to an identity server's end session endpoint
  • Periodically renews access/ID tokens in the background using iframe

Usage #

This package is usually used together with an idle tracking library/package such as idle_tracker.

import 'package:silent_auth/silent_auth.dart';
import 'package:idle_tracker/idle_tracker.dart';

final silentAuth = new SilentAuth(
    baseIdentityUri: 'https://your-identity-server.com/connect',
    clientId: 'admin',
    scope: 'openid api',
    redirectUri: 'http://localhost:12345/index.html',
    silentRedirectUri: 'http://localhost:12345/silent_auth.html',
    onRenew: (auth) => requestHeaders['Authorization'] = 'Bearer ${auth.accessToken}');

// Request headers for making API calls.
final requestHeaders = {
  'Accept': 'application/json',
  'Content-Type': 'application/json; charset=UTF-8',
};
  
void logIn() {
  // Pre-login tasks may be done here.
  
  silentAuth.logIn();
}

void logOut() {
  // Pre-logout tasks may be done here.
    
  silentAuth.logOut();
}

void loadData() {
  // Make some API call using [requestHeaders].
}
    
void main() {
  // Initializes silent authentication.
  silentAuth.init();
  
  // If the access token doesn't exist or has expired, redirect user to the login page.
  if (!silentAuth.isAccessTokenValid) {
    logIn();
    return;
  }
  
  // Set up an idle tracker to automatically log the user out after 30
  // minutes of inactivity.
  new IdleTracker(
      timeout: const Duration(minutes: 30),
      startsAsIdle: true,
      onIdle: logOut)
    ..start();
  
  loadData();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.0.8 #

  • Improve README.md
  • Update documentation

0.0.7 #

  • BREAKING CHANGE: This version requires Dart 2.0.0 or later
  • Fixed a bug where accessing Token.header will throw
  • Added some tests

0.0.6 #

  • Fixed a bug that happens when logOut is called due to the new Token type

0.0.5 #

  • refactoring: utils.dart was moved to /lib and no longer contains functions used internally
  • Added class Token, which represents an access or ID token
  • BREAKING CHANGE: SilentAuth.accessToken and SilentAuth.idToken are now of type Token rather than String.

0.0.4 #

  • Fixed a bug in which the token renewal is not properly scheduled the first time

0.0.3 #

  • Fixed a bug causing post_logout_redirect_uri not to be displayed in the logged-out page

0.0.2 #

  • Fixed a bug causing utils.callEndpoint to fail when compiled to JS

0.0.1 #

  • Initial version

Use this package as a library

1. Depend on it

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


dependencies:
  silent_auth: ^0.0.8

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

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

  • Dart: 2.8.4
  • pana: 0.13.9+1

Analysis suggestions

Package not compatible with runtime flutter-native of android

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime flutter-native of ios

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime flutter-native of linux

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime flutter-native of macos

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime flutter-native of windows

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime native-aot

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

Package not compatible with runtime native-jit

Because of the import of dart:html via the import chain package:silent_auth/silent_auth.dart->package:silent_auth/utils.dart->dart:html

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

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
build_runner ^0.10.0
build_web_compilers ^0.4.0
test ^1.3.0