WebAuthenticationBroker.AuthenticateAsync in andro

2019-09-06 12:51发布

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条回答
甜甜的少女心
2楼-- · 2019-09-06 13:22

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
    }
};
查看更多
登录 后发表回答