0
votes

I've been stuck in authentication problems for a long time now and I've tried everything that was possible to do but I can't find a solution for this problem.

I am using Azure Mobile Services as a backend to my app and everything works perfectly except for the authentication part. I am pretty sure I followed every single step of the documentation and revised it again and again.

The error happens after using LoginAsync(): "Cannot GET /.auth/login/twitter?................etc"

Here is my AppDelegate Code for Xamarin.iOS:

[Register("AppDelegate")]
public partial class AppDelegate : FormsApplicationDelegate, IAuthenticate
{

        private MobileServiceUser user { get; set; }
    public async Task<bool> Authenticate()
    {
        var res = false;
        if(user == null){
            //var json = new JObject();
            //json.Add("access_token","my token");
            Dictionary<string,string> dict = new Dictionary<string,string>();
            dict.Add("access_token","my token");

            try
            {
                user = await MyManager.DefaultManager.CurrentClient.LoginAsync(UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController,
                                                                                 MobileServiceAuthenticationProvider.Twitter,
                                                                                 "my scheme");

                if (user == null)
                {
                    res = false;
                }
                else
                {
                    res = true;
                }

            }catch(Exception e){
                System.Diagnostics.Debug.WriteLine("Login Status: " + e.Message);
            }
        }

        System.Diagnostics.Debug.WriteLine("Login Status: "+res);

        return res;
    }

    public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
    {
        return MyManager.DefaultManager.CurrentClient.ResumeWithURL(url);
    }


    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {

        Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
    //Initializing authenticator
          App.Init(this);

        LoadApplication(new App());
        UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);

        return base.FinishedLaunching(app, options);
    }

Note that when I change the "Action to take when request is not authenticated" to other than "nothing," it redirects to Facebook authentication (Which surprisingly works this way!!) automatically even if I chose Twitter, but I don't get the result in the app.

Thank you very much

1

1 Answers

1
votes

The error happens after using LoginAsync(): "Cannot GET /.auth/login/twitter?................etc"

Based on your LoginAsync method, you are using server-managed flow. I would recommend you make sure you have configured the settings correctly on Azure Portal for Twitter provider. You could just browser at https://yoursite.azurewebsites.net/.auth/login/twitter and find that whether you could get the successful authentication page to narrow this issue. I just created my azure mobile backend and downloaded the quick start sample to check this issue, for your mobile client, just reference the Microsoft.Azure.Mobile.Client and followed here for adding authentication to your Xamarin Forms app.