azure_ad_oauth 0.3.0 copy "azure_ad_oauth: ^0.3.0" to clipboard
azure_ad_oauth: ^0.3.0 copied to clipboard

unlisted

Flutter Azure AD oAuth client for web, iOS nad Android.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Azure AD oAuth Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
        animation: OAuth.instance..config.context = context,
        builder: (context, _) {
          return Scaffold(
            appBar: AppBar(
              title: Text(widget.title),
            ),
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  if (OAuth.instance.isLoggedIn &&
                      !OAuth.instance.loginInProgress)
                    Text(
                        'WELCOME\n ${OAuth.instance.map['name']}\n(${OAuth.instance.map['preferred_username']})',
                        textAlign: TextAlign.center),
                  const SizedBox(height: 20),
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      fixedSize: const Size(200, 50),
                    ),
                    onPressed: OAuth.instance.loginInProgress
                        ? null
                        : () {
                            OAuth.instance.isLoggedIn
                                ? OAuth.instance
                                    .logout()
                                    .onError((error, stackTrace) {
                                    ScaffoldMessenger.of(context).showSnackBar(
                                        SnackBar(
                                            content: Text(error.toString())));
                                    setState(() {});
                                  })
                                : OAuth.instance
                                    .login()
                                    .onError((error, stackTrace) {
                                    ScaffoldMessenger.of(context).showSnackBar(
                                        SnackBar(
                                            content: Text(error.toString())));
                                    setState(() {});
                                  });
                          },
                    child: OAuth.instance.loginInProgress
                        ? const SizedBox(
                            width: 16,
                            height: 16,
                            child:
                                CircularProgressIndicator(color: Colors.white))
                        : Text(OAuth.instance.isLoggedIn ? 'Logout' : 'Login'),
                  ),
                ],
              ),
            ),
          );
        });
  }
}
0
likes
0
pub points
51%
popularity

Publisher

unverified uploader

Flutter Azure AD oAuth client for web, iOS nad Android.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, flutter_inappwebview, flutter_secure_storage, http, shared_preferences

More

Packages that depend on azure_ad_oauth