Xamarin 与 Azure MobileServiceUser

Xamarin with Azure MobileServiceUser

我在学习 Xamarin 时遇到了一些问题,我意识到这是一个高层次的问题,我深表歉意。

我已经成功地通过 FB 作为我的身份验证提供商进行身份验证,并且已经能够使用 loginasync 对我的应用程序后端进行身份验证,但是我如何继续使用在您之后登录的用户'已经搬到另一个 activity 了吗?在我创建一个新的 activity 之后,当我调用我的应用程序服务时,我收到了未经授权的错误。

只是发现缺少 documentation/samples 关于在整个应用程序中使用 MobileServiceUser 时应如何设置项目的问题。

非常感谢任何帮助,谢谢!

如果您查看来自 Xamarin here 的 "Sport" 示例应用程序,它使用 MobileServiceUser

即使它是一个表单应用程序(并且您正在寻找 Android 示例),您也可以看到它如何设法使用 Settings singleton class to keep a reference to the MobileServiceUser user property. This 是应用程序设置 属性 像这样:

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(); 

xamarin 文档中还有一些示例 here

这个Todo app also has a similar pattern with its TodoService单例