msal_js 0.3.2 copy "msal_js: ^0.3.2" to clipboard
msal_js: ^0.3.2 copied to clipboard

outdated

A Dart wrapper for the 'Microsoft Authentication Library Preview for JavaScript (MSAL.js)'.

example/example.dart

import 'dart:async';
import 'package:msal_js/msal_js.dart';

// This example is based on
// https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/README.md#usage.

String idToken;
String accessToken;

Future<void> main() async {
  // Instantiate a UserAgentApplication with a client ID and callback
  final userAgentApplication = new UserAgentApplication('your_client_id', null, authCallback);

  // Login the user via a popup and get an access token
  final graphScopes = <String>['user.read', 'mail.send'];

  try {
    idToken = await userAgentApplication.loginPopup(graphScopes);

    print('Successfully received ID token from login.');

    try {
      accessToken = await userAgentApplication.acquireTokenSilent(graphScopes);

      print('Acquired access token silently.');
    } on MsalException {
      // Failed to acquire token silently, send an interactive request instead
      try {
        accessToken = await userAgentApplication.acquireTokenPopup(graphScopes);

        print('Acquired access token after interactive prompt.');
      } on MsalException catch (ex) {
        // Acquire token failure
        print(ex);
      }
    }
  } on MsalException catch (ex) {
    // Login failure
    print(ex);
  }
}

void authCallback(String errorDescription, String token, String error, 
  String tokenType, String userState
) {
  if (token != null) {
    // Login was successful!
    print('Success in auth calback!');
  } else {
    // An error occurred while logging in...
    print('$error:$errorDescription');
  }
}
19
likes
30
pub points
89%
popularity

Publisher

unverified uploader

A Dart wrapper for the 'Microsoft Authentication Library Preview for JavaScript (MSAL.js)'.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

js

More

Packages that depend on msal_js