简体   繁体   English

使用Xamarin自动登录Azure移动服务

[英]Azure mobile service auto-login with Xamarin

I'm brand new to Xamarin and playing around with a simple cross-platform app. 我是Xamarin的新手,正在玩一个简单的跨平台应用程序。

The app connects to an Azure Mobile Service, and requires login which I've set up server-side following tutorial : and client-side following tutorial . 该应用程序连接到Azure移动服务,并需要登录(我已在服务器端以下教程中设置了该登录)和在客户端以下教程中进行了设置

Everything works fine! 一切正常! However, the current implementation requires you to login everytime you start the app. 但是,当前的实现要求您在每次启动应用程序时登录。 How can i cache the user credentials and auto-login as long as you don't log out? 只要您不注销,我如何缓存用户凭据和自动登录?

I've tried something like this, but obviously didn't work: When a user is logging in I save (I'm not calling directly to MobileServiceClient, just showing you a snippet): 我已经尝试过类似的操作,但是显然没有用:当用户登录时,我保存了(我没有直接调用MobileServiceClient,只是向您显示了一个代码段):

 var userId = MobileServiceClient.CurrentUser.UserId;
 var authToken = MobileServiceClient.CurrentUser.MobileServiceAuthenticationToken

So i store these two strings, and when I next time open the app I try to: 所以我存储了这两个字符串,当我下次打开应用程序时,我尝试:

CurrentClient.CurrentUser = new MobileServiceUser(userId);
CurrentClient.CurrentUser.MobileServiceAuthenticationToken = authToken;

As I said this does not seem to be the correct way since it does not work. 正如我所说的那样,这似乎不是正确的方法,因为它不起作用。 What is the correct way to cache and auto-login an user? 缓存和自动登录用户的正确方法是什么?

You need to move over to a CLIENT-FLOW - in client-flow authentication, you use the client SDK provided by the auth provider and then pass that token silently to Azure Mobile Apps to authenticate there. 您需要移至客户端流-在客户端流身份验证中,您使用身份验证提供程序提供的客户端SDK,然后将该令牌静默传递给Azure移动应用程序以在此处进行身份验证。 Check out Chapter 2 of my book - http://aka.ms/zumobook 查看我的书的第2章-http://aka.ms/zumobook

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM