23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

https://www.facebook.com/dialog/oauth?client_id=&redirect_uri=&<br />

scope-read_stream&display=popup&response_type=token<br />

https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=&<br />

response_type=code&scope=http://picasaweb.google.com/data<br />

where and are replaced with whatever is specific to the app. Twitter and<br />

Flickr, for their parts, use OAuth 1.0a protocol instead, so much more ceremony goes into creating the<br />

lengthy OAuth token to include with the requestUri argument to authenticateAsync. I’ll leave it to the<br />

sample code to show those details.<br />

Tip Web authentication events are visible in the Event Viewer under Application and Services Logs ><br />

Microsoft > Windows > WebAuth > Operational. This can be helpful for debugging because it brings<br />

out information that is otherwise hidden behind the opaque layer of the broker.<br />

Single Sign On<br />

What we’ve seen so far with the credential locker and the web authentication broker works very well to<br />

minimize how often the app needs to pester the user for credentials. Where a single app is concerned, it<br />

would ideally only ask for credentials once until such time as the user explicitly logs out. But what about<br />

multiple apps? Imagine over time that you acquire some dozens, or even hundreds, of apps from the<br />

Windows Store that use external authentication providers. It could mean that you’d have to enter your<br />

Facebook, Twitter, Google, LinkedIn, Tumblr, Yahoo, or Yammer credentials in each app that uses them.<br />

Sure, you might need to do that only once in each individual app, but the compound effect is still<br />

tedious and annoying!<br />

From the user’s point of view, once they’ve authenticated through a given provider in one app, it<br />

makes sense that other apps should benefit from that authentication if possible. Yes, some apps might<br />

need to prompt for additional permissions and some providers may not support the process, but the<br />

ideal is again to minimize the fuss and bother where we can.<br />

The concept of single sign on is exactly this: authenticating the user in one app (or the system in the<br />

case of a Microsoft account) effectively logs the user in to other apps that use the same provider. At the<br />

same time, each app must often acquire its own access keys or tokens, because these should not be<br />

shared between apps. So the real trick is to effectively perform the same kind of authentication we’ve<br />

already seen, only to do it without showing any UI unless it’s really necessary.<br />

This is provided for in the web authentication broker through the variation of authenticateAsync<br />

that takes only the options and requestUri arguments. In this case options is often set to<br />

Web-AuthenticationOptions.silentMode to prevent the broker’s UI from appearing (but this isn’t<br />

required).<br />

To make silentMode work the broker still needs to know when the process is complete. So what<br />

callbackUri does it use for comparison, and how does the provider know that itself? It sounds like a<br />

situation where the broker would just sit there, forever hidden, while the provider patiently waits for<br />

input to a web page that’s equally invisible! What actually happens is that authenticateAsync watches<br />

665

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!