持续性认证的Azure移动服务 [英] Azure Mobile Services with persistent authentication

查看:165
本文介绍了持续性认证的Azure移动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现我的Windows Phone应用程序使用Windows Azure移动服务的身份验证。我按照官方教程和认证工作正常。的问题是,每当应用程序被关闭和重新启动时,用户必须输入用户名和密码。由于该服务只使用认证令牌,记住我在登录页面选择是不可能奏效。

I am trying to implement authentication with Windows Azure Mobile Services in my Windows Phone app. 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.

有关Windows Azure的官方文档显示单点登录与使用Live SDK的Microsoft帐户的可能性。在Live SDK提供了字符串的形式验证令牌。然而,即使此令牌的有效期大约为24小时。而且,该被限制为Microsoft帐户唯一

The official documentation for Windows Azure shows possibility of Single Sign On with the Microsoft account using the Live SDK. The Live SDK provides authentication token in form of string. However, even this token expires in about 24 hours. Moreover, this is restricted to the Microsoft Account only.

什么是我的机会,如果我想缓存用户的身份,并在启用自动登录?我已经通过文章<一走href=\"http://www.thejoyof$c$c.com/Setting_the_auth_token_in_the_Mobile_Services_client_and_caching_the_user_rsquo_s_identity_Day_10_.aspx\"相对=nofollow>此处。用户仍会有一次令牌到期重新登录。我看到这需要用户的应用程序在一次签字!

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!

推荐答案

如果您使用Live SDK,用户只需要登录一次。你会尽一切时间到Live SDK的调用,但SDK本身将管理缓存令牌你,需要(在大多数的情况下,无需用户干预),当它请求到服务器 - 例如见$ C以下$ C。

If you use the Live SDK, the user will only have to sign in once. 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.

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.

这篇关于持续性认证的Azure移动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆