Metro App - How to detect if logged in with Live ID or Local Account
c#, live-connect-sdk, liveconnect, microsoft-metro, windows-8
Solution
Found the answer: http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.authentication.onlineid.onlineidauthenticator.cansignout.aspx#Y0
Below is the property that we need to use:
Windows.Security.Authentication.OnlineId.OnlineAuthenticator.CanSignOut
Code Example:
public async Task<bool> Logout()
{
// Check to see if the user can sign out (Live account or Local account)
var onlineIdAuthenticator = new OnlineIdAuthenticator();
var serviceTicketRequest = new OnlineIdServiceTicketRequest("wl.basic", "DELEGATION");
await onlineIdAuthenticator.AuthenticateUserAsync(serviceTicketRequest);
if (onlineIdAuthenticator.CanSignOut)
{
LiveAuthClient.Logout();
}
return true;
}
Problem
I am building a Metro C# SkyDrive API on top of the Live Connect SDK (http://msdn.microsoft.com/en-us/live/default) - in Windows 8 the user has the choice to SignIn to the Windows 8 machine with either a LOCAL account, or a LIVE account. When using the Live Connect SDK, if I call ``` // assume wlscopes is properly set LiveAuthClient liveAuthClient = new LiveAuthClient(); LiveLoginResult loginResult = await liveAuthClient.LoginAsync(wlscopes); // do some stuff on skydrive liveAuthClient.Logout(); // <-- issue only with live account, not local ``` when using a LOCAL account, it logs me out (great) When I call the same code when using a LIVE account, I get an unhanded exception -- I cannot even add a try {} catch {} around this error. Exception: ``` Cannot sign out from the application since the user account is connected. (Exception from HRESULT: 0x8086000E) ``` Obviously since the user that is logged in under a Live account cannot logout, my api needs to detect if the current user is using a live account so I can prevent calling the logout() method. so....My question is, how do I know which account type the user has signed in with in Windows 8?