Version: v1.17.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 33 Imported by: 0



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.



This section is empty.


This section is empty.


func GenerateAlphanumericCode added in v0.19.0

func GenerateAlphanumericCode(length uint) (string, error)

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

func GenerateCode(length uint) (string, error)

GenerateCode creates a new OTP code.

func ScrubPhoneNumbers added in v0.19.0

func ScrubPhoneNumbers(s string) string

ScrubPhoneNumbers checks for phone numbers in known Twilio error strings that contains user phone numbers.

func ValidateDate added in v0.19.0

func ValidateDate(date, minDate, maxDate time.Time, tzOffset int) (*time.Time, error)

ValidateDate validates the date given -- returning the time or an error.


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) BuildSMS added in v0.29.0

func (c *Controller) BuildSMS(ctx context.Context, realm *database.Realm, signer crypto.Signer, keyID string, request *api.IssueCodeRequest, vercode *database.VerificationCode) (string, error)

BuildSMS builds and signs (if configured) the SMS message. It returns the complete and compiled message.

func (*Controller) BuildVerificationCode added in v0.19.0

func (c *Controller) BuildVerificationCode(ctx context.Context, internalRequest *IssueRequestInternal, 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) HandleUserReport added in v0.25.0

func (c *Controller) HandleUserReport() http.Handler

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 []*IssueRequestInternal) []*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 *IssueRequestInternal) *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 IssueRequestInternal added in v0.25.0

type IssueRequestInternal struct {
	IssueRequest  *api.IssueCodeRequest
	UserRequested bool
	// These files are for user initiated report
	Nonce []byte

IssueRequestInternal is used to join the base issue request with the optional nonce. If the nonce is provided and the the report type is self_report (user initiated code), then extra safeguards are applied.

type IssueResult added in v0.19.0

type IssueResult struct {
	VerCode      *database.VerificationCode
	GeneratedSMS string
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL