简体   繁体   English

具有持久身份验证的Azure移动服务

[英]Azure Mobile Services with persistent authentication

I am trying to implement authentication with Windows Azure Mobile Services in my Windows Phone app. 我正在尝试在Windows Phone应用中使用Windows Azure移动服务实现身份验证。 I have followed the official tutorials and the authentication works fine. 我遵循了官方教程,并且身份验证正常。 The issue is that, whenever the app is closed and started again, the user has to enter username and password. 问题是,每当关闭应用程序并再次启动它时,用户都必须输入用户名和密码。 Since the services only use authentication tokens, the 'Remember me' option on log in page is not likely to work. 由于服务仅使用身份验证令牌,因此登录页面上的“记住我”选项不太可能起作用。

The official documentation for Windows Azure shows possibility of Single Sign On with the Microsoft account using the Live SDK. Windows Azure的官方文档显示了使用Live SDK通过Microsoft帐户进行单点登录的可能性。 The Live SDK provides authentication token in form of string . Live SDK以string形式提供身份验证令牌。 However, even this token expires in about 24 hours. 但是,即使该令牌也会在约24小时后过期。 Moreover, this is restricted to the Microsoft Account only. 此外,这仅限于Microsoft帐户。

What are my possibilities if I want to cache the user's identity and enable automatic log in? 如果我想缓存用户的身份并启用自动登录,该怎么办? I have already gone through the article here . 我已经在这里浏览了这篇文章。 User will still have to log in again once the token expires. 令牌过期后,用户仍然必须再次登录。 I have seen apps which require user to sign in only once! 我看到过要求用户仅登录一次的应用程序!

If you use the Live SDK, the user will only have to sign in once. 如果您使用Live SDK,则用户只需登录一次。 You'll be making a call to the Live SDK every time, but the SDK itself will manage caching the token for you, and requesting it to the server when needed (in the great majority of the cases without user intervention) - see example code below. 您每次都会调用Live SDK,但SDK本身将为您管理令牌的缓存,并在需要时将其请求到服务器(在大多数情况下,无需用户干预)-请参阅示例代码下面。

var liveIdClient = new LiveAuthClient(clientId);
var liveLoginResult = await liveIdClient.LoginAsync("wl.basic wl.signin".Split());
if (liveLoginResult.Status == LiveConnectSessionStatus.Connected) {
    var token = new JObject();
    token.Add("authenticationToken", liveLoginResult.Session.AuthenticationToken);
    var user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, token);
}

Notice that if you're running your app on an emulator, it's possible that the login information will be lost if you close the emulator (I've seen this in the past). 请注意,如果您是在模拟器上运行应用程序,则关闭模拟器可能会丢失登录信息(我以前已经看到过)。 However, when running on a real device, or if you leave the emulator opened for long stretches of time) you should only need to login once. 但是,在真实设备上运行时,或者长时间不打开仿真器时,您只需登录一次即可。

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

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