Skip to content

Update NativeAuth imports and added UI Automation intent based initialisation#59

Open
spetrescu84 wants to merge 4 commits into
mainfrom
custom_headers_updated
Open

Update NativeAuth imports and added UI Automation intent based initialisation#59
spetrescu84 wants to merge 4 commits into
mainfrom
custom_headers_updated

Conversation

@spetrescu84
Copy link
Copy Markdown
Contributor

@spetrescu84 spetrescu84 commented May 26, 2026

Changes

  • Updated import for NativeAuthRequestInterceptor to use the new package location com.microsoft.identity.nativeauth.NativeAuthRequestInterceptor
  • Added intent-based initializationAuthClient and MainActivity now accept clientId and authorityUrl via intent extras, enabling UI automation tests to inject test tenant configuration at runtime without modifying bundled config files
  • Removed StringUtil dependency — replaced StringUtil.overwriteWithNull(password) with Kotlin's built-in password.fill('\u0000') to avoid pulling in the common library dependency
  • Reverted changes to flatUsername to prevent building error as PR for alias is not yet merged - Add flatUsername attribute to UserAttributes builder Fixes AB#3607103 AzureAD/microsoft-authentication-library-for-android#2513

Context

These changes support the new NativeAuth UI automation tests in android-complete (PR #437). The test launches NativeAuthSampleApp via adb with intent extras containing the CIAM tenant config, allowing end-to-end sign-in validation in the 1ES weekly pipeline via Firebase Test Lab.

import com.azuresamples.msalnativeauthandroidkotlinsampleapp.databinding.FragmentEmailPasswordBinding
import com.microsoft.identity.client.PublicClientApplication
import com.microsoft.identity.common.java.nativeauth.providers.NativeAuthRequestInterceptor
import com.microsoft.identity.nativeauth.NativeAuthRequestInterceptor;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need ";"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

import com.microsoft.identity.client.PublicClientApplication
import com.microsoft.identity.common.java.nativeauth.providers.NativeAuthRequestInterceptor
import com.microsoft.identity.nativeauth.NativeAuthRequestInterceptor;
import com.microsoft.identity.common.java.util.StringUtil
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also remove this one? com.microsoft.identity.common.java.util.StringUtil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed and from mfafragment.kt

-Removed adding flat ussername as it's not yet merged into MSAL so build fails
-update to attributeName as that's the correct value
@spetrescu84 spetrescu84 changed the title Update import for NativeAuthRequestInterceptor Add UI automation test support and update NativeAuth imports May 27, 2026
@spetrescu84 spetrescu84 changed the title Add UI automation test support and update NativeAuth imports Update NativeAuth imports and added UI Automation intent based initialisation May 27, 2026
val username = binding.usernameText.text.toString()

val attributes = UserAttributes.Builder()
.flatUsername(username)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not needed?

Copy link
Copy Markdown
Contributor Author

@spetrescu84 spetrescu84 May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment to description also - Reverted changes to flatUsername to prevent building error as PR for alias is not yet merged - AzureAD/microsoft-authentication-library-for-android#2513
Will add back once that PR is merged, but currently Sample App doesn't compile as .flatUsername is not in the MSAL package/nor this branch.

parameters.password = password
val actionResult: SignInResult = authClient.signIn(parameters)
binding.passwordText.text?.clear()
StringUtil.overwriteWithNull(password)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap the StringUtil in our StringUtil (new) class for eliminating hard-coded values? Also, the other classes still call StringUtil.overwriteWithNull(password).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean exactly. The only StringUtil class I see is in common and as @antrix1989 said we shouldn't use that. Indeed, I see now that it still existed in a few places in this sample app so I've done a commit to remove it completely. Let me know if that works or we should have a new StringUtil in MSAL or something like that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create StringUtil in our Sample App later, to move hard-coded usages but now not important thing.

// Custom implementation for Flat Username / Alias
if (actionResult.requiredAttributes.size == 1 &&
actionResult.requiredAttributes.any { it.name == "flatusername" }
actionResult.requiredAttributes.any { it.attributeName == "flatusername" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name also works, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Android Complete and pipeline it doesn't because of how it's imported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants