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

泪湿孤枕 提交于 2019-12-20 15:25:55

问题


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?


回答1:


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;
    }


来源:https://stackoverflow.com/questions/11210531/metro-app-how-to-detect-if-logged-in-with-live-id-or-local-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!