パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.1

aad_oauth

Azure Active Directory OAuth2 v2.0 エンドポイントに対するユーザー認証を実行するための Flutter OAuth パッケージ。

30日間ダウンロード
2.1万
いいね数
167
Pub ポイント
60

パッケージをインストール

flutter pub add aad_oauth

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

aad_oauth パッケージは、OAuth2 v2.0 プロトコルを使用して Azure Active Directory とのユーザー認証を簡素化することを目的とした Flutter ライブラリです。Microsoft のクラウドプラットフォームを通じたアイデンティティ管理を必要とするアプリケーション向けに、セキュアなログインフローを提供します。このパッケージはトークンの取得、更新、ストレージを処理し、Azure AD で保護された API とのシームレスな統合を可能にします。エンタープライズ環境をターゲットとする開発者向けに構築されており、Flutter アプリにおける現代的な認証基準の実装を容易にします。

用途

  • エンタープライズ向け Flutter アプリへの Azure AD ログインの統合
  • OAuth2 トークンを使用したAPIアクセスのセキュリティ確保
  • Microsoft ID を通じたシングルサインオン (SSO) の有効化
  • トークンの更新と永続性の処理
  • 規制産業向けのコンプライアンス対応IDワークフローの構築

主な機能

  • Azure AD の OAuth2 v2.0 サポート
  • セキュアなトークンの取り扱いと保存
  • 組み込みトークン更新ロジック
  • Azure AD アプリの簡単な構成
  • クロスプラットフォーム互換性(iOS、Android、Web)
  • 強化されたセキュリティのためのPKCEフローをサポート

適している対象

  • エンタープライズモバイルアプリ開発者
  • Microsoft ID統合を必要とするFlutterアプリ
  • 企業の認証ポリシーに準拠する必要があるアプリ
  • Azure AD をIDプロバイダーとして使用する開発者
  • 最小限のボイラープレートで安全かつスケーラブルな認証を必要とするプロジェクト

注意事項

  • 適切な Azure AD アプリケーション登録が必要です
  • 正しいリダイレクトURIの設定が必要です
  • Azure AD OAuth2 v2.0 エンドポイントに限定
  • 組み込みのUIがありません。カスタムまたはサードパーティのログイン画面が必要です。
  • iOS/Android/Web 用にプラットフォーム固有の設定が必要になる場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Azure Active Directory OAuth

pub package License: MIT style: effective dart pub points Join the chat

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.

If your app does not have the android.permission.INTERNET permission you must add it to the AndroidManifest <uses-permission android:name="android.permission.INTERNET"/>

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 is Optional as a default is calculated based on app type/web location
    redirectUri: "your redirect url available in azure portal",
    navigatorKey: navigatorKey,
    webUseRedirect: true, // default is false - on web only, forces a redirect flow instead of popup auth
    //Optional parameter: Centered CircularProgressIndicator while rendering web page in WebView
    loader: Center(child: CircularProgressIndicator()),
    postLogoutRedirectUri: 'http://your_base_url/logout', //optional
  );

  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:

final result = await oauth.login();
result.fold(
  (failure) => showError(failure.toString()),
  (token) => showMessage('Logged in successfully, your access token: $token'),
);
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();
Web Usage

For web you also have to add some lines to your index.html (see the index.html in the example applications):

<head>
  <script type="text/javascript" src="https://alcdn.msauth.net/browser/2.13.1/js/msal-browser.min.js"
    integrity="sha384-2Vr9MyareT7qv+wLp1zBt78ZWB4aljfCTMUrml3/cxm0W81ahmDOC6uyNmmn0Vrc"
    crossorigin="anonymous"></script>
  <script src="assets/packages/aad_oauth/assets/msalv2.js"></script>
</head>

Note that when using redirect flow on web, the login() call will not return if the user has not logged in yet because the page is redirected and the app is destroyed until login is complete. Your application must take care of calling login() again once reloaded to complete the login process within the flutter application - if login was successful, this second call will be fast, and will not cause another redirection.

When using redirecting logins with the example application, you will need to click on the login button again following a successful login to see the token details.

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", // Note: this is the default for Mobile
    // clientSecret: "YOUR_CLIENT_SECRET", // Note: do not include secret in publicly available applications
    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.

ADFS Usage

This library only suports ADFS authentication for Flutter mobile applications, not web builds.

Register an ADFS app = Windows Server ADFS Application Setup.

Use redirect URI: https://login.live.com/oauth20_desktop.srf.

Use a configuration like:

static final Config adfsAuthConfig = Config(
  customAuthorizationUrl:
      'https://adfs.your-domain.com/adfs/oauth2/authorize',
  customTokenUrl:
      'https://adfs.your-domain.com/adfs/oauth2/token',
  clientId: 'YOUR_CLIENT_ID',
  scope:
      'openid OTHER_SCOPES_YOU_NEED',
  navigatorKey: navigatorKey,
  loader: const SizedBox(),
);

Installation

Add the following to your pubspec.yaml dependencies:

dependencies:
  aad_oauth: "^1.0.1"

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.

カテゴリー

依存関係

依存関係一覧 7 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。