The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP] User authentication with Windows (Microsoft) account RRS feed

  • Question

  • I have a guest mode in my app which should only be unlocked by the user which is currently signed in to Windows. Is there an api call which pops-up an authentication window where the current signed in user has to enter his Windows (Microsoft) credentials and return true or false or some other kind of validation method?

    This is for the mobile part of the app where the owner of the phone sets the app in guest mode and then lends his phone to someone else to use the app, but that person may not be able to switch off the guest mode in the app...

    Monday, December 7, 2015 4:44 PM

Answers

  • I found a good method which even works with the iris scanner on the Lumia 950(XL):

    const string MicrosoftAccountProviderId = "https://login.microsoft.com";
    const string ConsumerAuthority = "consumers";
    const string AccountScopeRequested = "wl.basic";
    const string AccountClientId = "none";
    
    WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);
    WebTokenRequest webTokenRequest = new WebTokenRequest(provider, AccountScopeRequested, AccountClientId, WebTokenRequestPromptType.ForceAuthentication);
    WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);
    if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
    {
    		// Switch guest mode off
    }

    Only thing is that you must be online...

    Saturday, December 12, 2015 12:43 PM

All replies

  • Hi,

    What is your purpose in this case (must login to use app)? If you need to use OneDrive api, you need to use OneDrive SDK, this SDK has Microsoft account authentication mechanism. Check this page for more details about authenticating your app to use OneDrive.

    Hope this helps!

    Monday, December 7, 2015 6:26 PM
  • Hi,

    What is your purpose in this case (must login to use app)? If you need to use OneDrive api, you need to use OneDrive SDK, this SDK has Microsoft account authentication mechanism. Check this page for more details about authenticating your app to use OneDrive.

    Hope this helps!

    My app has a 'edit and managing' mode and a 'normal use' mode. The app automatically signs the user in with single sign in when the app starts and then all modes are accessible. When the owner of the phone lends the phone to someone else to use the app (a sort of outdoor game), that person may not access the edit and managing mode. The owner of the phone can go to the app's settings and switch that mode off, but now everyone can switch it back on. To prevent switching back by others, I want to show a Microsoft (Windows) account sign in form so that only the owner of the phone can switch back to the 'edit and manage' mode.

    Tuesday, December 8, 2015 4:21 PM
  • Hi DennisBakker71,

    >>” I want to show a Microsoft (Windows) account sign in form so that only the owner of the phone can switch back to the 'edit and manage' mode.”

    In my experience, if you need a “Microsoft (Windows) account sign in form”, you could use windows Live SDK, please refer to this MSDN document for details: Live SDK developer guide

    After the user or owner of this phone sign through this “Microsoft (Windows) account sign in form”, you could get the user information. Then you need to use the “User class” in winRT API, you could obtain the user information in current phone.

    Please refer to this “User class” for details: https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.user.aspx

    Here is a code sample about “User information”: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/UserInfo

    Then you could compare the local account in phone with the Microsoft account by signing in form. If the two accounts were equal, you could “switch that mode off”.

    You could download Live SDk form this link: http://www.microsoft.com/en-us/download/details.aspx?id=40739

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 10, 2015 8:21 AM
  • I found a good method which even works with the iris scanner on the Lumia 950(XL):

    const string MicrosoftAccountProviderId = "https://login.microsoft.com";
    const string ConsumerAuthority = "consumers";
    const string AccountScopeRequested = "wl.basic";
    const string AccountClientId = "none";
    
    WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);
    WebTokenRequest webTokenRequest = new WebTokenRequest(provider, AccountScopeRequested, AccountClientId, WebTokenRequestPromptType.ForceAuthentication);
    WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);
    if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
    {
    		// Switch guest mode off
    }

    Only thing is that you must be online...

    Saturday, December 12, 2015 12:43 PM