Facebook login failed with Xamarin.Auth

PassionateCreativePassionateCreative USMember ✭✭
edited October 2017 in Xamarin.Forms

I am developing an app that needs Facebook and Google login in Xamarin Forms.

I found a guidance here for social login.
https://developer.xamarin.com/guides/xamarin-forms/cloud-services/authentication/oauth/

I was able to get success in Google login with that guidance

Here is the code that I've tried for Google login.

    string clientId = null;
    string redirectUri = null;

    switch (Device.RuntimePlatform)
    {
            case Device.iOS:
                clientId = ApiUrl.iOSClientId;
                redirectUri = ApiUrl.iOSGoogleRedirectUrl;
                break;

            case Device.Android:
                clientId = ApiUrl.AndroidClientId;
                redirectUri = ApiUrl.AndroidGoogleRedirectUrl;
                break;
    }

    var authenticator = new OAuth2Authenticator(
            clientId,
            null,
            ApiUrl.GoogleScope,
            new Uri(ApiUrl.GoogleAuthorizeUrl),
            new Uri(redirectUri),
            new Uri(ApiUrl.GoogleAccessTokenUrl),
            null,
            true
    );

    authenticator.Completed += OnAuthCompleted;
    authenticator.Error += OnAuthError;

    AuthenticationState.Authenticator = authenticator;

    var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
    presenter.Login(authenticator);

The redirect urls like these

public static string iOSGoogleRedirectUrl = "com.googleusercontent.apps.675078306211-aqmafds8gk67h538eqius9pg9j89ajoc:/oauth2redirect";
public static string AndroidGoogleRedirectUrl = "com.googleusercontent.apps.675078306211-b0t2i7sbcrp05ilt6iu4k455snbov7cp:/oauth2redirect";

I've tried similar thing in facebook login. Here is the code that I've tried for Facebook login.

    var authenticator = new OAuth2Authenticator(
            ApiUrl.AppId,
            ApiUrl.FacebookScope,
            new Uri(ApiUrl.FacebookAuthorizeUrl),
            new Uri(ApiUrl.FacebookRedirectUrl),
            null,
            true
    );

    authenticator.Completed += OnAuthCompleted;
    authenticator.Error += OnAuthError;

    AuthenticationState.Authenticator = authenticator;

    var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
    presenter.Login(authenticator);

The redirect url likes this

public static string FacebookRedirectUrl = "fb506102719744051:/oauth2redirect";

But I am getting error in Facebook login.

I think I may have an error in redirect url for facebook. but I am not sure what should be set for redirect url in facebook.

Please help me to fix this!
Sorry for my English, Thanks.

Answers

Sign In or Register to comment.