Expand description
Phone / SMS magic-code sign-in.
Mirror of the email magic-code flow but with phone numbers as the identity. Same code shape (6-digit numeric), same expiry (10 min), same single-use semantics. Pluggable SMS transport lets apps use Twilio / MessageBird / a webhook.
Phone numbers are E.164-normalized (+15551234567) before any
storage / lookup so case + whitespace + formatting differences
collapse to one identity.
Workflow:
- POST /api/auth/phone/send-code { phone }
→ SMS arrives with
Your sign-in code is 123456. - POST /api/auth/phone/verify { phone, code } → returns the session token, same shape as magic-email.
Apps that need full E.164 validation (libphonenumber-style)
should plug a custom validator before calling Phone::normalize.
Structs§
- InMemory
Phone Code Backend - Null
SmsTransport - No-op transport for tests + the in-memory dev runtime.
- Phone
Code - Stored pending code. Same shape as MagicCode but keyed on phone.
- Phone
Code Store - Twilio
SmsTransport - Twilio REST API transport. Reads PYLON_TWILIO_ACCOUNT_SID +
PYLON_TWILIO_AUTH_TOKEN + PYLON_TWILIO_FROM at construction.
fromMUST be a verified Twilio number / messaging service id.
Enums§
Traits§
- Phone
Code Backend - SmsSender
- SMS sender. Apps register a Twilio/MessageBird transport at
startup; tests use
NullSmsTransport.
Functions§
- normalize
- Normalize a user-supplied phone number to E.164. Strips spaces,
dashes, parens, dots. Leading
+required. ASCII digits only. Returns None for malformed input.