Metro App - How to detect if logged in with Live ID or Local Account
Asked Answered
D

1

7

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?

Dodecagon answered 26/6, 2012 at 15:17 Comment(2)
Why can't you just not log the user out of their account? Allow them to decide. What is the results of loginResult. I don't believe Microsoft will expose this sort of information otherwise it would lead to malware that targets your Windows Live session.Indrawn
When you log into windows 8 with a live account, you cannot 'log out' until you switch to another account or a local account...windows 8 keeps you signed into everything. I agree, they may not expose this, but then the SDK is throwing an un-handleable error...so how do I prevent that?Dodecagon
D
5

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;
    }
Dodecagon answered 27/6, 2012 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.