Authentication with Facebook by using Xamarin.Auth

1.8k Views Asked by At

I am using Xamarin.Auth for login with facebook in my app(android/iOS) and all is going well but when successfully loged in, facebook profile is opening and not going back to my application. i want to redirect to my app's home page without showing facebook profile. i am following this tutorial and not get any success. i think i am not giving proper Urls of my app. Please give me suggestions. your help will be appreciated thanks in advance.

here is my code of loginPageRenderer:

[assembly: ExportRenderer (typeof (FBLoginPage), typeof (LoginPageRendrerr))]
 namespace FFirst_app.Droid
 {
public class LoginPageRendrerr : PageRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        // this is a ViewGroup - so should be able to load an AXML file and FindView<>
        var activity = this.Context as Activity;

        var auth = new OAuth2Authenticator (
            clientId: "7b745e26dbb64e1a3a3bf6bfd33165bc", // your OAuth2 client id
            scope: "basic", // the scopes for the particular API you're accessing, delimited by "+" symbols
            authorizeUrl: new Uri("https://apps.facebook.com/myappppppp"),//("https://api.instagram.com/oauth/authorize/"), // the auth URL for the service
            redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html")); // the redirect URL for the service

        auth.Completed += (sender, eventArgs) => {
            if (eventArgs.IsAuthenticated) 
            {
                App.SuccessfulLoginAction.Invoke();

                // Use eventArgs.Account to do wonderful things
                App.SaveToken(eventArgs.Account.Properties["access_token"]);

                string sessionToken = App.Token;   //  /* Authenticate the user with Facebook and fetch a session token */;
                DateTime expiration =  DateTime.Today;  ///* The expiration time for the session token */;
                string facebookId = Constants.FBAppId;
                 ParseFacebookUtils.LogInAsync (facebookId, sessionToken, expiration);

            } else {
                // The user cancelled
            }



        };

        activity.StartActivity (auth.GetUI(activity));
    }
}

 }
2

There are 2 best solutions below

0
On BEST ANSWER

I have found answer that i was wrong with URL's and now its working after when i changed 'authorizeUrl:' to "http://www.facebook.com/connect/login_success.html" and this URl also set on FB App as it is.So now my code is working properly.

0
On

On the Xamarin.Auth Getting Started page, it is mentioned that it is up to you to dismiss the UI on iOS:

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