aad_oauth 패키지는 OAuth2 v2.0 프로토콜을 사용하여 Azure Active Directory와의 사용자 인증을 간소화하도록 설계된 Flutter 라이브러리입니다. Microsoft의 클라우드 플랫폼을 통해 신원 관리를 필요로 하는 애플리케이션을 위한 안전한 로그인 흐름을 제공합니다. 이 패키지는 토큰 획득, 갱신 및 저장을 처리하며, Azure AD 보호 API와의 원활한 통합을 지원합니다. 기업 환경을 대상으로 하는 개발자를 위해 제작되었으며, Flutter 앱에서 현대적인 인증 표준을 구현하는 과정을 간소화합니다.
사용 사례
기업용 Flutter 앱에 Azure AD 로그인 통합
OAuth2 토큰을 사용하여 API 액세스 보안화
Microsoft ID를 통한 단일 로그인(Single Sign-On, SSO) 활성화
토큰 갱신 및 지속성 처리
규제 산업을 위한 준수 가능한 신원 워크플로우 구축
주요 기능
Azure AD의 OAuth2 v2.0 지원
보안 토큰 처리 및 저장
내장된 토큰 갱신 로직
Azure AD 앱을 위한 간단한 구성
크로스 플랫폼 호환성 (iOS, Android, Web)
강화된 보안을 위한 PKCE 흐름을 지원합니다
적합한 대상
기업 모바일 앱 개발자
Microsoft ID 통합이 필요한 플러터 앱
기업 인증 정책 준수를 필요로 하는 앱
Azure AD를 신원 공급자로 사용하는 개발자
보안성과 확장성이 뛰어나며 최소한의 부가 코드를 필요로 하는 프로젝트
고려 사항
적절한 Azure AD 앱 등록이 필요합니다
올바른 리디렉션 URI 설정이 필요합니다
Azure AD OAuth2 v2.0 엔드포인트만 가능
내장된 UI 없음 — 사용자 지정 또는 제3자 로그인 화면 필요
iOS/Android/Web용 플랫폼별 구성이 필요할 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Azure Active Directory OAuth
A Flutter OAuth package for performing user authentication against Azure Active Directory OAuth2 v2.0 endpoint. Forked from hitherejoe.FlutterOAuth.
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>();
// ... staticfinalConfig config = newConfig(
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
);
finalAadOAuth oauth = newAadOAuth(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.// ...Widgetbuild(BuildContext context) {
returnMaterialApp(
// ...
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):
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.
Add your Azure tenant ID, tenantName, client ID (ID of App), client Secret (Secret of App) and redirectUrl in the main.dart source-code:
staticfinalConfig configB2Ca = newConfig(
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.
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.