none
Xamarin Localhost Debug Authentification RRS feed

  • Question

  • I'm working on an app that uses facebook login, and most of my custom api controllers need to know which the current user is to make an action based on that user.

    My problem is with authentication when running in localhost. For now I'm working with the "Attach Debugger" feature, but is very unproductive as it is very slow and have to publish again for every change. In the client I use (Xamarin.iOS):

    client = new MobileServiceClient ("http://[localhostIp]:[port]/", new NativeMessageHandler ());
    client.AlternateLoginHost = new Uri ("https://[name].azurewebsites.net/");

    And I obtain the current user as follows:

    var claimsPrincipal = this.User as ClaimsPrincipal;
    string sid = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier).Value;

    But in localhost I always receive null (throws NullPointerException). This should be a common problem, but after investigating for several hours I couldn't resolve it. How can I get the sid of the user that is sending the request in localhost? (doesn't matter if the token is valid or not, is just for testing purposes). I can add seed data in my localhost database with certain Users with defined sids to work with.

    Other quick question: I have my 'User' table, but I receive this unique and static Sid. I should put in my User table a column called "FacebookSid", set it the first time the user logs in, and create an index to retrieve it quickly in each request I need the user?

    Thanks!

    Friday, July 15, 2016 9:10 PM

Answers

All replies

  • To use authentication locally, see Local debugging with authentication.

    To learn more about SIDs, see Understanding User Ids in the server SDK wiki. You can use this SID as the index of your user table if you are using only Facebook auth, but if you're using another auth provider, then you probably need to create a custom user ID. 

    Friday, July 15, 2016 9:42 PM
    Moderator
  • Everything is resolved now, thanks donna!

    Sometimes it is hard to find some specific topic related documentation; the '.Net served SDK' documentation section is great, but a bit long. I would suggest (just a feedabck, maybe I'm just bad at finding) to put this section in a new separate doc page with more structuring.

    Regarding the unique sid, thanks for the link, helped me a lot. However, to use the "truly unique user id" as the PK assumes that your login provider will be always the same or that you have only one (maybe I'm wrong). Wouldn't be nice to have one unique sid for all service providers (like in AWS Cognito Identity where you can also merge identites)? I understand it keeps things simple, that's good. I think I will keep doing a "facebookSid" indexed column and use a GUID user id.

    Thanks!

    Monday, July 18, 2016 6:05 PM