Documentation
¶
Overview ¶
Package identifier normalizes and validates the identifiers accounts sign in with: email addresses, phone numbers and device identifiers. Every module stores and looks up identifiers in the canonical form this package produces, so one address cannot become two accounts by being spelled two ways.
Index ¶
- Constants
- Variables
- func CanonicalEmail(email string) string
- func CanonicalIdentifier(authType, identifier string) string
- func CanonicalMobile(number string) (string, error)
- func Check(areaCode, telephone string) bool
- func CheckPhone(telephone string) bool
- func EmailMailboxKey(email string) string
- func FormatToE164(area, phone string) (string, error)
- func FormatToInternational(telephone string) string
- func GetCountryCode(telephone string) string
- func MaskEmail(email string) string
- func MaskPhoneNumber(phone string) string
- func NormalizeIdentifier(authType, identifier string) (string, error)
- func ValidateEmail(email, domainList string, enforceDomain bool) (string, error)
Constants ¶
const ( Email = "email" Mobile = "mobile" Device = "device" )
Variables ¶
var ( ErrInvalidEmail = errors.New("invalid email address") ErrEmailDomainDenied = errors.New("email domain is not allowed") ErrEmailDomainListNil = errors.New("email domain allowlist is empty") )
var ErrInvalidMobile = errors.New("invalid phone number")
ErrInvalidMobile reports a phone number that does not parse.
Functions ¶
func CanonicalEmail ¶
func CanonicalIdentifier ¶
CanonicalIdentifier is NormalizeIdentifier for lookups: an identifier that cannot be normalized is returned as given and simply matches nothing.
func CanonicalMobile ¶ added in v1.21.0
CanonicalMobile returns the E.164 form of a phone number written with its country calling code, with or without the leading "+" and with the separators people type: "86-13800138000" (the form the admin panel used to store), "+86 138 0013 8000" and "8613800138000" all give "+8613800138000". The number is parsed, not validated: an unassigned number still has one E.164 form, the one sign-in looks it up in.
func CheckPhone ¶
func EmailMailboxKey ¶ added in v1.21.0
EmailMailboxKey maps an email address to the mailbox that receives it: the subaddress after "+" is dropped, and Gmail ignores dots in the local part and treats googlemail.com as gmail.com. Addresses sharing a key reach one inbox, so one person could register them all. The key only detects such aliases; it is never stored or used to sign in.
func FormatToE164 ¶
FormatToE164 returns the E.164 form of a phone number given as its country calling code and national number, the form every sign-in, verification code and binding stores and looks the number up in.
func FormatToInternational ¶
func GetCountryCode ¶
func MaskEmail ¶
MaskEmail hides the local part of an email address for display, keeping only its first and last characters: alice@example.com becomes a***e@example.com. A local part of one or two characters keeps at most its first, so a short address is not given away whole, and a string that is not an address becomes "***".
func MaskPhoneNumber ¶
MaskPhoneNumber parses a phone number and masks the middle of its national part, keeping the country code, the first three and the last four digits.
func NormalizeIdentifier ¶ added in v1.21.0
NormalizeIdentifier returns the form an identifier of authType is stored and looked up in: an email address lower-cased and trimmed, a phone number in E.164 (see CanonicalMobile). Other identifiers are opaque and returned as given. It fails for an empty email address or a phone number that does not parse.
Types ¶
This section is empty.