msal_auth_flutter 0.0.2 msal_auth_flutter: ^0.0.2 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");
});
}, child: const Text("SignIn")),
TextButton(onPressed: (){
_msalAuthFlutterPlugin.logout().then((value) {
print("🚀 LoggedOut: $value");
});
}, child: const Text("SignOut"))
],
),
),
),
);
}
}