Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone verification on entryway #2055

Merged
merged 25 commits into from
Jan 29, 2024
Merged

Phone verification on entryway #2055

merged 25 commits into from
Jan 29, 2024

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Jan 17, 2024

Adds optional phone verification to the entryway using Twilio's verify API

Building off of the schemas in #2056

@dholms dholms changed the base branch from main to multi-pds-auth January 17, 2024 00:14
@dholms dholms marked this pull request as ready for review January 17, 2024 01:46
if (!input.body.verificationPhone) {
throw new InvalidRequestError(
'Phone number verification is required on this server and none was provided.',
'InvalidPhoneVerification',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider adding this error type to the lexicon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i played kinda fast and loose cuz i know this is gonna be temporary. but yup probably a good idea 👍

.insertInto('phone_verification')
.values({
did,
phoneNumber: input.body.verificationPhone,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if twilio spits out a normalized version of phone numbers—but if they do it might be worth tracking it here. It's a real pain to validate and normalize phone numbers, and we'll end-up storing a wide variety of different formats in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup looks like it does 👍

Comment on lines +10 to +12
.createIndex('phone_verification_number_idx')
.on('phone_verification')
.column('phoneNumber')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to ensure the numbers stored here are normalized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right that's a good point 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay actually took a different track on this & decided to just enforce the format that twilio wants (https://www.twilio.com/docs/glossary/what-e164#regex-matching-for-e164)

the api forces it pretty close, but it still allows some slight variations (like dashes between numbers)

Comment on lines +29 to +43
ctx.twilio.sendCode = async (number: string) => {
if (!verificationCodes[number]) {
const code = crypto.randomStr(4, 'base10').slice(0, 6)
verificationCodes[number] = code
}
const code = verificationCodes[number]
sentCodes.push({ code, number })
}
ctx.twilio.verifyCode = async (number: string, code: string) => {
if (verificationCodes[number] === code) {
delete verificationCodes[number]
return true
}
return false
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's some comparable mocking code in dev-env—could we make use of that here?

Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin good! Main thing to maybe give a think is storing/handling normalized phone numbers.

@dholms dholms merged commit c7d95e9 into multi-pds-auth Jan 29, 2024
10 checks passed
@dholms dholms deleted the entryway-twilio branch January 29, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants