0

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:

enter image description here

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:

enter image description here

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

pixel
  • 6,765
  • 12
  • 60
  • 101

3 Answers3

0

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

Cherry Bu - MSFT
  • 7,773
  • 1
  • 5
  • 12
  • Sorry but Entry has nothing to do with this. Also, the other 2 links are not related to the topic. This is issue with ADAL authentication flow in Xamarin.Forms Android. Thanks anyways! – pixel Jul 02 '19 at 17:09
0

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).

Jenny
  • 1,023
  • 4
  • 11
0

This issue is caused by Microsoft's ADAL component Microsoft.IdentityModel.Clients.ActiveDirectory and it has been fixed in 5.1.0 version released just couple of weeks ago (current version is 5.2.0).

What I had to do in order to fix this issue is: 1. Update ADAL from 3.19.8 to 5.2.0 (everything below 5.1.0 has this problem) 2. Then modified AuthorityURL passed to AuthenticationContext c-tor from something like https://login.microsoftonline.com/my-tenant-id/oauth2/authorize to https://login.microsoftonline.com/my-tenant-id

Number 2 was necessary even though Microsoft claims in most places that the change is non-breaking change (they confirmed this is necessary).

After this, I was able to authenticate just like before but rotation on Android would not loose already provided user id and/or password.

pixel
  • 6,765
  • 12
  • 60
  • 101