【发布时间】:2017-05-22 09:20:10
【问题描述】:
我正在尝试对 Xamarin Forms 应用程序进行身份验证,但找不到 Windows 命名空间类和方法的替代方法:WebAuthenticationBroker.GetCurrentApplicationCallbackUri。
对于 Xamarin Forms UWP 应用,我可以使用它来获取 RedirectURL,但我不确定如何处理 iOS 和 Android 应用。
class Authenticator : IAuthenticator
{
/// <summary>
/// Address to return to upon receiving a response from the authority.
/// </summary>
private static readonly Uri RedirectURI = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
public async Task<AuthenticationResult> AuthenticateAsync(UserLogOn user, string authority, string resource, Uri redirectURI, string clientId)
{
PlatformParameters platformParams = new PlatformParameters(PromptBehavior.Always, false);
try
{
var authContext = new AuthenticationContext(authority);
var authResult = await authContext.AcquireTokenAsync(resource, clientId, RedirectURI, platformParams);
return authResult;
}
catch (Exception e)
{
Debug.WriteLine($"AquireTokenAsync Error: {e.Message}");
return null;
}
}
}
谢谢你, 标记
【问题讨论】:
-
就目前而言,由于缺少一些细节,因此很难提供一个好的问题。您使用哪个库进行身份验证?
Xamarin.Auth?您显示的代码是为 UWP 显示的吗? -
是的,这是 UWP 代码,我正在使用 ADAL:Microsoft.IdentityModel.Clients.ActiveDirectory。 Xamarin.Auth 看起来两年多没有接触过,所以我不确定是否要使用它。但我很灵活。主要的是,我需要一个包含所有正确信息的令牌,并且 GetCurrentApplicationCallbackUri 方法显然将应用程序的 Window Store ID 和 RedirectURL 关联在一起。因此,对于 iOS 和 Android 应用程序,我认为我需要弄清楚如何在 iOS 和 Android 中使用 GetCurrentApplicationCallbackUri 方法。
-
@MarkGarcia 顺便说一句,我知道 Xamarin Auth 库令人困惑,因为那里有一个旧的,但 this 版本确实会定期更新。
-
感谢您让我知道 hvaughan3。我试试看!
标签: c# xamarin xamarin.forms adal