Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin.iOS使用MSAL身份验证失败:基于浏览器的身份验证对话框无法完成_C#_Azure_Xamarin.ios_Xamarin.forms_Azure Ad B2c - Fatal编程技术网

C# Xamarin.iOS使用MSAL身份验证失败:基于浏览器的身份验证对话框无法完成

C# Xamarin.iOS使用MSAL身份验证失败:基于浏览器的身份验证对话框无法完成,c#,azure,xamarin.ios,xamarin.forms,azure-ad-b2c,C#,Azure,Xamarin.ios,Xamarin.forms,Azure Ad B2c,我创建了一个Xamarin.Forms应用程序,它使用MSAL对Azure B2C目录中的用户进行身份验证。我设置了以下示例中的所有内容: 我在main活动和AppDelegate中指定我的PlatformParameters。然后在我的主页中调用AquireTokenAsync()方法,如下所示: AuthenticationResult ar = await App.AuthenticationClient.AcquireTokenAsync(Config.Scopes, string.E

我创建了一个Xamarin.Forms应用程序,它使用MSAL对Azure B2C目录中的用户进行身份验证。我设置了以下示例中的所有内容:

我在
main活动
AppDelegate
中指定我的
PlatformParameters
。然后在我的
主页中
调用
AquireTokenAsync()
方法,如下所示:

AuthenticationResult ar = await App.AuthenticationClient.AcquireTokenAsync(Config.Scopes, string.Empty, 
                                UiOptions.SelectAccount, string.Empty, null,
                                Config.Authority, Config.SignUpSignInpolicy);
此代码在Android中运行良好,并正确显示了一个
WebView
,我的用户可以在其中成功登录

但是,当我在iPhone模拟器(iPhone 7 Plus-iOS 10.2)上执行此代码时,应用程序崩溃并抛出MsalException,其中包含以下消息:

authentication_ui_failed: The browser based authentication dialog failed to complete
以下是堆栈跟踪的其余部分:

Authority: https://login.microsoftonline.com/<myAuthority>/
    Scope: <myClientId>
    ClientId: <MyClientId>
    CacheType: null
3/21/2017 8:41:10 PM: - WebUI.cs: System.NullReferenceException: Object reference not set to an instance of an object
 at Microsoft.Identity.Client.WebUI.Authenticate (System.Uri authorizationUri, System.Uri redirectUri, System.Collections.Generic.IDictionary`2[TKey,TValue] additionalHeaders, Microsoft.Identity.Client.Internal.CallState callState) [0x00029]
Mar 21 15:41:10 3/21/2017 8:41:10 PM: - AcquireTokenHandlerBase.cs: Microsoft.Identity.Client.MsalException: authentication_ui_failed: The browser based authentication dialog failed to complete ---> System.NullReferenceException: Object reference not set to an instance of an object
 at Microsoft.Identity.Client.WebUI.Authenticate (System.Uri authorizationUri, System.Uri redirectUri, System.Collections.Generic.IDictionary`2[TKey,TValue] additionalHeaders, Microsoft.Identity.Client.Internal.CallState callState) [0x00029]
权限:https://login.microsoftonline.com//
范围:
客户ID:
CacheType:null
2017年3月21日下午8:41:10:-WebUI.cs:System.NullReferenceException:对象引用未设置为对象的实例
在Microsoft.Identity.Client.WebUI.Authenticate(System.Uri授权Uri,System.Uri重定向Uri,System.Collections.Generic.IDictionary`2[TKey,TValue]附加标头,Microsoft.Identity.Client.Internal.CallState CallState)[0x00029]
2017年3月21日15:41:10 3/21 8:41:10 PM:-AcquireTokenHandlerBase.cs:Microsoft.Identity.Client.MsalException:authentication\u ui\u失败:基于浏览器的身份验证对话框未能完成---->System.NullReferenceException:对象引用未设置为对象的实例
在Microsoft.Identity.Client.WebUI.Authenticate(System.Uri授权Uri,System.Uri重定向Uri,System.Collections.Generic.IDictionary`2[TKey,TValue]附加标头,Microsoft.Identity.Client.Internal.CallState CallState)[0x00029]

我发现了另一个类似的问题,即我需要为我的应用程序添加一些功能,但我找不到如何为Xamarin.iOS应用程序添加这些功能。

我最终发现了我的愚蠢错误,但万一其他人遇到同样的问题,这就是我的痛苦:


我正在调用页面构造函数中的
AquireTokenAsync()
方法,因此它还没有完成加载。显然,这不是Android的问题,但是为了让网页在iOS中弹出,页面需要已经加载。我将我的
AquireTokenAsync
调用移动到我的
OnAppearing()
方法,现在它可以工作了

我终于明白了我愚蠢的错误,但万一其他人遇到同样的问题,我的痛苦就在于此:


我正在调用页面构造函数中的
AquireTokenAsync()
方法,因此它还没有完成加载。显然,这不是Android的问题,但是为了让网页在iOS中弹出,页面需要已经加载。我将我的
AquireTokenAsync
调用移动到我的
OnAppearing()
方法,现在它可以工作了

我想我发现的类似问题是使用Windows而不是iOS,所以我可能没有遗漏这一权限。有人知道如何修复这个错误吗?我能找到的代码与在iOS上工作的代码之间的唯一区别是安装了NuGet软件包。可能是我的某个NuGet软件包导致了这个错误吗?我想我发现的类似问题是使用Windows而不是iOS,所以我可能没有丢失这个权限。有人知道如何修复这个错误吗?我能找到的代码与在iOS上工作的代码之间的唯一区别是安装了NuGet软件包。可能是我的某个NuGet软件包导致了此错误吗?