1
votes

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.

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.

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!

1

1 Answers

2
votes

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.