github.com/volatiletech/authboss@v2.4.1+incompatible/otp/twofactor/sms2fa/sms_payloads.go (about)

     1  package sms2fa
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/volatiletech/authboss"
     7  )
     8  
     9  // SMSValuer returns a code or a resend-code from the body
    10  type SMSValuer interface {
    11  	authboss.Validator
    12  
    13  	GetCode() string
    14  	GetRecoveryCode() string
    15  }
    16  
    17  // SMSPhoneNumberValuer returns a phone number from the body
    18  type SMSPhoneNumberValuer interface {
    19  	authboss.Validator
    20  
    21  	GetPhoneNumber() string
    22  }
    23  
    24  // MustHaveSMSValues upgrades a validatable set of values
    25  // to one specifically holding the code we're looking for, or a resend.
    26  func MustHaveSMSValues(v authboss.Validator) SMSValuer {
    27  	if u, ok := v.(SMSValuer); ok {
    28  		return u
    29  	}
    30  
    31  	panic(fmt.Sprintf("bodyreader returned a type that could not be upgraded to SMSValuer: %T", v))
    32  }
    33  
    34  // MustHaveSMSPhoneNumberValue upgrades a validatable set of values
    35  // to ones specifically holding a phone number.
    36  func MustHaveSMSPhoneNumberValue(v authboss.Validator) SMSPhoneNumberValuer {
    37  	if u, ok := v.(SMSPhoneNumberValuer); ok {
    38  		return u
    39  	}
    40  
    41  	panic(fmt.Sprintf("bodyreader returned a type that could not be upgraded to SMSValuer: %T", v))
    42  }