我使用ADAL和ADFS来验证Xamarin中的web api调用,并且在重复身份验证过程时遇到问题,它似乎在从内存缓存中获取令牌时遇到了问题。
有趣的是,我有另一个演示应用程序执行相同的操作并且没有相同的问题......
使用的代码如下所示,如果有人可以屏蔽一些关于如何进一步调试它的灯,将非常感激。
try
{
AuthenticationContext ac = new AuthenticationContext(authority, false);
try
{
ar = ac.AcquireTokenSilentAsync(resourceURI, clientID).Result;
}
catch (AggregateException exc)
{
//do nothing?
}
if (ar == null)
{
ar = await ac.AcquireTokenAsync(resourceURI, clientID, new Uri(clientReturnURI), parent);
}
**catch (Exception ex)** //always been hit
{
2016-08-14 22:54:46.075 TimeSheetiOS [70494:1224472] 8/15/2016 5:54:46 AM:c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs:向上看 缓存令牌... 2016-08-14 22:54:46.076 TimeSheetiOS [70494:1224472] 8/15/2016 5:54:46 AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs:匹配的项目 请求的资源在缓存中找到2016-08-14 22:54:46.076 TimeSheetiOS [70494:1224472] 8/15/2016 5:54:46 AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs:29.0067555833333 剩余分钟,直到缓存中的令牌到期2016-08-14 22:54:46.077 TimeSheetiOS [70494:1224472] 8/15/2016 5:54:46 AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs:匹配项 (在缓存中找到(访问令牌或刷新令牌或两者) 2016-08-14 22:54:46.082 TimeSheetiOS [70494:1224472] 8/15/2016 5:54:46 AM:c7b85581-cef2-492c-86ee-5686a5d4de67 - AcquireTokenHandlerBase.cs: System.ArgumentNullException:未将参数设置为实例的字符串引用 一个字符串。参数名称:s在System.Text.Encoding.GetBytes (System.String s)[0x00006] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/text/encoding.cs :1083 在 Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.CreateSha256Hash (System.String输入)[0x0000c] in:0 at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.LogReturnedToken (Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult 结果)[0x00067] in:0 at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.PostRunAsync (Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult 结果)[0x