azuread_login_view 0.6.1 copy "azuread_login_view: ^0.6.1" to clipboard
azuread_login_view: ^0.6.1 copied to clipboard

Provides one or more widgets to handle OAuth logins via Azure Active Directory.

example/lib/main.dart

// This file is part of the azuread_login_view distribution.
// Copyright (c) Next.e.GO Mobile SE, Aachen, Germany (https://e-go-mobile.com/)
//
// azuread_login_view is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, version 3.
//
// azuread_login_view is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import 'dart:convert';

import 'package:azuread_login_view/azuread_login_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;

void main() {
  runApp(const AzureADLoginViewExampleApp());
}

class AzureADLoginViewExampleApp extends StatelessWidget {
  const AzureADLoginViewExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(),
      home: const AzureADLoginViewExampleAppPage(),
    );
  }
}

class AzureADLoginViewExampleAppPage extends StatefulWidget {
  const AzureADLoginViewExampleAppPage({Key? key}) : super(key: key);

  @override
  State<AzureADLoginViewExampleAppPage> createState() =>
      _AzureADLoginViewExampleAppPageState();
}

class _AzureADLoginViewExampleAppPageState
    extends State<AzureADLoginViewExampleAppPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: FutureBuilder(
      future: _loadAppJSON(),
      builder: (ctx, snapshot) {
        if (snapshot.hasError) {
          return Center(
            child: Text("${snapshot.error}"),
          );
        } else if (snapshot.hasData) {
          final dynamic appJSON = snapshot.data;

          return AzureADLoginView(AzureADLoginViewOptionsBuilder()
              .setTenant(appJSON['tenant'])
              .setClientId(appJSON['clientId'])
              .setRedirectUri(appJSON['redirectUri'])
              .setLoginPolicy(appJSON['loginPolicy'])
              .setScopes(appJSON['scopes'].map<String>((e) => "$e"))
              .setOnNewTokens((context) {
            // ignore: avoid_print
            print('New tokens: ${context.tokens!.toMap()}');
          }).build());
        }

        return const Center(
          child: CircularProgressIndicator(),
        );
      },
    ));
  }

  Future<dynamic> _loadAppJSON() async {
    return jsonDecode(await rootBundle.loadString('assets/app.json'));
  }
}
1
likes
130
pub points
20%
popularity

Publisher

verified publishere-go-mobile.de

Provides one or more widgets to handle OAuth logins via Azure Active Directory.

Repository (GitHub)
View/report issues

Documentation

API reference

License

LGPL-3.0 (LICENSE)

Dependencies

flutter, http, webview_flutter

More

Packages that depend on azuread_login_view