0

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();
Zozo
  • 870
  • 1
  • 8
  • 27
  • Would be awesome if you could share a snippet that shows how you're acquiring (and where) the session. – Den Mar 07 '13 at 00:32

2 Answers2

0

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

Hermit Dave
  • 3,036
  • 1
  • 13
  • 13
  • I don't think there is anything beyond that option.. In my app, I can clearly see request for "Access and edit your SkyDrive", "Access your information at any time" and "View your SkyDrive photos and documents" . Restarting the app does not require signing in again – Hermit Dave Mar 06 '13 at 15:40
-1

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

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

Zozo
  • 870
  • 1
  • 8
  • 27