From f046aaec80a844441d74a114b8a4612933cbbb9a Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Fri, 23 Oct 2020 10:13:08 -0300 Subject: [PATCH 1/9] log android --- example/.flutter-plugins-dependencies | 1 + example/android/app/build.gradle | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 example/.flutter-plugins-dependencies diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..766e329 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-23 10:04:04.250779","version":"1.20.2"} \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index b06baf9..a8a8570 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -50,6 +50,8 @@ android { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. + buildConfigField "boolean", 'IS_PRINT_LOG', "false" + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug } } From bef0ed725e6519e02eb5b8ca89b268569199e3d2 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Mon, 26 Oct 2020 07:21:11 -0300 Subject: [PATCH 2/9] add buildTypes --- android/build.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index a844df8..ab01a23 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,6 +39,13 @@ android { lintOptions { disable 'InvalidPackage' } + + buildTypes { + release { + buildConfigField "boolean", 'IS_PRINT_LOG', "false" + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } } dependencies { From 0e30134f68b78d039bb10436dddd282f6f3a69d8 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Mon, 26 Oct 2020 07:52:35 -0300 Subject: [PATCH 3/9] lod.d --- .../moodio/msal_flutter/MsalFlutterPlugin.kt | 52 +++++++++---------- example/.flutter-plugins-dependencies | 2 +- .../ios/Flutter/flutter_export_environment.sh | 11 ++-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt index c52dd26..389c394 100644 --- a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt +++ b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt @@ -27,7 +27,7 @@ class MsalFlutterPlugin: MethodCallHandler { @JvmStatic fun registerWith(registrar: Registrar) { - Log.d("MsalFlutter","Registering plugin") + // Log.d("MsalFlutter","Registering plugin") val channel = MethodChannel(registrar.messenger(), "msal_flutter") channel.setMethodCallHandler(MsalFlutterPlugin()) mainActivity = registrar.activity() @@ -35,11 +35,11 @@ class MsalFlutterPlugin: MethodCallHandler { fun getAuthCallback(result: Result) : AuthenticationCallback { - Log.d("MsalFlutter", "Getting the auth callback object") + // Log.d("MsalFlutter", "Getting the auth callback object") return object : AuthenticationCallback { override fun onSuccess(authenticationResult : IAuthenticationResult){ - Log.d("MsalFlutter", "Authentication successful") + // Log.d("MsalFlutter", "Authentication successful") Handler(Looper.getMainLooper()).post { result.success(authenticationResult.accessToken) } @@ -47,15 +47,15 @@ class MsalFlutterPlugin: MethodCallHandler { override fun onError(exception : MsalException) { - Log.d("MsalFlutter","Error logging in!") - Log.d("MsalFlutter", exception.message) + // Log.d("MsalFlutter","Error logging in!") + // Log.d("MsalFlutter", exception.message) Handler(Looper.getMainLooper()).post { result.error("AUTH_ERROR", "Authentication failed", exception.localizedMessage) } } override fun onCancel(){ - Log.d("MsalFlutter", "Cancelled") + // Log.d("MsalFlutter", "Cancelled") Handler(Looper.getMainLooper()).post { result.error("CANCELLED", "User cancelled", null) } @@ -64,18 +64,18 @@ class MsalFlutterPlugin: MethodCallHandler { } private fun getApplicationCreatedListener(result: Result) : IPublicClientApplication.ApplicationCreatedListener { - Log.d("MsalFlutter", "Getting the created listener") + // Log.d("MsalFlutter", "Getting the created listener") return object : IPublicClientApplication.ApplicationCreatedListener { override fun onCreated(application: IPublicClientApplication) { - Log.d("MsalFlutter", "Created successfully") + // Log.d("MsalFlutter", "Created successfully") msalApp = application as MultipleAccountPublicClientApplication result.success(true) } override fun onError(exception: MsalException?) { - Log.d("MsalFlutter", "Initialize error") + // Log.d("MsalFlutter", "Initialize error") result.error("INIT_ERROR", "Error initializting client", exception?.localizedMessage) } } @@ -88,10 +88,10 @@ class MsalFlutterPlugin: MethodCallHandler { val scopes: Array? = scopesArg?.toTypedArray() val clientId : String? = call.argument("clientId") val authority : String? = call.argument("authority") - - Log.d("MsalFlutter","Got scopes: $scopes") - Log.d("MsalFlutter","Got cleintId: $clientId") - Log.d("MsalFlutter","Got authority: $authority") +// +// Log.d("MsalFlutter","Got scopes: $scopes") +// Log.d("MsalFlutter","Got cleintId: $clientId") +// Log.d("MsalFlutter","Got authority: $authority") when(call.method){ "logout" -> Thread(Runnable{logout(result)}).start() @@ -105,11 +105,11 @@ class MsalFlutterPlugin: MethodCallHandler { private fun acquireToken(scopes : Array?, result: Result) { - Log.d("MsalFlutter", "acquire token called") + //Log.d("MsalFlutter", "acquire token called") // check if client has been initialized if(!isClientInitialized()){ - Log.d("MsalFlutter","Client has not been initialized") + // Log.d("MsalFlutter","Client has not been initialized") Handler(Looper.getMainLooper()).post { result.error("NO_CLIENT", "Client must be initialized before attempting to acquire a token.", null) } @@ -117,14 +117,14 @@ class MsalFlutterPlugin: MethodCallHandler { //check scopes if(scopes == null){ - Log.d("MsalFlutter", "no scope") + // Log.d("MsalFlutter", "no scope") result.error("NO_SCOPE", "Call must include a scope", null) return } //remove old accounts while(msalApp.accounts.any()){ - Log.d("MsalFlutter","Removing old account") + // Log.d("MsalFlutter","Removing old account") msalApp.removeAccount(msalApp.accounts.first()) } @@ -134,11 +134,11 @@ class MsalFlutterPlugin: MethodCallHandler { private fun acquireTokenSilent(scopes : Array?, result: Result) { - Log.d("MsalFlutter", "Called acquire token silent") + // Log.d("MsalFlutter", "Called acquire token silent") // check if client has been initialized if(!isClientInitialized()){ - Log.d("MsalFlutter","Client has not been initialized") + // Log.d("MsalFlutter","Client has not been initialized") Handler(Looper.getMainLooper()).post { result.error("NO_CLIENT", "Client must be initialized before attempting to acquire a token.", null) } @@ -146,7 +146,7 @@ class MsalFlutterPlugin: MethodCallHandler { //check the scopes if(scopes == null){ - Log.d("MsalFlutter", "no scope") + // Log.d("MsalFlutter", "no scope") Handler(Looper.getMainLooper()).post { result.error("NO_SCOPE", "Call must include a scope", null) } @@ -172,14 +172,14 @@ class MsalFlutterPlugin: MethodCallHandler { { //ensure clientid provided if(clientId == null){ - Log.d("MsalFlutter","error no clientId") + // Log.d("MsalFlutter","error no clientId") result.error("NO_CLIENTID", "Call must include a clientId", null) return } //if already initialized, ensure clientid hasn't changed if(isClientInitialized()){ - Log.d("MsalFlutter","Client already initialized.") + // Log.d("MsalFlutter","Client already initialized.") if(msalApp.configuration.clientId == clientId) { result.success(true) @@ -190,11 +190,11 @@ class MsalFlutterPlugin: MethodCallHandler { // if authority is set, create client using it, otherwise use default if(authority != null){ - Log.d("MsalFlutter", "Authority not null") - Log.d("MsalFlutter", "Creating with: $clientId - $authority") + // Log.d("MsalFlutter", "Authority not null") + // Log.d("MsalFlutter", "Creating with: $clientId - $authority") PublicClientApplication.create(mainActivity.applicationContext, clientId, authority, getApplicationCreatedListener(result)) }else{ - Log.d("MsalFlutter", "Authority null") + // Log.d("MsalFlutter", "Authority null") PublicClientApplication.create(mainActivity.applicationContext, clientId, getApplicationCreatedListener(result)) } } @@ -202,7 +202,7 @@ class MsalFlutterPlugin: MethodCallHandler { private fun logout(result: Result){ while(msalApp.accounts.any()){ - Log.d("MsalFlutter","Removing old account") + // Log.d("MsalFlutter","Removing old account") msalApp.removeAccount(msalApp.accounts.first()) } Handler(Looper.getMainLooper()).post { diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 766e329..021bbbd 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-23 10:04:04.250779","version":"1.20.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-26 07:24:31.426833","version":"1.22.2"} \ No newline at end of file diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 216902d..8eac4ab 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,10 +1,15 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/mahmoud/development/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/mahmoud/projects/46-msalflutter/example" +export "FLUTTER_ROOT=/Users/fabioconceicao/Documents/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/fabioconceicao/Documents/Projetos/msal-flutter/example" export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "FLUTTER_FRAMEWORK_DIR=/Users/mahmoud/development/flutter/bin/cache/artifacts/engine/ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=/Users/fabioconceicao/Documents/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1.0.0" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" From 370224148d9d6ab43bc3be63c8a09f4ceeb2fe98 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Tue, 27 Oct 2020 08:55:13 -0300 Subject: [PATCH 4/9] teste v2 msal --- CHANGELOG.md | 2 +- README.md | 14 +- android/build.gradle | 18 +- .../moodio/msal_flutter/MsalFlutterPlugin.kt | 132 +++------ example/.flutter-plugins-dependencies | 2 +- example/android/app/Keystore/debug.keystore | Bin 0 -> 2106 bytes .../android/app/Keystore/julia_keystore.jks | Bin 0 -> 2102 bytes example/android/app/build.gradle | 24 +- .../android/app/src/main/AndroidManifest.xml | 7 +- .../src/main/res/raw/msal_default_config.json | 262 +++++++++--------- example/lib/main.dart | 4 +- lib/src/public_client_application.dart | 3 + 12 files changed, 229 insertions(+), 239 deletions(-) create mode 100644 example/android/app/Keystore/debug.keystore create mode 100644 example/android/app/Keystore/julia_keystore.jks diff --git a/CHANGELOG.md b/CHANGELOG.md index dcbf65a..6baa952 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.0.0+2 +# 1.0.0+2 * Updates to readme in regards to kotlin static field issues. ## 1.0.0+1 * Added some more information to readme for clarity diff --git a/README.md b/README.md index deb6bc3..8abfee0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ e.g. `https://msalfluttertest.b2clogin.com/tfp/msalfluttertest.onmicrosoft.com/B For troubleshooting known bugs in the new build, please scroll down to the bottom of the page where all bugs and fixes we find will be noted. -# MSAL Wrapper Library for Flutter +## MSAL Wrapper Library for Flutter Please note this product is in very early alpha release and subject to change and bugs. The Microsoft Authentication Library Flutter Wrapper is a wrapper that uses that MSAL libraries for Android and IOS. Currently only the public client application functionality is supported, using the implicit workflow. @@ -37,6 +37,7 @@ This section is mostly copied and modified from [the official android MSAL libra ``` + ``` 2. In your AndroidManifest.xml file add the following intent filter, replacing the placeholder \ for your azure b2c application's client id where indicated below. @@ -53,6 +54,7 @@ The default redirect url is msal\://auth however this can now b android:host="auth" /> + ``` 3. Copy the [msal_default_config](https://raw.githubusercontent.com/moodio/msal-flutter/master/doc/templates/msal_default_config.json) from this repository (or make your own if you know what you're doing) and place it into your flutter apps android/src/main/res/raw folder. @@ -80,6 +82,7 @@ This section is mostly copied and modified from Step 1 from [the official iOS MS + ``` 2. Add LSApplicationQueriesSchemes to allow making call to Microsoft Authenticator if installed (For Authentication broker) @@ -90,6 +93,7 @@ This section is mostly copied and modified from Step 1 from [the official iOS MS msauthv2 msauthv3 + ``` 3. Open the app's iOS project in xcode, click on the Runner app to open up the configuration, and under capabilities, expand Keychain Sharing and add the keychain group `com.microsoft.adalcache` @@ -143,6 +147,7 @@ try{ } on MsalException { //error handling logic here } + ``` 4. Once a user has logged in atleast once, to retrieve a token silently call the acquireTokenSilent function, passing the scopes you wish to acquire the token for. Note that this function will throw an error on failure and should be surrounded by a try catch block as per the example below @@ -184,6 +189,9 @@ try{ # Trouble Shooting -Please note there is currently an issue that seems to occur with Android which uses slightly older versions of kotlin. -If you get the error when attemtping to acquire a token, along the lines of "static member msalApp not found", goto your app's android folder, open the build.gradle file, and on the second line change the version of kotlin from 1.3.10 to 1.3.50. For more information take a look at issue #4. +Please note there is currently an issue that seems to occur with Android which uses slightly older + versions of kotlin. +If you get the error when attemtping to acquire a token, along the lines of "static member msalApp +not found", goto your app's android folder, open the build.gradle file, and on the second line +change the version of kotlin from 1.3.10 to 1.3.50. For more information take a look at issue #4. A fix will be implemented shortly. \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index ab01a23..99099ce 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -18,6 +18,11 @@ rootProject.allprojects { repositories { google() jcenter() + mavenCentral() + mavenLocal() + maven { + url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1' + } } } @@ -26,13 +31,14 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 28 + compileSdkVersion 30 sourceSets { main.java.srcDirs += 'src/main/kotlin' } + defaultConfig { - minSdkVersion 21 + targetSdkVersion 30 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" manifestPlaceholders = [msal_clientid: "5913dfb1-7576-451c-a7ea-a7c5a3f8682a"] } @@ -40,15 +46,9 @@ android { disable 'InvalidPackage' } - buildTypes { - release { - buildConfigField "boolean", 'IS_PRINT_LOG', "false" - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.microsoft.identity.client:msal:1.0.+' + implementation 'com.microsoft.identity.client:msal:2.+' } diff --git a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt index 389c394..ee409f4 100644 --- a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt +++ b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt @@ -4,58 +4,48 @@ import android.app.Activity import android.os.Handler import android.os.Looper import android.util.Log -import androidx.annotation.WorkerThread +import com.microsoft.identity.client.* +import com.microsoft.identity.client.IPublicClientApplication.IMultipleAccountApplicationCreatedListener +import com.microsoft.identity.client.exception.MsalException import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result import io.flutter.plugin.common.PluginRegistry.Registrar -import com.microsoft.identity.client.* -import com.microsoft.identity.client.exception.MsalException -import com.microsoft.identity.client.IPublicClientApplication -import com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration @Suppress("SpellCheckingInspection") -class MsalFlutterPlugin: MethodCallHandler { - companion object - { - lateinit var mainActivity : Activity +class MsalFlutterPlugin : MethodCallHandler { + companion object { + lateinit var mainActivity: Activity lateinit var msalApp: IMultipleAccountPublicClientApplication fun isClientInitialized() = ::msalApp.isInitialized @JvmStatic fun registerWith(registrar: Registrar) { - // Log.d("MsalFlutter","Registering plugin") + // Log.d("MsalFlutter","Registering plugin") val channel = MethodChannel(registrar.messenger(), "msal_flutter") channel.setMethodCallHandler(MsalFlutterPlugin()) mainActivity = registrar.activity() } - fun getAuthCallback(result: Result) : AuthenticationCallback - { - // Log.d("MsalFlutter", "Getting the auth callback object") - return object : AuthenticationCallback - { - override fun onSuccess(authenticationResult : IAuthenticationResult){ - // Log.d("MsalFlutter", "Authentication successful") + fun getAuthCallback(result: Result): AuthenticationCallback { + + return object : AuthenticationCallback { + override fun onSuccess(authenticationResult: IAuthenticationResult) { Handler(Looper.getMainLooper()).post { result.success(authenticationResult.accessToken) } } - override fun onError(exception : MsalException) - { - // Log.d("MsalFlutter","Error logging in!") - // Log.d("MsalFlutter", exception.message) + override fun onError(exception: MsalException) { Handler(Looper.getMainLooper()).post { result.error("AUTH_ERROR", "Authentication failed", exception.localizedMessage) } } - override fun onCancel(){ - // Log.d("MsalFlutter", "Cancelled") + override fun onCancel() { Handler(Looper.getMainLooper()).post { result.error("CANCELLED", "User cancelled", null) } @@ -63,90 +53,70 @@ class MsalFlutterPlugin: MethodCallHandler { } } - private fun getApplicationCreatedListener(result: Result) : IPublicClientApplication.ApplicationCreatedListener { - // Log.d("MsalFlutter", "Getting the created listener") + private fun getApplicationCreatedListener(result: Result): IMultipleAccountApplicationCreatedListener { + + return object : IMultipleAccountApplicationCreatedListener { - return object : IPublicClientApplication.ApplicationCreatedListener - { - override fun onCreated(application: IPublicClientApplication) { - // Log.d("MsalFlutter", "Created successfully") - msalApp = application as MultipleAccountPublicClientApplication + override fun onCreated(application: IMultipleAccountPublicClientApplication) { + msalApp = application result.success(true) } override fun onError(exception: MsalException?) { - // Log.d("MsalFlutter", "Initialize error") + Log.d("MsalFlutter", "Initialize error") result.error("INIT_ERROR", "Error initializting client", exception?.localizedMessage) } } } } - override fun onMethodCall(call: MethodCall, result: Result) - { - val scopesArg : ArrayList? = call.argument("scopes") + override fun onMethodCall(call: MethodCall, result: Result) { + val scopesArg: ArrayList? = call.argument("scopes") val scopes: Array? = scopesArg?.toTypedArray() - val clientId : String? = call.argument("clientId") - val authority : String? = call.argument("authority") -// -// Log.d("MsalFlutter","Got scopes: $scopes") -// Log.d("MsalFlutter","Got cleintId: $clientId") -// Log.d("MsalFlutter","Got authority: $authority") - - when(call.method){ - "logout" -> Thread(Runnable{logout(result)}).start() + val clientId: String? = call.argument("clientId") + val authority: String? = call.argument("authority") + + when (call.method) { + "logout" -> Thread(Runnable { logout(result) }).start() "initialize" -> initialize(clientId, authority, result) - "acquireToken" -> Thread(Runnable {acquireToken(scopes, result)}).start() - "acquireTokenSilent" -> Thread(Runnable {acquireTokenSilent(scopes, result)}).start() + "acquireToken" -> Thread(Runnable { acquireToken(scopes, result) }).start() + "acquireTokenSilent" -> Thread(Runnable { acquireTokenSilent(scopes, result) }).start() else -> result.notImplemented() } } - private fun acquireToken(scopes : Array?, result: Result) - { - //Log.d("MsalFlutter", "acquire token called") - + private fun acquireToken(scopes: Array?, result: Result) { // check if client has been initialized - if(!isClientInitialized()){ - // Log.d("MsalFlutter","Client has not been initialized") + if (!isClientInitialized()) { Handler(Looper.getMainLooper()).post { result.error("NO_CLIENT", "Client must be initialized before attempting to acquire a token.", null) } } //check scopes - if(scopes == null){ - // Log.d("MsalFlutter", "no scope") + if (scopes == null) { result.error("NO_SCOPE", "Call must include a scope", null) return } //remove old accounts - while(msalApp.accounts.any()){ - // Log.d("MsalFlutter","Removing old account") - msalApp.removeAccount(msalApp.accounts.first()) - } + while (msalApp.accounts.any()) { msalApp.removeAccount(msalApp.accounts.first()) } //acquire the token msalApp.acquireToken(mainActivity, scopes, getAuthCallback(result)) } - private fun acquireTokenSilent(scopes : Array?, result: Result) - { - // Log.d("MsalFlutter", "Called acquire token silent") - + private fun acquireTokenSilent(scopes: Array?, result: Result) { // check if client has been initialized - if(!isClientInitialized()){ - // Log.d("MsalFlutter","Client has not been initialized") + if (!isClientInitialized()) { Handler(Looper.getMainLooper()).post { result.error("NO_CLIENT", "Client must be initialized before attempting to acquire a token.", null) } } //check the scopes - if(scopes == null){ - // Log.d("MsalFlutter", "no scope") + if (scopes == null) { Handler(Looper.getMainLooper()).post { result.error("NO_SCOPE", "Call must include a scope", null) } @@ -154,7 +124,7 @@ class MsalFlutterPlugin: MethodCallHandler { } //ensure accounts exist - if(msalApp.accounts.isEmpty()){ + if (msalApp.accounts.isEmpty()) { Handler(Looper.getMainLooper()).post { result.error("NO_ACCOUNT", "No account is available to acquire token silently for", null) } @@ -168,41 +138,31 @@ class MsalFlutterPlugin: MethodCallHandler { } } - private fun initialize(clientId: String?, authority: String?, result: Result) - { + private fun initialize(clientId: String?, authority: String?, result: Result) { //ensure clientid provided - if(clientId == null){ - // Log.d("MsalFlutter","error no clientId") + if (clientId == null) { result.error("NO_CLIENTID", "Call must include a clientId", null) return } //if already initialized, ensure clientid hasn't changed - if(isClientInitialized()){ - // Log.d("MsalFlutter","Client already initialized.") - if(msalApp.configuration.clientId == clientId) - { + if (isClientInitialized()) { + if (msalApp.configuration.clientId == clientId) { result.success(true) } else { result.error("CHANGED_CLIENTID", "Attempting to initialize with multiple clientIds.", null) } } - // if authority is set, create client using it, otherwise use default - if(authority != null){ - // Log.d("MsalFlutter", "Authority not null") - // Log.d("MsalFlutter", "Creating with: $clientId - $authority") - PublicClientApplication.create(mainActivity.applicationContext, clientId, authority, getApplicationCreatedListener(result)) - }else{ - // Log.d("MsalFlutter", "Authority null") - PublicClientApplication.create(mainActivity.applicationContext, clientId, getApplicationCreatedListener(result)) - } + PublicClientApplication.createMultipleAccountPublicClientApplication(mainActivity.applicationContext, + R.raw.msal_default_config, getApplicationCreatedListener(result)) + + } - private fun logout(result: Result){ - while(msalApp.accounts.any()){ - // Log.d("MsalFlutter","Removing old account") + private fun logout(result: Result) { + while (msalApp.accounts.any()) { msalApp.removeAccount(msalApp.accounts.first()) } Handler(Looper.getMainLooper()).post { diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 021bbbd..92004d5 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-26 07:24:31.426833","version":"1.22.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-27 08:16:10.889681","version":"1.22.2"} \ No newline at end of file diff --git a/example/android/app/Keystore/debug.keystore b/example/android/app/Keystore/debug.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aWIc{O%^uX{@IcGI#_eY0P@7e|O^cORjUjHkeP ${e.message} --> ${e.code}"); throw _convertException(e); } } From 1a553cffc64033fd18864fea6adb37d5a70e2a3d Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Thu, 29 Oct 2020 16:58:31 -0300 Subject: [PATCH 5/9] version msal update 2.+ --- .../moodio/msal_flutter/MsalFlutterPlugin.kt | 112 +++++++++++++++--- example/.flutter-plugins-dependencies | 2 +- .../android/app/Keystore/julia_keystore.jks | Bin 2102 -> 0 bytes example/android/app/build.gradle | 1 + .../src/main/res/raw/msal_default_config.json | 18 +-- example/lib/main.dart | 14 ++- lib/src/public_client_application.dart | 6 +- 7 files changed, 119 insertions(+), 34 deletions(-) delete mode 100644 example/android/app/Keystore/julia_keystore.jks diff --git a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt index ee409f4..b5fb084 100644 --- a/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt +++ b/android/src/main/kotlin/uk/co/moodio/msal_flutter/MsalFlutterPlugin.kt @@ -6,7 +6,11 @@ import android.os.Looper import android.util.Log import com.microsoft.identity.client.* import com.microsoft.identity.client.IPublicClientApplication.IMultipleAccountApplicationCreatedListener +import com.microsoft.identity.client.IPublicClientApplication.LoadAccountsCallback +import com.microsoft.identity.client.exception.MsalClientException import com.microsoft.identity.client.exception.MsalException +import com.microsoft.identity.client.exception.MsalServiceException +import com.microsoft.identity.client.exception.MsalUiRequiredException import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler @@ -19,6 +23,7 @@ class MsalFlutterPlugin : MethodCallHandler { companion object { lateinit var mainActivity: Activity lateinit var msalApp: IMultipleAccountPublicClientApplication + lateinit var accountList: List fun isClientInitialized() = ::msalApp.isInitialized @@ -53,13 +58,40 @@ class MsalFlutterPlugin : MethodCallHandler { } } + /** + * Callback used in for silent acquireToken calls. + */ + fun getAuthSilentCallback(result: Result): SilentAuthenticationCallback { + return object : SilentAuthenticationCallback { + override fun onSuccess(authenticationResult: IAuthenticationResult) { + Log.d("MSAL_FLUTTER", "Successfully authenticated") + Handler(Looper.getMainLooper()).post { + result.success(authenticationResult.accessToken) + } + } + + override fun onError(exception: MsalException) { + /* Failed to acquireToken */ + Log.d("MSAL_FLUTTER", "Authentication failed: $exception") + if (exception is MsalClientException) { + result.error("NO_SCOPE", "Call must include a scope", exception.localizedMessage) + } else if (exception is MsalServiceException) { + result.error("NO_SCOPE", exception.localizedMessage, exception.localizedMessage) + } else if (exception is MsalUiRequiredException) { + result.error("NO_SCOPE", "Call must include a scope", exception.localizedMessage) + } + } + } + } + private fun getApplicationCreatedListener(result: Result): IMultipleAccountApplicationCreatedListener { return object : IMultipleAccountApplicationCreatedListener { - override fun onCreated(application: IMultipleAccountPublicClientApplication) { - msalApp = application - result.success(true) + + msalApp = application + result.success(true) + } override fun onError(exception: MsalException?) { @@ -68,6 +100,8 @@ class MsalFlutterPlugin : MethodCallHandler { } } } + + } override fun onMethodCall(call: MethodCall, result: Result) { @@ -79,6 +113,7 @@ class MsalFlutterPlugin : MethodCallHandler { when (call.method) { "logout" -> Thread(Runnable { logout(result) }).start() "initialize" -> initialize(clientId, authority, result) + "loadAccounts" -> Thread(Runnable { loadAccounts(result) }).start() "acquireToken" -> Thread(Runnable { acquireToken(scopes, result) }).start() "acquireTokenSilent" -> Thread(Runnable { acquireTokenSilent(scopes, result) }).start() else -> result.notImplemented() @@ -101,7 +136,9 @@ class MsalFlutterPlugin : MethodCallHandler { } //remove old accounts - while (msalApp.accounts.any()) { msalApp.removeAccount(msalApp.accounts.first()) } + while (msalApp.accounts.any()) { + msalApp.removeAccount(msalApp.accounts.first()) + } //acquire the token msalApp.acquireToken(mainActivity, scopes, getAuthCallback(result)) @@ -109,6 +146,7 @@ class MsalFlutterPlugin : MethodCallHandler { private fun acquireTokenSilent(scopes: Array?, result: Result) { // check if client has been initialized + if (!isClientInitialized()) { Handler(Looper.getMainLooper()).post { result.error("NO_CLIENT", "Client must be initialized before attempting to acquire a token.", null) @@ -124,20 +162,21 @@ class MsalFlutterPlugin : MethodCallHandler { } //ensure accounts exist - if (msalApp.accounts.isEmpty()) { + if (accountList?.isEmpty()) { Handler(Looper.getMainLooper()).post { result.error("NO_ACCOUNT", "No account is available to acquire token silently for", null) } return } - + val selectedAccount: IAccount = accountList.first(); //acquire the token and return the result - val res = msalApp.acquireTokenSilent(scopes, msalApp.accounts[0], msalApp.configuration.defaultAuthority.authorityURL.toString()) - Handler(Looper.getMainLooper()).post { - result.success(res.accessToken) - } + val sc = scopes.map { s -> s.toLowerCase() }.toTypedArray() + + msalApp.acquireTokenSilentAsync(sc, selectedAccount, selectedAccount.authority, getAuthSilentCallback(result)) + } + private fun initialize(clientId: String?, authority: String?, result: Result) { //ensure clientid provided if (clientId == null) { @@ -153,20 +192,59 @@ class MsalFlutterPlugin : MethodCallHandler { result.error("CHANGED_CLIENTID", "Attempting to initialize with multiple clientIds.", null) } } - // if authority is set, create client using it, otherwise use default - PublicClientApplication.createMultipleAccountPublicClientApplication(mainActivity.applicationContext, - R.raw.msal_default_config, getApplicationCreatedListener(result)) + if(!isClientInitialized()) { + // if authority is set, create client using it, otherwise use default + PublicClientApplication.createMultipleAccountPublicClientApplication(mainActivity.applicationContext, + R.raw.msal_default_config, getApplicationCreatedListener(result)) + } + + } + + /** + * Load currently signed-in accounts, if there's any. + */ + private fun loadAccounts(result: Result) { + msalApp.getAccounts(object : LoadAccountsCallback { + + override fun onTaskCompleted(resultList: List) { + accountList = resultList + result.success(true) + } + override fun onError(exception: MsalException) { + result.error("NO_ACCOUNT", "No account is available to acquire token silently for", exception) + } + }) } private fun logout(result: Result) { - while (msalApp.accounts.any()) { - msalApp.removeAccount(msalApp.accounts.first()) + if(!isClientInitialized()){ + Handler(Looper.getMainLooper()).post { + result.error("NO_ACCOUNT", "No account is available to acquire token silently for", null) + } + return } - Handler(Looper.getMainLooper()).post { - result.success(true) + + if (accountList?.isEmpty()) { + Handler(Looper.getMainLooper()).post { + result.error("NO_ACCOUNT", "No account is available to acquire token silently for", null) + } + return } + + msalApp.removeAccount(accountList.first(), object : IMultipleAccountPublicClientApplication.RemoveAccountCallback{ + override fun onRemoved() { + Thread(Runnable { loadAccounts(result) }).start() + } + + override fun onError(exception: MsalException) { + result.error("NO_ACCOUNT", "No account is available to acquire token silently for", exception) + } + }) + } } + + diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 92004d5..cf2bc25 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-27 08:16:10.889681","version":"1.22.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-28 18:02:31.172962","version":"1.22.2"} \ No newline at end of file diff --git a/example/android/app/Keystore/julia_keystore.jks b/example/android/app/Keystore/julia_keystore.jks deleted file mode 100644 index 380d226cee6b75c36c9da73aae6be42b8fb8b6f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2102 zcma)6X*3iH8=e_66Jy`Sm`2K4%*Zz4$~w|j!brA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;KUTJ-~#XEvyf>f_7#Kn_^vp9snX7)P*b^z?Z2n{p-hL7-k{)*(ufJ_UfE$EF-ns-_AO;eq+dnBCh#jilJe$5|k_x*JbRxV1*n$qRO zMH6cECK77qQD!%pzCaoO6IE*qI27K>meAR#!}#V0+JE9!iKo`u^z@J3 z+8;*G^whK`cbU9!u`0c4!fLO>z^g^)rKfX)^1Z_C*B_20Sww91Ff{z1l@r+k?=eej;6%L^R|X z+>B8M@c;q9LIu<@lswmdc_FYASmJqAV{pI$wDnQNSqF8w)*%e*&(r@kk((jcL?Gbk zE(K0~COh4i}l#V^CYHVpTzv?uOIkX6FqNMUWAgiOSn z!;!I~_qKare8NQwp+Kz#W{8%NV9X&Yt?c4DZj)I}+;vH$imj%f_VYAGyW~8dlZHi; zDfNU8>omp6JXfD{V?_!M=QIo&C*^Gho~f+At(@>QLjKSqKX`fXI+L|1zCrhK*aWIc{O%^uX{@IcGI#_eY0P@7e|O^cORjUjHkeP { static const String _authority = "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize"; - static const String _clientId = "1516f813-e189-4587-8158-ffb338650aa7"; + static const String _clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; String _output = 'NONE'; + static const List kScopes = [ + "https://graph.microsoft.com/user.read", + "https://graph.microsoft.com/Calendars.ReadWrite", + ]; PublicClientApplication pca; @@ -27,7 +31,7 @@ class _MyAppState extends State { String res; try{ - res = await pca.acquireToken(["https://msalfluttertest.onmicrosoft.com/msalbackend/user_impersonation"]); + res = await pca.acquireToken(kScopes); } on MsalUserCancelledException { res = "User cancelled"; } on MsalNoAccountException { @@ -53,15 +57,15 @@ class _MyAppState extends State { String res; try { - res = await pca.acquireTokenSilent(["https://msalfluttertest.onmicrosoft.com/msalbackend/user_impersonation"]); + res = await pca.acquireTokenSilent(kScopes); } on MsalUserCancelledException { res = "User cancelled"; } on MsalNoAccountException { res = "no account"; } on MsalInvalidConfigurationException { res = "invalid config"; - } on MsalInvalidScopeException { - res = "Invalid scope"; + } on MsalInvalidScopeException catch (e) { + res = "Invalid scope: ${e.errorMessage}"; }on MsalException { res = "Error getting token silently!"; } diff --git a/lib/src/public_client_application.dart b/lib/src/public_client_application.dart index 7049748..ae95fa1 100644 --- a/lib/src/public_client_application.dart +++ b/lib/src/public_client_application.dart @@ -27,6 +27,7 @@ class PublicClientApplication { {String authority}) async { var res = PublicClientApplication._create(clientId, authority: authority); await res._initialize(); + return res; } @@ -51,8 +52,8 @@ class PublicClientApplication { //call platform try { - final String token = - await _channel.invokeMethod('acquireTokenSilent', res); + await _channel.invokeMethod('loadAccounts'); + final String token = await _channel.invokeMethod('acquireTokenSilent', res); return token; } on PlatformException catch (e) { throw _convertException(e); @@ -61,6 +62,7 @@ class PublicClientApplication { Future logout() async { try { + await _channel.invokeMethod('loadAccounts'); await _channel.invokeMethod('logout', {}); } on PlatformException catch (e) { throw _convertException(e); From 048b1204900430f1738a966592072f52ee0b712d Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Thu, 29 Oct 2020 17:02:36 -0300 Subject: [PATCH 6/9] version msal update 2.+ fix loadAccounts request --- lib/src/public_client_application.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/public_client_application.dart b/lib/src/public_client_application.dart index ae95fa1..3d64789 100644 --- a/lib/src/public_client_application.dart +++ b/lib/src/public_client_application.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -52,7 +53,9 @@ class PublicClientApplication { //call platform try { - await _channel.invokeMethod('loadAccounts'); + if (Platform.isAndroid) { + await _channel.invokeMethod('loadAccounts'); + } final String token = await _channel.invokeMethod('acquireTokenSilent', res); return token; } on PlatformException catch (e) { @@ -62,7 +65,9 @@ class PublicClientApplication { Future logout() async { try { - await _channel.invokeMethod('loadAccounts'); + if (Platform.isAndroid) { + await _channel.invokeMethod('loadAccounts'); + } await _channel.invokeMethod('logout', {}); } on PlatformException catch (e) { throw _convertException(e); From e688d1cfa2b4299b3495fb72386fb54728ebb9c6 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Thu, 29 Oct 2020 17:44:51 -0300 Subject: [PATCH 7/9] teste --- example/android/app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index d15ee1e..26dc2a3 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -38,6 +38,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "uk.co.moodio.msal_flutter_example" minSdkVersion 21 targetSdkVersion 30 From 71cacc9c74b91519d48a7e26d40ad218c34839e8 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Thu, 29 Oct 2020 17:46:14 -0300 Subject: [PATCH 8/9] teste2 --- pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2a3903c..e6f62b0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,8 @@ name: msal_flutter description: A Microsoft Authentication Library wrapper for Android and iOS -version: 1.0.0+2 -homepage: https://github.com/moodio/msal-flutter -repository: https://github.com/moodio/msal-flutter +version: 1.0.0+4 +#homepage: https://github.com/moodio/msal-flutter +#repository: https://github.com/moodio/msal-flutter environment: sdk: ">=2.1.0 <3.0.0" From 285cb350ea5a151ec398a13681f5402c8204fcd5 Mon Sep 17 00:00:00 2001 From: "fabio.conceicao" Date: Wed, 11 Nov 2020 08:50:28 -0300 Subject: [PATCH 9/9] fix msal versio stable 2.0.2 --- android/build.gradle | 2 +- example/.flutter-plugins-dependencies | 2 +- example/ios/Flutter/flutter_export_environment.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 99099ce..1488f2c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -50,5 +50,5 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.microsoft.identity.client:msal:2.+' + implementation 'com.microsoft.identity.client:msal:2.0.2' } diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index cf2bc25..13f0a16 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Projetos/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-10-28 18:02:31.172962","version":"1.22.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Folder Projects/msal-flutter/","dependencies":[]}],"android":[{"name":"msal_flutter","path":"/Users/fabioconceicao/Documents/Folder Projects/msal-flutter/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"msal_flutter","dependencies":[]}],"date_created":"2020-11-11 08:48:46.235613","version":"1.22.3"} \ No newline at end of file diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 8eac4ab..7145aa1 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,7 +1,7 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. export "FLUTTER_ROOT=/Users/fabioconceicao/Documents/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/fabioconceicao/Documents/Projetos/msal-flutter/example" +export "FLUTTER_APPLICATION_PATH=/Users/fabioconceicao/Documents/Folder Projects/msal-flutter/example" export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios"