Genesys Source

Microsoft Account Logon for Windows Universal (8, 8.1, 10) Apps

Microsoft Account Logon for Windows Universal (8, 8.1, 10) Apps

Introduction

I spent way too much time figuring out something so simple: How do I auto-logon my Windows 8/Windows Phone 8 app?

Call it what you want, single sign-on (SSO), automatic logon, unified logon...the point is the same. A well-written native app doesn't bother the user to logon or register unless necessary. Extra hassles for the user, extra dev time, extra code to maintain. Why not let the device automatically log on the user?

The (confusing) Journey

So I started researching for my Windows 8 app (now with Windows Universal, the same app will run on Windows Phone 8 also).

My career is in the mid-sized company world, which tends to roll-your-own authentication/registration. So I had to catch up with all the new cool SSO services out there. Wanting to go Microsoft, I found that there were plenty of services: Windows Live Account Services, Azure ACS, Azure AD, Microsoft Account, etc. In short, Azure AD is the newest service that supports cross-platform devices for most current Auth providers (Microsoft, Facebook, Google, LinkedIn, etc.)

Azure AD sounded pretty good, but being a solo cowboy startup, I didnt have much time for research. So I started researching Azure AD, and it seemed simple! But after fumbling with getting a sample app working with my Azure account, I decided to switch to the Windows 8-only method...Microsoft Account logon. Besides, Azure would require a SSO web service so that all of my web sites and native apps would work. I didn't want to write a SSO provider just yet, I want to get my app off the ground quickly.

Too much research time spent already, time to switch gears to Microsoft Account...I'll port to Azure AD later.

I found a PERFECT sample here. Download the app, run the app, watch it auto-logon. Well the sample app stopped the auto-logon to have a Sign In button, but you get the picture.

Copied the code to my brand new Windows Universal template, run the app, and an error: {"The application requesting authentication tokens is either disabled or incorrectly configured. (Exception from HRESULT: 0x80860003)"}

The problem was that the app needed to be known to my Microsoft Developer account. But nowhere in any documentation did I see the critical step that accomplished this. Minutes turned into hours, and I just so happened to stumble on the solution... one click of a menu in Visual Studio 2013. Thats all it took to get it working, jeez.

Just Tell Me the Answer!

Ok, so here is the answer.

  • Download the Microsoft Account Sample here
  • Create your app, and copy all code from Scenario01_DelegationToken.xaml.cs. Just comment out all of the errors, they are all UI controls that aren't needed. Remember to make SignInButton_Click public so you can call it directly.
  • At this point, running your app will fail...need to link it to your developer account.
  • Create a Microsoft Developer account here.
  • Go to your Dashboard here and register your app, Step 1 (Name your App) is all that is required.
  • Now the trick: Right-click your Project in Visual Studio 2013, click Store, and click Associate App with the Store.

Blog-AssociateStore

Guess what? It works. Hope this helps somebody!

Leave your comment
Comments
12/24/2016 9:42 AM
Thanks for your thugthos. It's helped me a lot.