Cypress: WebAuthn.addCredential causes exception
Our mobile app uses passkey to authorize users. I am testing the API for our mobile app. We have a SignUpSignIn command that returns "challenge”, "pubKeyCredParams”, "excludeCredentials”, ”rp" and "user”. Now I need to get authenticator information from my browser i.e. "authenticatorData”,“signature”, "clientDataJSON”. I have found this code https://github.com/cypress-io/cypress/issues/6991#issuecomment-1267934998 and tried it. I successfully received _AUTHENTICATOR_ID but I’m stuck about the next step. I tried the command WebAuthn.addCredential but I just got “(uncaught exception)Error: An error occurred trying to create the credential”. I do not understand what I did wrong and if it was a correct step.
This code leads to an exception it is highly likely that the reason is in 'privateKey':
let elliptic = require('elliptic');
let ec = new elliptic.ec('secp256k1');
let keyPair = ec.genKeyPair(); // Generate random keys
let privKey = keyPair.getPrivate("hex");
cy.log("privKey "+privKey);
//privKey 0c2a815f5e67ff7c650c475624e71486ad7dee4294ee7301be2a221919b5d5f8
cy.log("_AUTHENTICATOR_ID "+_AUTHENTICATOR_ID);
Cypress.automation("remote:debugger:protocol", {
command: "WebAuthn.addCredential",
params: {
authenticatorId: _AUTHENTICATOR_ID,
credential: {
credentialId: Buffer.from("1", 'utf8').toString('base64'),
isResidentCredential: false,
setAutomaticPresenceSimulation: true,
rpId: my_rpID,
signCount: 1,
privateKey: privKey.toString('base64'),
}
}
}).then(() => {});
Comments
Post a Comment