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.

The result from pickAsync, as given to your completed handler, is a CredentialPickerResults<br />

object with the following properties—when you enter some credentials in the sample here, you’ll see<br />

these values reflected in the sample’s output:<br />

• credentialuserName A string containing the entered username.<br />

• credentialPassword A string containing the password (typically encrypted depending on the<br />

authentication protocol option).<br />

• credentialDomainName A string containing a domain if entered with the username (as in<br />

\).<br />

• credentialSaved A Boolean indicating whether the credential was saved automatically; this<br />

depends on picker options, as discussed below.<br />

• credentialSavedOption A CredentialSavedOption value indicating the state of the<br />

Remember My Credentals check box: unselected, selected, or hidden. We’ll see how to handle<br />

this shortly as well.<br />

• errorCode Contains zero if there is no error, otherwise an error code.<br />

• credential An IBuffer containing the credential as an opaque byte array. This is what you can<br />

save in your own persistent state if needs be and passed back to the picker at a later time; we’ll<br />

see how shortly.<br />

The three scenarios in the sample demonstrate the different options you can use to invoke the<br />

credential picker. For this there are three separate variants of pickAsync. The first variant accepts a<br />

target name (ignored) and a message string that appears in the place of “Please enter your credentials”<br />

in Figure 14-2:<br />

Windows.Security.Credentials.UI.CredentialPicker.pickAsync(targetName, message)<br />

.done(function (results) {<br />

}<br />

The second variant accepts the same arguments plus a caption string that appears in the place of<br />

“Credential Picker Sample” in Figure 14-2:<br />

Windows.Security.Credentials.UI.CredentialPicker.pickAsync(targetName, message, caption)<br />

.done(function (results) {<br />

}<br />

The third variant accepts a CredentialPickerOptions object that has properties for the same<br />

targetName, message, and caption strings along with the following:<br />

• previousCredential An IBuffer with the opaque credential information as provided by a<br />

previous invocation of the picker (see CredentialPickerResults.credential above).<br />

• alwaysDisplayDialog A Boolean indicating whether the dialog box is displayed. The default<br />

value is false, but this applies only if you also populate previousCredential (with an exception<br />

657

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

Saved successfully!

Ooh no, something went wrong!