Question

I'm developing Windows Phone 8 application, and at first run I'm letting user auth from his Microsoft Account. User credentials are saving great, but permission screen ("Let this app access your info") is appearing everytime I'm running application.

How can I save my choice and display permission screen only once (first time I'm running app)?

Code snippet:

private LiveConnectSession _session;
    private async Task<Users> Authenticate()
    {

        var liveIdClient = new LiveAuthClient("XXXXXXXXXXXXXXX");

        while (_session == null)
        {
            var result = await liveIdClient.LoginAsync(new[]
                                                           {
                                                               "wl.signin",
                                                               "wl.offline_access"
                                                           });

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                _session = result.Session;
                var client = new LiveConnectClient(result.Session);
                var meResult = await client.GetAsync("me");
                var user = await App.MobileService.LoginAsync(result.Session.AuthenticationToken);
                return new Users
                {
                    UserName = user.UserId,
                    RealName = string.Format("{0} {1}", meResult.Result["first_name"], meResult.Result["last_name"]),
                    TimeStamp = DateTime.Now,
                    IsAuthorised = false
                };
            }
            else
            {
                _session = null;
                MessageBox.Show("You must log in.", "Login Required", MessageBoxButton.OK);
            }
        }
        return null;
    }

And in the constructor (public MainPage()):

(DataContext as MainViewModel).User = await Authenticate();
Was it helpful?

Solution 2

The code didn't work with my live account on emulator.

It is working well on device and emulator with other account.

OTHER TIPS

your app needs wl.offline_access scope in order to not keep requesting auth over and over.

wl.offline_access

http://msdn.microsoft.com/en-us/library/live/hh243646.aspx#wlofflineaccess

Scopes and permissions (Live Connect)

http://msdn.microsoft.com/en-us/library/live/hh243646.aspx

this is the post I used to discover offline_access

http://dotnet.dzone.com/articles/things-know-about-uploading?mz=27249-windowsphone7

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top