在Android Xamarin中的WebAuthenticationBroker.AuthenticateAsync

时间:2014-02-26 04:46:25

标签: c# android xamarin.android xamarin

我正在使用Xamarin开发一个跨平台的Android应用程序。目前我坚持WebAuthenticationBroker.AuthenticateAsync方法,找不到与之相当的东西。

这是我想在android中做的事情:

       var broker = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);

            var datax = broker.ResponseData;
            if (broker.ResponseStatus != WebAuthenticationStatus.Success)
                await new Windows.UI.Popups.MessageDialog("Invalid username or user doesn't exists").ShowAsync();

根据文档,截至目前,xamarin中没有WebAuthenticationBroker。是否有任何解决方法可以实现相同的目标? 任何想法如何用xamarin中的android实现。

1 个答案:

答案 0 :(得分:0)

你看过Xamarin.Auth了吗?看起来这就是你想要的。这是一个小代码片段,它会给你一个关于你可以用它做什么的提示:

using Xamarin.Auth;
...
var auth = new OAuth2Authenticator (
    clientId: "App ID from https://developers.facebook.com/apps",
    scope: "",
    authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
    redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

回调事件:

auth.Completed += (sender, eventArgs) => {
    // We presented the UI, so it's up to us to dimiss it on iOS.
    DismissViewController (true, null);

    if (eventArgs.IsAuthenticated) {
        // Use eventArgs.Account to do wonderful things
    } else {
        // The user cancelled
    }
};