Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Using Xamarin.Auth with Xamarin.Forms

$
0
0

How you can use Xamarin.Auth when you're using Xamarin.Forms?

I have this:

async public System.Threading.Tasks.Task<bool> LoginWithFacebook (object dialog, string FacebookAppID)
        {
            var user = new ParseUser ();
            var auth = new OAuth2Authenticator (
                           clientId: FacebookAppID,
                           scope: "",
                           authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
                           redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));
            auth.AllowCancel = true;
            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += async (object sender, AuthenticatorCompletedEventArgs ee) => {

                // Now that we're logged in, make a OAuth2 request to get the user's info.
                var accessToken = ee.Account.Properties ["access_token"].ToString ();
                var expiresIn = Convert.ToDouble (ee.Account.Properties ["expires_in"]);
                var expiryDate = DateTime.Now + TimeSpan.FromSeconds (expiresIn);

                // Now that we're logged in, make a OAuth2 request to get the user's id.
                var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account);
                var response = await request.GetResponseAsync ();
                var obj = JObject.Parse (response.GetResponseText ());
                var id = obj ["id"].ToString ().Replace ("\"", ""); // Id has extraneous quotation marks
                user = await ParseFacebookUtils.LogInAsync (id, accessToken, expiryDate);

            };
            var dvc = ((DialogViewController)dialog);
            dvc.PresentViewController (auth.GetUI (), true, null);
            return user.IsAuthenticated;
        }

But I can't cast ContentPage to DialogViewController or an Activity


Viewing all articles
Browse latest Browse all 91519

Trending Articles