twilio / twilio-node

Node.js helper library
MIT License
1.37k stars 495 forks source link

Missing required parameter error when updating factor in `verify.v2` #1019

Closed yifanplanet closed 2 months ago

yifanplanet commented 2 months ago

Issue Summary

I received error RestException [Error]: Missing required parameter FriendlyName in the post body when using wilio-node SDK and verifying factor using update method following the doc: Verify that the user has successfully registered

Steps to Reproduce

  1. Create the factor
  2. Try to verify the factor by calling update with the totp code

Code Snippet

const client = twilio(accountSid, authToken);
const factor = await client.verify.v2
  .services(twilioServiceId)
  .entities(userPublicId)
  .factors(factorSid)
  .update({
    authPayload: totpCode,
  });

Exception/Log

RestException [Error]: Missing required parameter FriendlyName in the post body

Technical details:

tiwarishubham635 commented 2 months ago

It works correctly for me though. Can you re-check once?

tiwarishubham635 commented 2 months ago

Just to be on the same page, I followed these steps:

  1. I created a service from here and stored the Service SID in variable serviceSid
  2. Next, I created an entity using this code snippet:
    const identity = 'user-identity';
    client.verify.v2.services(serviceSid)
             .entities
             .create({
                 identity: identity
             })
             .then(entity => console.log(entity));
  3. Then I created a new TOTP factor using this:
    client.verify.v2.services(serviceSid)
    .entities(identity)
    .newFactors
    .create({
        friendlyName: `Name`,
        factorType: 'totp'
    })
    .then(new_factor => console.log(new_factor));
  4. I saved the value of new_factor.sid in factorSid and used new_factor.binding.uri to create QR code using this.
  5. Scanned this QR code and saved the key in my phone.
  6. Then used the following code snippet for verification:
    const totpCode = '123456'
    client.verify.v2.services(serviceSid)
    .entities(identity)
    .factors(factorSid)
    .update({authPayload: totpCode})
    .then(factor => console.log(factor));
  7. The status shows verified for me

Let me know if I am doing something different but it works fine for me. Thanks!

yifanplanet commented 2 months ago

Sorry that was a mistake on my side. Thanks so much for detailed steps for the implementation. One question: Is the entity create step necessary for the factor verification?

tiwarishubham635 commented 2 months ago

Nope, it is not necessary. I just created it to see if that os creating a problem for you.