Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FlutterMicrosoftAuthenticationPlugin: MethodCallHandler {
"acquireTokenSilently" -> acquireTokenSilently(scopes, authority, result)
"loadAccount" -> loadAccount(result)
"signOut" -> signOut(result)
"init" -> initPlugin(configPath)
"init" -> initPlugin(configPath, result)
else -> result.notImplemented()
}

Expand Down Expand Up @@ -103,11 +103,11 @@ class FlutterMicrosoftAuthenticationPlugin: MethodCallHandler {
}
}

private fun initPlugin(assetPath: String) {
createSingleAccountPublicClientApplication(assetPath)
private fun initPlugin(assetPath: String, result: Result) {
createSingleAccountPublicClientApplication(assetPath, result)
}

private fun createSingleAccountPublicClientApplication(assetPath: String) {
private fun createSingleAccountPublicClientApplication(assetPath: String, result: Result) {
val configFile = getConfigFile(assetPath)
val context: Context = mainActivity.applicationContext

Expand All @@ -123,10 +123,12 @@ class FlutterMicrosoftAuthenticationPlugin: MethodCallHandler {
*/
Log.d(TAG, "INITIALIZED")
mSingleAccountApp = application
result.success(null)
}

override fun onError(exception: MsalException) {
Log.e(TAG, exception.message)
result.error(exception.errorCode, exception.message, null)
}
})
}
Expand Down
19 changes: 17 additions & 2 deletions lib/flutter_microsoft_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FlutterMicrosoftAuthentication {
List<String> _kScopes;
String _kClientID, _kAuthority;
String _androidConfigAssetPath;
Future initialFuture;

FlutterMicrosoftAuthentication(
{String kClientID,
Expand All @@ -20,8 +21,22 @@ class FlutterMicrosoftAuthentication {
_kScopes = kScopes;
_androidConfigAssetPath = androidConfigAssetPath;

if (Platform.isAndroid)
_channel.invokeMethod("init", _createMethodcallArguments());
if (Platform.isAndroid) {
initialFuture = _channel.invokeMethod("init", _createMethodcallArguments());
}
}

/// Make sure the plugin has been ready.
///
/// To prevent potential problem,
/// you should call this after instantiate [FlutterMicrosoftAuthentication].
///
/// ``dart
/// final fma = FlutterMicrosoftAuthentication();
/// await fma.ensureInitialized();
/// ```
Future ensureInitialized () {
return Future.value(initialFuture);
}

Map<String, dynamic> _createMethodcallArguments() {
Expand Down