WebAuthenticationBroker.AuthenticateAsync in android Xamarin

不羁的心 提交于 2019-12-25 03:08:18

问题


Iam developing a cross platform android app using Xamarin. Currently I am stuck with the WebAuthenticationBroker.AuthenticateAsync method and cannot find anything equivalent to it.

Here is something I want to do in 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();

According to the documentation there is no WebAuthenticationBroker in xamarin as of now. Is there any work around for achieving the same? Any ideas how this can be achieved with android in xamarin.


回答1:


Did you look at the Xamarin.Auth? It seems like that's what you want. Here is a little code snippet which would give you a hint about what you can do with it:

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"));

The callback event:

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
    }
};


来源:https://stackoverflow.com/questions/22031990/webauthenticationbroker-authenticateasync-in-android-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!