flutter_aad_oauth 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

Azure Active Directory OAuth #

Forked from Earlybyte.aad_oauth.

A Flutter OAuth package for performing user authentication against Azure Active Directory OAuth2 v2.0 endpoint. Forked from hitherejoe.FlutterOAuth.

Supported Flows:

Usage #

For using this library you have to create an azure app at the Azure App registration portal. Use native app as platform type (with callback URL: https://login.live.com/oauth20_desktop.srf).

Afterwards you have to initialize the library as follow:

final Config config = new Config(
  "openid profile offline_access",
  "your redirect url available in azure portal");
final AadOAuth oauth = new AadOAuth(config);

This allows you to pass in an tenant ID, client ID, scope and redirect url.

Then once you have an OAuth instance, you can call login() and afterwards getAccessToken() or getIdToken() or the getRefreshToken() to retrieve an access token or the id token or the refresh token:

await oauth.login();
String accessToken = await oauth.getAccessToken();
String idToken = await oauth.getIdToken();
String refreshToken = await oauth.getRefreshToken();
String tokenType = await oauth.getTokenType();
DateTime issueTimeStamp = await oauth.getIssueTimeStamp();
DateTime refreshToken = await oauth.getExpireTimeStamp();
int refreshToken = await oauth.getExpiresIn();

You can also call getAccessToken() directly. It will automatically login and retrieve an access token. You can also call getIdToken() directly. It will automatically login and retrieve an id token. You can also call getRefreshToken() directly. It will automatically login and retrieve a refresh token. You can also call getTokenType() directly. It will retrieve the token type. You can also call getIssueTimeStamp() directly. It retrieve the Issue Time Stamp. You can also call getExpireTimeStamp() directly. It retrieve the Expire Time Stamp. You can also call getExpiresIn() directly. It retrieve the value of when the token expires in.

Tokens are stored in Keychain for iOS or Keystore for Android. To destroy the tokens you can call logout():

await oauth.logout();

0.0.3 #

  • Update Read.me
  • Implementing new methods to retrieve refresh toekn and other informations from the token

0.0.2 #

  • Update Read.me

0.0.1 #

  • Initial release
  • Same package as aad_oauth except this one adds a new method to retrive the id token


import 'package:flutter_aad_oauth/flutter_aad_oauth.dart';
import 'package:flutter_aad_oauth/model/config.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  initState() {

  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'AAD OAuth Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      home: new MyHomePage(title: 'AAD OAuth Home'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  _MyHomePageState createState() => new _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  static final Config config = new Config(
    "openid profile offline_access",
  final FlutterAadOauth oauth = FlutterAadOauth(config);

  Widget build(BuildContext context) {
    // adjust window size for browser login
    var screenSize = MediaQuery.of(context).size;
    var rectSize =
        Rect.fromLTWH(0.0, 25.0, screenSize.width, screenSize.height - 25);

    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      body: ListView(
        children: <Widget>[
            title: Text(
              "AzureAD OAuth",
              style: Theme.of(context).textTheme.headline,
            leading: Icon(Icons.launch),
            title: Text('Login'),
            onTap: () {
            leading: Icon(Icons.delete),
            title: Text('Logout'),
            onTap: () {

  void showError(dynamic ex) {

  void showMessage(String text) {
    var alert = new AlertDialog(content: new Text(text), actions: <Widget>[
      new FlatButton(
          child: const Text("Ok"),
          onPressed: () {
    showDialog(context: context, builder: (BuildContext context) => alert);

  void login() async {
    try {
      await oauth.login();
      String accessToken = await oauth.getAccessToken();
      showMessage("Logged in successfully, your access token: $accessToken");
    } catch (e) {

  void logout() async {
    await oauth.logout();
    showMessage("Logged out");

Use this package as a library

1. Depend on it

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

  flutter_aad_oauth: ^0.0.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_aad_oauth/flutter_aad_oauth.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health issues and suggestions

Document public APIs. (-1 points)

107 out of 107 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

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.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_secure_storage ^3.2.0 3.3.3
flutter_webview_plugin ^0.3.0+2 0.3.11
http ^0.12.0 0.12.1
shared_preferences ^0.5.2 0.5.7+3
Transitive dependencies
charcode 1.1.3
collection 1.14.12
flutter_web_plugins 0.0.0
http_parser 3.1.4
meta 1.1.8
path 1.7.0
pedantic 1.9.0
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies