在Xamarin Forms iOS应用程序中调用ADAL AcquireTokenAsync时为空引用

时间:2015-11-27 05:12:31

标签: c# xamarin.ios xamarin.forms adal

使用ADAL验证Xamarin iOS应用程序。在初次登录时一切都很好,但是当退出并再次注销时(例如,当AccessToken在90天后过期时重定向到登录),应用程序崩溃并带有以下内容

Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
at Xamarin.Forms.Platform.iOS.Platform.DidAppear () [0x0000d] in :0
at Xamarin.Forms.Platform.iOS.PlatformRenderer.ViewDidAppear (Boolean animated) [0x00006] in :0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2077/d8e9592a/source/maccore/src/UIKit/UIApplication.cs:74
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2077/d8e9592a/source/maccore/src/UIKit/UIApplication.cs:57
at MyAwesomeApp.iOS.Application.Main (System.String[] args) [0x0000c] in d:\Working\City.Australia\MyAwesomeApp\Main\MyAwesomeApp\MyAwesomeApp\MyAwesomeApp.iOS\Main.c
s:18

源代码

var view = appDelegate.RootViewController;
appDelegate.MakeKeyAndVisible();
AdalInitializer.Initialize();
var azureSettings = AzureSettings.GetSettings();
AuthenticationContext authenticationContext = new AuthenticationContext(azureSettings.AdAuthority);

下一行是失败的地方

AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(azureSettings.AdResource,
azureSettings.AdClientId,
new Uri(azureSettings.AdRedirect),
new AuthorizationParameters(view),
UserIdentifier.AnyUser,
string.Format(“domain_hint={0}”, azureSettings.AdDomainHint));

就像我提到的那样,第一次登录是好的,但是再次签出和签名会导致 AcquireTokenAsync 调用中的Null引用异常。如果有人遇到此问题或熟悉此问题,请告诉我。

问题不在于ADAL库调用,而在于UIViewController。尝试使其线程安全并经过测试,任务延迟但一旦到达 AcquireTokenAsync 应用程序崩溃并引用空引用异常

无法立即获得示例应用,但如果没有取得多大成功,将尝试获取该应用。

Xamarin表格:1.4

ADAL(Microsoft.IdentityModel.Clients.ActiveDirectory):3.1.0.0

任何建议/帮助非常感谢。

此致

Vinod Srinivasan

0 个答案:

没有答案