Documentation ¶
Overview ¶
Package issueapi implements the API handler for taking a code request, assigning an OTP, saving it to the database and returning the result. This is invoked over AJAX from the Web frontend.
Index ¶
- func GenerateAlphanumericCode(length uint) (string, error)
- func GenerateCode(length uint) (string, error)
- func ScrubPhoneNumbers(s string) string
- func ValidateDate(date, minDate, maxDate time.Time, tzOffset int) (*time.Time, error)
- type Controller
- func (c *Controller) BatchIssueWithAPIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
- func (c *Controller) BatchIssueWithUIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
- func (c *Controller) BuildVerificationCode(ctx context.Context, request *api.IssueCodeRequest, realm *database.Realm) (*database.VerificationCode, *IssueResult)
- func (c *Controller) CommitCode(ctx context.Context, vCode *database.VerificationCode, realm *database.Realm, ...) error
- func (c *Controller) HandleBatchIssueAPI() http.Handler
- func (c *Controller) HandleBatchIssueUI() http.Handler
- func (c *Controller) HandleIssueAPI() http.Handler
- func (c *Controller) HandleIssueUI() http.Handler
- func (c *Controller) IssueCode(ctx context.Context, vCode *database.VerificationCode, realm *database.Realm) *IssueResult
- func (c *Controller) IssueMany(ctx context.Context, requests []*api.IssueCodeRequest) []*IssueResult
- func (c *Controller) IssueOne(ctx context.Context, request *api.IssueCodeRequest) *IssueResult
- func (c *Controller) IssueWithAPIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
- func (c *Controller) IssueWithUIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
- func (c *Controller) SendSMS(ctx context.Context, realm *database.Realm, smsProvider sms.Provider, ...)
- type IssueResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAlphanumericCode ¶ added in v0.19.0
GenerateAlphanumericCode will generate an alpha numberic code. It uses the length to estimate how many bytes of randomness will base64 encode to that length string. For example 16 character string requires 12 bytes.
func GenerateCode ¶ added in v0.19.0
GenerateCode creates a new OTP code.
func ScrubPhoneNumbers ¶ added in v0.19.0
ScrubPhoneNumbers checks for phone numbers in known Twilio error strings that contains user phone numbers.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg config.IssueAPIConfig, db *database.Database, limiter limiter.Store, smsSigner keys.KeyManager, h *render.Renderer) *Controller
New creates a new IssueAPI controller.
func (*Controller) BatchIssueWithAPIAuth ¶ added in v0.19.0
func (c *Controller) BatchIssueWithAPIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
func (*Controller) BatchIssueWithUIAuth ¶ added in v0.19.0
func (c *Controller) BatchIssueWithUIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
func (*Controller) BuildVerificationCode ¶ added in v0.19.0
func (c *Controller) BuildVerificationCode(ctx context.Context, request *api.IssueCodeRequest, realm *database.Realm) (*database.VerificationCode, *IssueResult)
BuildVerificationCode populates and validates a code from an issue request.
func (*Controller) CommitCode ¶ added in v0.19.0
func (c *Controller) CommitCode(ctx context.Context, vCode *database.VerificationCode, realm *database.Realm, retryCount uint) error
CommitCode will generate a verification code and save it to the database, based on the paremters provided. It returns the short code, long code, a UUID for accessing the code, and any errors.
func (*Controller) HandleBatchIssueAPI ¶ added in v0.19.0
func (c *Controller) HandleBatchIssueAPI() http.Handler
HandleBatchIssueAPI responds to the /batch-issue API for issuing verification codes
func (*Controller) HandleBatchIssueUI ¶ added in v0.19.0
func (c *Controller) HandleBatchIssueUI() http.Handler
HandleBatchIssueUI responds to the /batch-issue API for issuing verification codes
func (*Controller) HandleIssueAPI ¶ added in v0.19.0
func (c *Controller) HandleIssueAPI() http.Handler
HandleIssueAPI responds to the /issue API for issuing verification codes
func (*Controller) HandleIssueUI ¶ added in v0.19.0
func (c *Controller) HandleIssueUI() http.Handler
HandleIssueUI responds to the /issue API for issuing verification codes
func (*Controller) IssueCode ¶ added in v0.19.0
func (c *Controller) IssueCode(ctx context.Context, vCode *database.VerificationCode, realm *database.Realm) *IssueResult
func (*Controller) IssueMany ¶ added in v0.19.0
func (c *Controller) IssueMany(ctx context.Context, requests []*api.IssueCodeRequest) []*IssueResult
IssueMany handles validating a list of IssueCodeRequest, issuing new codes, and sending SMS messages.
func (*Controller) IssueOne ¶ added in v0.19.0
func (c *Controller) IssueOne(ctx context.Context, request *api.IssueCodeRequest) *IssueResult
IssueOne handles validating a single IssueCodeRequest, issuing a new code, and sending an SMS message.
func (*Controller) IssueWithAPIAuth ¶ added in v0.19.0
func (c *Controller) IssueWithAPIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
func (*Controller) IssueWithUIAuth ¶ added in v0.19.0
func (c *Controller) IssueWithUIAuth(w http.ResponseWriter, r *http.Request) *IssueResult
func (*Controller) SendSMS ¶ added in v0.19.0
func (c *Controller) SendSMS(ctx context.Context, realm *database.Realm, smsProvider sms.Provider, signer crypto.Signer, keyID string, request *api.IssueCodeRequest, result *IssueResult)
SendSMS sends the sms mesage with the given provider and wraps any seen errors into the IssueResult
type IssueResult ¶ added in v0.19.0
type IssueResult struct { VerCode *database.VerificationCode ErrorReturn *api.ErrorReturn HTTPCode int // contains filtered or unexported fields }
IssueResult is the response returned from IssueLogic.IssueOne or IssueMany.
func (*IssueResult) IssueCodeResponse ¶ added in v0.19.0
func (result *IssueResult) IssueCodeResponse() *api.IssueCodeResponse
IssueCodeResponse converts an IssueResult to the external api response.