-
Notifications
You must be signed in to change notification settings - Fork 126
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
The acquireToken method doesn't work if the app uses "withFragmemt" #1725
Comments
@negoe |
+1 on this |
Looks like the pull request is created but haven't reviewed for long time: |
I found the workaround. I still see the error about fragment transaction, but it works. |
Wow, you're awesome. Thanks for bringing back a workaround. To clarify, you just created |
+1 on this. Also need this to be fixed. |
I did this and it worked beautifully. Thanks! |
Yes, I just create this file in my project with the same name and package |
Additional information for assigned person. Please consider the following sample: Parent activity:
If you attach the fragment in the first time, it works with workaround, but it you then switch to "Another fragment" and then back to the Azure, the empty view will be displayed(noting loaded), the error in logs is displayed and it doesn't work. it cool be to have the working sample and documentation how you should use "withFragment" method correctly. |
@VolodaUa Thanks for the workaround. "Type com.microsoft.identity.common.internal.providers.oauth2.AndroidAuthorizationStrategy is defined multiple times" Did you find the same problem? Could you solve it? Thanks |
@juampiMG I had ideas to use some plugin to remove/rename the class from the final package, but respecting that the project where I work is huge, I failed this setup. Currently, I stopped as it fixes only case when you just need to attach the fragment once. Otherwise, the webview stop working and nothing will be displayed. I strongly suggest considering checking this case during the main fix as it is quite often case. |
I was able to get this working in release. TLDR; it takes some work. For my purposes, I wanted to replace both You may want to get a coffee (or beverage of your choice) before attempting the following: Removing the necessary files from the library
Importing the AAR in your project successfullyI added In the
ResultNow I can build a release build with both For those who trust a random on GitHub providing them with a modified AAR, I have attached mine below. For those who don't, just follow the Removing the necessary files from the library steps above. |
@RileyGB I also want to fix WebView not loading after the fragment attachment in the second time. I think you saved a lot of develops time who faced with it. |
Regarding the issue with fragment attaching in the second time.
|
@VolodaUa Thanks for the feedback on the documentation and sample. We are taking a look and will provide you with updates. |
Facing the same issue and the work-around of having a local copy of |
Hello @negoe , is there any update on this issue? |
@RileyGB I tried this approach but getting the below error, any ideas? Thanks |
I also encountered the same issue with 4.1.0. It works fine with the previous version. |
@VolodaUa Thank you for the info, can you please let me know which version(s) worked for you?
but still getting the same error
|
Please try this code: ` // Microsoft MSAL (need to exclude all transitive dependencies or the commons lib will cause a duplicate class error)
|
@negoe Could you please tell me whether the issue is fixed? I don't see any pull request with the fix, but the ticket was closed. |
@negoe The fix is not present in the latest version 4.10.0. I can't capture why a simple fix was skipped and people still need to do a workaround to make it work ((((
Thanks for answer! |
I have similar problem here. And the work-around did not work. Environment: Configuration file:
aquire token:
Scope: profile, if we change to User.Read, the user need to use the MFA. This is the reason of we use the profile scope. The AndroidAuthorizationStrategy class is now in the project https://github.com/AzureAD/microsoft-authentication-library-common-for-android/tree/release/16.2.0 I did not receive any error message, and I am trying to get it. If you can get me any tip I will appreciate ;) |
Hi @fvaladares , As I see, your problem is different. This problem relates to the issue when the "withFragment()" method is used using AcquireTokenParameters.Bulder. I suggest you add logging. Maybe you will find something there. |
Hi @VolodaUa, Thanks for ask my question. I will take a look in your suggestion and make some tests. |
Details
We are going to make b2c authorization in our Android app and we faced with issue with "IMultipleAccountPublicClientApplication.acquireToken" method and fragment.
Smartphone (please complete the following information):
Config
{ "broker_redirect_uri_registered": false, "client_id" : "****", "authorization_user_agent" : "WEBVIEW", "redirect_uri" : "****", "authorities" : [ { "type": "B2C", "authority_url": "https://schcoad.b2clogin.com/schcoad.onmicrosoft.com/.......", "default": true } ] }
Stacktrace
W/MSALLogger: AuthorizationFragment:onCreate | [2022-11-11 13:11:47 - thread_name: main, correlation_id: UNSET - Android 31] No stored state. Unable to handle response W/AuthorizationFragment:onCreate: [2022-11-11 13:11:47 - thread_name: main, correlation_id: UNSET - Android 31] No stored state. Unable to handle response E/MSALLogger: AuthorizationFragment#finish | [2022-11-11 13:11:47 - thread_name: main, correlation_id: UNSET - Android 31] Logged as error to capture 'cause'; Exception occurred when removing ourselves from provided FragmentManager java.lang.IllegalStateException: FragmentManager is already executing transactions at androidx.fragment.app.FragmentManager.ensureExecReady(FragmentManager.java:1636) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1666) at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317) at com.microsoft.identity.common.internal.providers.oauth2.AuthorizationFragment.finish(AuthorizationFragment.java:136) at com.microsoft.identity.common.internal.providers.oauth2.AuthorizationFragment.onCreate(AuthorizationFragment.java:94) at com.microsoft.identity.common.internal.providers.oauth2.WebViewAuthorizationFragment.onCreate(WebViewAuthorizationFragment.java:104) at androidx.fragment.app.Fragment.performCreate(Fragment.java:2981) at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:474) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:257) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1758) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701) at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:488) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8663) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
To Reproduce
Create the fragment where you would like to have the WebView.
As example, in sample app. it can be "MultipleAccountModeFragment" from the sample app.
Set the WebView client for "authorization_user_agent" : "WEBVIEW",
Add the "withFragment" to
val parameters: AcquireTokenParameters = AcquireTokenParameters.Builder() .withScopes(AzureUserAuthorizationApi.SCOPES) .startAuthorizationFromActivity(requireActivity())// we are inside fragment .withCallback(b2cAuthenticationCallback) *.withFragment(*this*)// this equals MultipleAccountModeFragment* .withPrompt(Prompt.LOGIN) .build()
call IMultipleAccountPublicClientApplication.acquireToken(parameters)
Expected behavior
I would like to have the WebView is run inside the fragment/over MultipleAccountModeFragment.
Also, I checked all the provided documentation, samples and I've not found anything how to use "withFragment" method correctly.
I kindly ask to document it and it can save a lot of time for developers. Right know it doesn't work.
Actual Behavior

The error log message is observed, the spinner is running.
I found that it by some reasons "savedInstanceState" and "mInstanceState" is null and it closes itself onCreate.
AuthorizationFragment.java
if (savedInstanceState == null && mInstanceState == null) { Logger.warn(methodTag, "No stored state. Unable to handle response"); **finish();** return; }
The text was updated successfully, but these errors were encountered: