Reputation: 29
I'm having some trouble with learning Xamarin, I realize this is a high level question, I apologize.
I have successfully been able to authenticate with FB as my auth provider, and have been able to use loginasync to authenticate with my app backend, however how do I continue to use that user that has been logged in after you've moved to a different activity? After I've brought up a new activity, when I call my app service, I get the unauthorized error.
Just finding a lack of documentation/samples on how a project should be set up while using a MobileServiceUser across the whole app.
Any help is much appreciated, thanks!
Upvotes: 1
Views: 202
Reputation: 9703
If you have a look at the "Sport" sample app from Xamarin here which uses MobileServiceUser
.
Even tho it is a forms app (and you are looking for an Android sample) you can see how it manages to use the Settings singleton class to keep a reference to the MobileServiceUser
user
property. This is where the app sets that property like so:
AuthenticationStatus = "Loading...";
MobileServiceUser user = await _authenticator.DisplayWebView();
var identity = await AzureService.Instance.Client.InvokeApiAsync("getUserIdentity", null, HttpMethod.Get, null);
App.AuthToken = identity.Value<string>("accessToken");
Utility.SetSecured("AuthToken", App.AuthToken, "xamarin.sport", "authentication");
Settings.Instance.User = user;
await Settings.Instance.Save();
There are some more samples in the xamarin docs here
This Todo app also has a similar pattern with its TodoService singleton
Upvotes: 1