msal_auth_flutter 0.0.4 copy "msal_auth_flutter: ^0.0.4" to clipboard
msal_auth_flutter: ^0.0.4 copied to clipboard

Plugin for Microsoft AD Authenticator

example/lib/main.dart

import 'dart:ffi';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:msal_auth_flutter/msal_auth_flutter.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool? _isInitialized = false;
  final _msalAuthFlutterPlugin = MsalAuthFlutter();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    bool? isInitialized;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      isInitialized =
          await _msalAuthFlutterPlugin.initialize('assets/auth_config_single_account.json');
    } on PlatformException {
      isInitialized = false;
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    print("🚀 isInitialized: $isInitialized");
    if (!mounted) return;
    setState(() {
      print("🚀 setState called isInitialized: $isInitialized");
      _isInitialized = isInitialized;
    });
  }

  @override
  Widget build(BuildContext context) {
    print("🚀 build called isInitialized: $_isInitialized");
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Initialized: $_isInitialized\n'),
              TextButton(onPressed: (){
                 _msalAuthFlutterPlugin.acquireToken(List.filled(1, "user.read")).then((value) {
                   print("🚀 Token: $value");
                 }).catchError((err) {
                   print(err.toString());
                 });
              }, child: const Text("SignIn")),
              TextButton(onPressed: (){
                _msalAuthFlutterPlugin.logout().then((value) {
                  print("🚀 LoggedOut: $value");
                });
              }, child: const Text("SignOut"))
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
130
pub points
23%
popularity

Publisher

verified publishergigjamgo.in

Plugin for Microsoft AD Authenticator

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on msal_auth_flutter