Azure AD (ADAL) Login Screen Loses Entered User Em

2019-08-26 09:17发布

问题:

I have Xamarin.Forms application that authenticates user against Azure AAD using ADAL (Microsoft.IdentityModel.Clients.ActiveDirectory). That all works fine but on Android, device orientation looses user email on the Microsoft authentication screen.

Here I am in Portrait mode and I have entered user email:

Clicking on Next lands on screen asking to enter password. If I now rotate device on Android, it will return me back to blank screen above, user email I entered above is lost:

Device rotation should not return user back and re-prompt for user email again. It should stay on password prompt.

How do I prevent the rotation from re-prompting for user email? I dont want to disable rotation, I just want to prevent it from returning me back to screen that prompts for user email again.

This is Xamarin.Forms application and my MainActivity has already ConfigChages.Orientation attribute like below; however, this is not solving the issue:

[Activity(Name = "my.mainactivity"
, Label = "MyApp"
, Icon = "@drawable/icon"
, ConfigurationChanges = ConfigChanges.ScreenSize 
    | ConfigChanges.SmallestScreenSize 
    | ConfigChanges.ScreenLayout 
    | ConfigChanges.Orientation)]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
   ...
}

UPDATE

Even if I freeze orientation to Portrait before call to AcquireTokenAsync and unfreeze it after the call receives response, it still behaves same - it will still rotate the Microsoft sign in page even though I freeze its parent (MainActivity) to Portrait (which is the owner passed in PlatformParameters to the call to AcquireTokenAsync. So, my activity stays in portrait but that sign-in page still rotates and looses data. It appears that the WebView Microsoft uses internally in AcquireTokenAsync is not following orientation settings on the activity passed inside PlatformParameters to AcquireTokenAsync.

Confirmed by Microsoft that this is their internal issues. If you are also running into this issue on Android where device rotation returns you back to prompt for user email, you can follow up progress of fixes for both ADAL and MSAL here:

https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/1622 https://github.com/xamarin/xamarin-android/issues/3326

回答1:

I use Entry at my side, adding ConfigurationChanges = ConfigChanges.ScreenSize| ConfigChanges.Orientation, it works fine.

If you still have this issue, I suggest you can follow the next steps:

1.on Forms PCL, you can override OnSizeAllocated to check screen orientation, like this:

How to detect screen orientation of the device in Xamarin.Forms?

2.On Forms PCL and Android, you can use MessageCener to subscribe and send data

3.override method onSaveInstanceState() and onRestoreInstanceState(), like this:

Handle screen rotation without losing data - Android



回答2:

The issue has been fixed in ADAL Release 5.1.1, and will be included in the next version of MSAL (most likely 4.3.1).