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.

There is one subtle difference between the findAll and retrieve methods in the list above. The<br />

retrieve method will provide you with fully populated credentials objects. The findAll methods, on the<br />

other hand, will give you objects in which the password properties are still empty. This avoids<br />

performing password decryption on what is potentially a large number of credentials. To populate that<br />

property for any individual credential, call the PasswordCredential.retievePassword method.<br />

For further demonstrations of the credential locker—the code is very straightfoward—refer to the<br />

Credential locker sample. This shows variations for single user/single resource (Scenario 1), single<br />

user/multiple resources (Scenario 2), multiple users/multiple resources (Scenario 3), and clearing out the<br />

locker entirely (Scenario 4).<br />

The Web Authentication Broker<br />

Although apps can acquire and manage user credentials of their own, supplying users perhaps with the<br />

ability to create app-specific or service-specific accounts (typically through the Settings charm, as<br />

discussed in Chapter 8 and also on Guidelines and checklist for login controls), you might want to<br />

simply leverage an account that the user has already created through another OAuth provider,<br />

especially when you want to use that provider’s resources. You’ve likely experienced this on many<br />

websites already, where you log in through another site like Facebook. Of course, that typically means<br />

navigating away from the original website to the provider’s site—a process that flows well enough in a<br />

web browser but isn’t quite so attractive in the context of an app!<br />

For this purpose, Windows provides the Web Authentication Broker, which essentially does the same<br />

job without leaving the context of the app itself. An app provides the URI of the authenticating page of<br />

the external site (which must use the https:// URI scheme, otherwise you get an invalid parameter<br />

error). The broker then creates a new web host process in its own app container, into which it loads the<br />

indicated web page. The UI for that process is displayed as an overlay dialog on the app, as shown in<br />

Figure 14-3, for which I’m using Scenario 1 of the Web authentication broker sample.<br />

FIGURE 14-3 The Web authentication broker sample using a Facebook login page.<br />

661

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

Saved successfully!

Ooh no, something went wrong!