msal_flutter 0.0.2 copy "msal_flutter: ^0.0.2" to clipboard
msal_flutter: ^0.0.2 copied to clipboard

outdated

A Microsoft Authentication Library wrapper for Android and iOS

example/lib/main.dart

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

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _output = 'NONE';

  PublicClientApplication pca;

  @override
  void initState() {
    super.initState();
    // initPlatformState();
    pca = PublicClientApplication("5913dfb1-7576-451c-a7ea-a7c5a3f8682a", authority: "https://login.microsoftonline.com/tfp/msalfluttertest.onmicrosoft.com/B2C_1_sisu");
  }

  Future<void> _acquireToken() async{
    String res;
    try{
      res = await pca.acquireToken(["https://msalfluttertest.onmicrosoft.com/msalbackend/user_impersonation"]);
    } on PlatformException {
      res = "Error getting token";
    }

    setState(() {
      _output = res;
    });
  }

  Future<void> _acquireTokenSilently() async {
    String res;
    try
    {
      res = await pca.acquireTokenSilent(["https://msalfluttertest.onmicrosoft.com/msalbackend/user_impersonation"]);
    } on PlatformException{
      res = "Error getting token silently!";
    }
    setState(() {
      _output = res;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              RaisedButton( onPressed: _acquireToken, 
                child: Text('AcquireToken()'),),
              RaisedButton( onPressed: _acquireTokenSilently,
                child: Text('AcquireTokenSilently()')),
              Text( _output)
            ],
          ),
        ),
      ),
    );
  }
}
28
likes
0
pub points
89%
popularity

Publisher

verified publishermuljin.com

A Microsoft Authentication Library wrapper for Android and iOS

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on msal_flutter