Azure AD (ADAL) Login Screen Loses Entered User Email on Device Orientation in Android Only-XamarinForms.Android

妖精的绣舞 提交于 2019-12-13 03:18:43

问题


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




回答3:


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.



来源:https://stackoverflow.com/questions/56813381/azure-ad-adal-login-screen-loses-entered-user-email-on-device-orientation-in-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!