Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidated config between android and ios #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
.dart_tool/

.vscode/
.packages
.pub/

Expand Down
35 changes: 0 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,6 @@ keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.k
}
```

* Path folder res -> raw -> msal_default_config.json
> [MSAL (Microsoft Authentication Library)](https://docs.microsoft.com/pt-br/azure/active-directory/develop/msal-configuration)

```
{
"authorities": [
{
"type": "AAD",
"audience": {
"type": "AzureADMyOrg",
"tenant_id": "organizations"
}
}
],
"client_id": "xxxxxxxxxxxxxxx",
"redirect_uri" : "msauth://com.exemple/U5rbvBLdFUbEazWhQfDgt6oRa24%3D",
"authorization_user_agent": "DEFAULT",
"minimum_required_broker_protocol_version": "3.0",
"multiple_clouds_supported": false,
"broker_redirect_uri_registered": true,
"environment": "Production",
"http": {
"connect_timeout": 10000,
"read_timeout": 30000
},
"logging": {
"pii_enabled": false,
"log_level": "WARNING",
"logcat_enabled": true
},
"account_mode": "MULTIPLE",

}
```

## iOs Configs
* Version msal 1.1.22
- https://github.com/AzureAD/microsoft-authentication-library-for-objc
Expand Down
9 changes: 7 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
group 'com.fsconceicao.azure_ad_authentication'
version '1.0-SNAPSHOT'

def msalVersion = "2.+"
if (project.hasProperty("distMsalVersion")) {
msalVersion = distMsalVersion
Expand All @@ -13,7 +14,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:4.1.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -24,6 +25,7 @@ rootProject.allprojects {
mavenCentral()
maven {
url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
name 'Duo-SDK-Feed'
}
}
}
Expand All @@ -39,6 +41,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
disable 'InvalidPackage'
}

kotlinOptions {
jvmTarget = '1.8'
}
Expand All @@ -54,6 +60,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "com.microsoft.identity.client:msal:${msalVersion}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding


class AzureAdAuthenticationPlugin : FlutterPlugin, ActivityAware {

private var TAG = "AzureAdAuthenticationPlugin"
private val TAG = "AzureAdAuthenticationPlugin"
private var msalCallHandler: MsalHandlerImpl? = null
private var msal:Msal? = null;
private var msal:Msal? = null


override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
Expand All @@ -24,7 +23,7 @@ class AzureAdAuthenticationPlugin : FlutterPlugin, ActivityAware {

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
if (msalCallHandler == null) {
Log.wtf(TAG, "Already detached from the engine.");
Log.wtf(TAG, "Already detached from the engine.")
return;
}

Expand All @@ -46,7 +45,7 @@ class AzureAdAuthenticationPlugin : FlutterPlugin, ActivityAware {
}

override fun onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
onDetachedFromActivity()
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.fsconceicao.azure_ad_authentication

import android.app.Activity
import android.content.Context
import android.os.Handler
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.ISingleAccountApplicationCreatedListener
import com.microsoft.identity.client.exception.MsalClientException
import com.microsoft.identity.client.exception.MsalException
import com.microsoft.identity.client.exception.MsalServiceException
Expand All @@ -18,7 +18,7 @@ class Msal(context: Context, activity: FlutterActivity?) {
internal val applicationContext = context
internal var activity: FlutterActivity? = activity

lateinit var adAuthentication: IMultipleAccountPublicClientApplication
lateinit var adAuthentication: IPublicClientApplication
lateinit var accountList: List<IAccount>

fun setActivity(activity: FlutterActivity) {
Expand All @@ -27,7 +27,7 @@ class Msal(context: Context, activity: FlutterActivity?) {

internal fun isClientInitialized(): Boolean = ::adAuthentication.isInitialized

internal fun getApplicationCreatedListener(result: MethodChannel.Result): IMultipleAccountApplicationCreatedListener {
internal fun getMultipleApplicationCreatedListener(result: MethodChannel.Result): IMultipleAccountApplicationCreatedListener {

return object : IMultipleAccountApplicationCreatedListener {
override fun onCreated(application: IMultipleAccountPublicClientApplication) {
Expand All @@ -45,11 +45,36 @@ class Msal(context: Context, activity: FlutterActivity?) {
}
}

internal fun getSingleApplicationCreatedListener(result: MethodChannel.Result): ISingleAccountApplicationCreatedListener {

return object : ISingleAccountApplicationCreatedListener {
override fun onCreated(application: ISingleAccountPublicClientApplication) {
adAuthentication = application
result.success(true)
}

override fun onError(exception: MsalException?) {
result.error(
"INIT_ERROR",
"Error initializting client = ${exception.toString()}",
exception?.localizedMessage
)
}
}
}

internal fun getAuthCallback(result: MethodChannel.Result): AuthenticationCallback {
return object : AuthenticationCallback {
override fun onSuccess(authenticationResult: IAuthenticationResult) {
Handler(Looper.getMainLooper()).post {
result.success("{\"accessToken\":\"${authenticationResult.accessToken}\",\"expiresOn\":\"${authenticationResult.expiresOn}\"}")
val account = authenticationResult.account as MultiTenantAccount;
result.success(
mapOf(
"identifier" to "${account.id}.${account.tenantId}",
"accessToken" to authenticationResult.accessToken,
"expiresOn" to "${authenticationResult.expiresOn}"
))

}
}

Expand Down Expand Up @@ -118,23 +143,24 @@ class Msal(context: Context, activity: FlutterActivity?) {
*/
internal fun loadAccounts(result: MethodChannel.Result) {

adAuthentication.getAccounts(object : IPublicClientApplication.LoadAccountsCallback {

override fun onTaskCompleted(resultList: List<IAccount>) {
accountList = resultList
result.success(true)
}

override fun onError(exception: MsalException) {
result.error(
"NO_ACCOUNT",
"No account is available to acquire token silently for",
exception
)
}
})
}
(adAuthentication as? IMultipleAccountPublicClientApplication)?.let {
it.getAccounts(object : IPublicClientApplication.LoadAccountsCallback {

override fun onTaskCompleted(resultList: List<IAccount>) {
accountList = resultList
result.success(true)
}

override fun onError(exception: MsalException) {
result.error(
"NO_ACCOUNT",
"No account is available to acquire token silently for",
exception
)
}
})
}
}
}

Loading