aad_oauth 0.4.0-beta.1 copy "aad_oauth: ^0.4.0-beta.1" to clipboard
aad_oauth: ^0.4.0-beta.1 copied to clipboard

A Flutter OAuth package for performing user authentication against Azure Active Directory OAuth2 v2.0 endpoint.

Azure Active Directory OAuth #

pub package License: MIT style: effective dart pub points [![Join the chat at https://gitter.im/Earlybyte/aad_oauth](https://badges.gitter.im/Earlybyte/aad_oauth.svg)](https://gitter.im/Earlybyte/aad_oauth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A Flutter OAuth package for performing user authentication against Azure Active Directory OAuth2 v2.0 endpoint. Forked from hitherejoe.FlutterOAuth.

Supported Flows:

Usage #

For using this library you have to create an azure app at the Azure App registration portal. Use native app as platform type (with callback URL: https://login.live.com/oauth20_desktop.srf).

Your minSdkVersion must be >= 20 in android/app/build.gradle section android / defaultConfig to support webview_flutter. Version 19 may build but will likely fail at runtime.

Afterwards you must create a navigatorKey and initialize the library as follow:

  final navigatorKey = GlobalKey<NavigatorState>();

  // ... 

  static final Config config = new Config(
    tenant: "YOUR_TENANT_ID",
    clientId: "YOUR_CLIENT_ID",
    scope: "openid profile offline_access",
    redirectUri: "your redirect url available in azure portal",
    navigatorKey: navigatorKey,
  );

  final AadOAuth oauth = new AadOAuth(config);

This allows you to pass in an tenant ID, client ID, scope and redirect url.

The same navigatorKey must be provided to the top-level MaterialApp.

  // ...
  // Material App must be built with the same navigatorKey
  // to support navigation to the login route for interactive
  // authentication.
  // ...

    Widget build(BuildContext context) {
    return MaterialApp(
      // ...
      navigatorKey: navigatorKey,
      // ...
    );
  }

Then once you have an OAuth instance, you can call login() and afterwards getAccessToken() to retrieve an access token:

await oauth.login();
String accessToken = await oauth.getAccessToken();

Tokens are stored in Keychain for iOS or Keystore for Android. To destroy the tokens you can call logout():

await oauth.logout();

B2C Usage #

Setup your B2C directory - Azure AD B2C Setup.

Register an App on the previously created B2C directory - Azure AD B2C App Register.

Use native app as plattform type (with callback URL: https://login.live.com/oauth20_desktop.srf).

Create your user flows - Azure AD B2C User Flows

Add your Azure tenant ID, tenantName, client ID (ID of App), client Secret (Secret of App) and redirectUrl in the main.dart source-code:

  static final Config configB2Ca = new Config(
    tenant: "YOUR_TENANT_NAME",
    clientId: "YOUR_CLIENT_ID",
    scope: "YOUR_CLIENT_ID offline_access",
    redirectUri: "https://login.live.com/oauth20_desktop.srf",
    clientSecret: "YOUR_CLIENT_SECRET",
    isB2C: true,
    policy: "YOUR_USER_FLOW___USER_FLOW_A",
    tokenIdentifier: "UNIQUE IDENTIFIER A",
    navigatorKey: navigatorKey,
  );

Afterwards you can login and get an access token for accessing other resources. You can also use multiple configs at the same time.

Installation #

Add the following to your pubspec.yaml dependencies:

dependencies:
  aad_oauth: "^0.4.0"

Contribution #

Contributions can be submitted as pull requests and are highly welcomed. Changes will be bundled together into a release. You can find the next release date and past releases in the CHANGELOG file.

140
likes
0
pub points
97%
popularity

Publisher

verified publisherearlybyte.ch

A Flutter OAuth package for performing user authentication against Azure Active Directory OAuth2 v2.0 endpoint.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_secure_storage, http, js, pedantic, shared_preferences, webview_flutter

More

Packages that depend on aad_oauth