Metro app - how to detect if you are logged in using a Live ID or local account

I am creating the 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 option to log in to Sign In Windows 8 with a LOCAL account or LIVE.

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 of the system (excellent)

When I call the same code when using a LIVE account, I get an exception without exception - I canโ€™t even add try {} catch {} around this error.

An exception:

 Cannot sign out from the application since the user account is connected. (Exception from HRESULT: 0x8086000E) 

Obviously, since the user who logs in under the Live account cannot log out, my api must determine if the current user is using the current account, so I can prevent the logout () method from being called.

so .... My question is, how do I know which type of account the user has logged into Windows 8 with?

+7
source share
1 answer

Found the answer: http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.authentication.onlineid.onlineidauthenticator.cansignout.aspx#Y0

The following is the property 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; } 
+5
source

All Articles