Search code examples
windows-8live

Can the Windows 8 Live SDK use another Microsoft Account other than the current user?


Using the Windows 8 Live SDK you can have a user give you permission to their Microsoft Account. With this you can get their name and photo and more. But using the Live SDK appears to require the user of the app to use the same Microsoft Account as whoever is signed into the current session of Windows 8.

In some scenarios, using a different account is very legitimate.

I have simple sign-in working like a charm! This uses the same account.

I can't find a way to do use another. Is it possible?


Solution

  • You can call Logout after Init and before LoginUser.

    Here's the code for javascript:

    function LiveLogin(){
       WL.init("<<Your clientID goes here>>");
    
       if (WL.canLogout()) {
           WL.logout(function () {Callback(callback);});
       }
       else{
           Callback(callback);
       }
    }
    
    function Callback(){
    WL.login({ scope: ["wl.signin", "wl.basic", "wl.emails"] }, function () {
            var session = WL.getSession();
            // do stuff with your session
        });
    }
    

    And this is for C#:

    LiveAuthClient liveAuthClient = new LiveAuthClient();
    List<string> scopes = new List<string>();
    scopes.Add("wl.signin");
    scopes.Add("wl.basic");
    scopes.Add("wl.emails");
    LiveLoginResult loginResult = await liveAuthClient.InitializeAsync();
    if (liveAuthClient.CanLogout)
    {
        liveAuthClient.Logout();
    }
    
    loginResult = await liveAuthClient.LoginAsync(scopes);
    

    It worked for me. I hope this is what you are looking for.