Make userHandle nullable instead of optional

This commit is contained in:
Joao Peixoto
2019-02-06 20:15:22 -08:00
parent 5493a2aed1
commit dda77e9c2a
2 changed files with 25 additions and 22 deletions
+1 -1
View File
@@ -494,7 +494,7 @@ interface AuthenticatorAttestationResponse extends AuthenticatorResponse {
interface AuthenticatorAssertionResponse extends AuthenticatorResponse {
readonly authenticatorData: ArrayBuffer;
readonly signature: ArrayBuffer;
readonly userHandle?: ArrayBuffer;
readonly userHandle: ArrayBuffer | null;
}
/**
@@ -5,7 +5,7 @@ function passwordBasedSignInDeprecated() {
return;
}
navigator.credentials.get({password: true}).then((credential) => {
navigator.credentials.get({ password: true }).then((credential) => {
if (!credential) {
return;
}
@@ -117,7 +117,7 @@ function federatedSignIn() {
navigator.credentials
.get({
password: true,
federated: {providers: ['https://federation.com']}
federated: { providers: ['https://federation.com'] }
})
.then((credential) => {
if (!credential) return;
@@ -141,7 +141,7 @@ function federatedSignIn() {
const pwCred = credential as PasswordCredential;
fetch(
'https://example.com/loginEndpoint',
{credentials: pwCred, method: 'POST'});
{ credentials: pwCred, method: 'POST' });
}
});
}
@@ -159,7 +159,7 @@ function passwordPostSignInConfirmation() {
const formElem = (e.target as HTMLFormElement);
const c = new PasswordCredential(formElem);
fetch(formElem.action, {method: 'POST', credentials: c}).then(r => {
fetch(formElem.action, { method: 'POST', credentials: c }).then(r => {
if (r.status === 200) {
navigator.credentials!.store(c);
}
@@ -172,7 +172,7 @@ function passwordPostSignInConfirmation() {
function federationPostSignInConfirmation() {
if (navigator.credentials) {
navigator.credentials.store(new FederatedCredential(
{id: 'username', provider: 'https://federation.com'}));
{ id: 'username', provider: 'https://federation.com' }));
}
}
@@ -188,7 +188,7 @@ function existingFormPost(credential: PasswordCredential) {
credential.passwordName = 'p';
fetch(
'https://example.com/loginEndpoint',
{credentials: credential, method: 'POST'});
{ credentials: credential, method: 'POST' });
}
function additionalDataPost(credential: PasswordCredential, token: string) {
@@ -196,14 +196,14 @@ function additionalDataPost(credential: PasswordCredential, token: string) {
credential.additionalData.append('csrf', token);
fetch(
'https://example.com/loginEndpoint',
{credentials: credential, method: 'POST'});
{ credentials: credential, method: 'POST' });
}
function formEncodedPost(credential: PasswordCredential, token: string) {
credential.additionalData = new URLSearchParams();
fetch(
'https://example.com/loginEndpoint',
{credentials: credential, method: 'POST'});
{ credentials: credential, method: 'POST' });
}
// requireUserMediation example: not included in the spec, but included here
@@ -236,7 +236,7 @@ function createPasswordCredential() {
}
navigator.credentials.create({
password: {id: 'username', password: 'password'}
password: { id: 'username', password: 'password' }
}).then((credential) => {
// Credential created!
});
@@ -266,7 +266,7 @@ function createFederatedCredential() {
}
navigator.credentials.create({
federated: {id: 'username', provider: 'provider'}
federated: { id: 'username', provider: 'provider' }
}).then((credential) => {
// Credential created!
});
@@ -293,7 +293,7 @@ function webauthnRegister() {
},
challenge,
pubKeyCredParams: [
{type: 'public-key', alg: -7},
{ type: 'public-key', alg: -7 },
],
excludeCredentials: [
{
@@ -329,16 +329,18 @@ function webauthnAuthenticate() {
const challenge = new Uint8Array(32);
window.crypto.getRandomValues(challenge);
const authPromise = navigator.credentials.get({publicKey: {
challenge,
timeout: 5000,
rpId: document.domain,
allowCredentials: [{
type: "public-key",
id: credentialID,
transports: ['internal', 'ble', 'nfc', 'usb']
}],
}});
const authPromise = navigator.credentials.get({
publicKey: {
challenge,
timeout: 5000,
rpId: document.domain,
allowCredentials: [{
type: "public-key",
id: credentialID,
transports: ['internal', 'ble', 'nfc', 'usb']
}],
}
});
authPromise.then((cred) => {
if (cred === null) {
@@ -362,6 +364,7 @@ function mockAuthenticatorAssertionResponse() {
clientDataJSON: new ArrayBuffer(0),
authenticatorData: new ArrayBuffer(0),
signature: new ArrayBuffer(0),
userHandle: null,
};
sampleResponse.userHandle === undefined;
}