verification

package
v1.0.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecode            = errors.New("verification: could not decode token")
	ErrSize              = errors.New("verification: invalid size for token")
	ErrInvalidRecordID   = errors.New("invalid verification token: no record id")
	ErrInvalidExpiration = errors.New("invalid verification token: no expiration timestamp")
	ErrInvalidNonce      = errors.New("invalid verification token: incorrect nonce")
	ErrInvalidSignature  = errors.New("invalid verification token: incorrect hmac signature")
	ErrUnexpectedType    = errors.New("verification: could not scan non-bytes type")
)

Functions

This section is empty.

Types

type SignedToken

type SignedToken struct {
	Token
	// contains filtered or unexported fields
}

A signed token contains a signature that can be stored in the local database in order to verify an incoming verification token from a client.

func (*SignedToken) Equal

func (t *SignedToken) Equal(o *SignedToken) bool

func (*SignedToken) MarshalBinary

func (t *SignedToken) MarshalBinary() (out []byte, err error)

func (*SignedToken) Scan

func (t *SignedToken) Scan(value interface{}) error

Scan the signed token from a database query.

func (*SignedToken) Signature

func (t *SignedToken) Signature() []byte

Retrieve the signature from the signed token.

func (*SignedToken) UnmarshalBinary

func (t *SignedToken) UnmarshalBinary(data []byte) (err error)

func (*SignedToken) Validate

func (t *SignedToken) Validate() (err error)

func (*SignedToken) Value

func (t *SignedToken) Value() (_ driver.Value, err error)

Produce a database value from the signed token for inserts/updates to database.

func (*SignedToken) Verify

func (t *SignedToken) Verify(token VerificationToken) (secure bool, err error)

Verify that a signed token belongs with the associated verification token.

type Token

type Token struct {
	RecordID   ulid.ULID // ID of the record in the database for verification
	Expiration time.Time // Expiration date of the token (not after)
	// contains filtered or unexported fields
}

A Token is a data representation of the information needed to create a secure record verification token for use in cases such as sending Sunrise email or password reset links. Tokens can be used to generate SignedTokens and SignedTokens can be used to send a secure verification token and to verify that tokens belong to the specified user.

func NewToken

func NewToken(recordID ulid.ULID, expiration time.Time) *Token

Create a new token with the specified ID and expiration timestamp. If the timestamp is zero valued, then a timestamp in the future will be generated with the default expiration deadline.

func (*Token) Equal

func (t *Token) Equal(o *Token) bool

func (*Token) IsExpired

func (t *Token) IsExpired() bool

func (*Token) MarshalBinary

func (t *Token) MarshalBinary() ([]byte, error)

func (*Token) Sign

func (t *Token) Sign() (token VerificationToken, signature *SignedToken, err error)

Sign a token creating a verification token that should be sent as a string to the counterparty and a signed token that should be stored in the database.

func (*Token) UnmarshalBinary

func (t *Token) UnmarshalBinary(data []byte) error

func (*Token) Validate

func (t *Token) Validate() (err error)

type VerificationToken

type VerificationToken []byte

A verification token is sent to the client and contains the information needed to lookup a signed token in the database and to verify that the message is authentic.

func ParseVerification

func ParseVerification(tks string) (_ VerificationToken, err error)

func (VerificationToken) RecordID

func (v VerificationToken) RecordID() ulid.ULID

func (VerificationToken) Secret

func (v VerificationToken) Secret() []byte

func (VerificationToken) String

func (v VerificationToken) String() string

Jump to

Keyboard shortcuts

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