Documentation
¶
Index ¶
- Variables
- func NormalizeEmail(email string) string
- type AuthMagicLinkController
- func (mlc *AuthMagicLinkController) GenerateChallenge(email string) (challenge string, err error)
- func (mlc *AuthMagicLinkController) GenerateSessionId(user *AuthUserRecord) (sessionId string, err error)
- func (mlc *AuthMagicLinkController) GetUserByEmail(email string) (*AuthUserRecord, error)
- func (mlc *AuthMagicLinkController) GetUserCount() (int, error)
- func (mlc *AuthMagicLinkController) StoreUser(user *AuthUserRecord) error
- func (mlc *AuthMagicLinkController) UserExistsByEmail(email string) bool
- func (mlc *AuthMagicLinkController) UsersExist() (bool, error)
- func (mlc *AuthMagicLinkController) VerifyChallenge(challenge string) (user *AuthUserRecord, err error)
- func (mlc *AuthMagicLinkController) VerifySessionId(sessionId string) (user *AuthUserRecord, err error)
- type AuthUserRecord
- type RecordWithID
- type RecordWithKeyName
- type UserAuthDatabase
Constants ¶
This section is empty.
Variables ¶
var ErrBrokenChallenge = errors.New("broken challenge")
var ErrBrokenSessionId = errors.New("broken session id")
var ErrExpiredChallenge = errors.New("expired challenge")
var ErrExpiredSessionId = errors.New("expired session id")
var ErrInvalidChallenge = errors.New("invalid challenge")
var ErrInvalidSessionId = errors.New("invalid session id")
var ErrSecretKeyTooShort = errors.New("secret Key too short (min 16 bytes)")
var ErrUserAlreadyExists = errors.New("user already exists")
var ErrUserDisabled = errors.New("user disabled")
var ErrUserNotFound = errors.New("user not found")
Functions ¶
func NormalizeEmail ¶
Types ¶
type AuthMagicLinkController ¶
type AuthMagicLinkController struct {
// contains filtered or unexported fields
}
All functionalities needed to implement the Magic Link login system is available through the AuthMagicLinkController.
func NewAuthMagicLinkController ¶
func NewAuthMagicLinkController(secretKey []byte, challengeExpDuration time.Duration, sessionExpDuration time.Duration, db UserAuthDatabase) (mlc *AuthMagicLinkController, err error)
NewAuthMagicLinkController configures and creates a new instance of the AuthMagicLinkController. The secretKey needs to be kept safe. To provide your own storage mechanism for the magic link data, implement the UserAuthDatabase interface. There are file system and SQL database implementations provided.
func (*AuthMagicLinkController) GenerateChallenge ¶
func (mlc *AuthMagicLinkController) GenerateChallenge(email string) (challenge string, err error)
GenerateChallenge creates a challenge string to be used for constructing the magic link. This challenge string needs to be verified by VerifyChallenge()
func (*AuthMagicLinkController) GenerateSessionId ¶
func (mlc *AuthMagicLinkController) GenerateSessionId(user *AuthUserRecord) (sessionId string, err error)
GenerateSessionId generates a session id suitable for using as a cookie in a web app.
func (*AuthMagicLinkController) GetUserByEmail ¶
func (mlc *AuthMagicLinkController) GetUserByEmail(email string) (*AuthUserRecord, error)
func (*AuthMagicLinkController) GetUserCount ¶ added in v0.9.3
func (mlc *AuthMagicLinkController) GetUserCount() (int, error)
func (*AuthMagicLinkController) StoreUser ¶
func (mlc *AuthMagicLinkController) StoreUser(user *AuthUserRecord) error
func (*AuthMagicLinkController) UserExistsByEmail ¶
func (mlc *AuthMagicLinkController) UserExistsByEmail(email string) bool
func (*AuthMagicLinkController) UsersExist ¶ added in v0.9.4
func (mlc *AuthMagicLinkController) UsersExist() (bool, error)
func (*AuthMagicLinkController) VerifyChallenge ¶
func (mlc *AuthMagicLinkController) VerifyChallenge(challenge string) (user *AuthUserRecord, err error)
VerifyChallenge verifies the challenge string generated by GenerateChallenge(), and returns the AuthUserRecord corresponding to the user for which the challenge was created (identifying them by their email address).
func (*AuthMagicLinkController) VerifySessionId ¶
func (mlc *AuthMagicLinkController) VerifySessionId(sessionId string) (user *AuthUserRecord, err error)
VerifySessionId verifies the session ID generated by GenerateSessionId() and if it's valid, returns the AuthUserRecord of the associated user.
type AuthUserRecord ¶
type AuthUserRecord struct {
ID uuid.UUID `json:"id"` // Unique identifier
Enabled bool `json:"enabled"`
Email string `json:"email"` // Also must be unique
AccessLevel int `json:"access_level"`
FirstLoginTime time.Time `json:"first_login_time"`
RecentLoginTime time.Time `json:"recent_login_time"`
CustomData map[string]string `json:"custom_data"` // Apps can attach custom data to the user record
}
AuthUser represents user data
func NewAuthUserRecord ¶
func NewAuthUserRecord(email string) (aur *AuthUserRecord, err error)
NewAuthUserRecords constructs a new AuthUserRecord. This function isn't normally directly called by the users of this package.
func (*AuthUserRecord) GetKeyName ¶
func (aur *AuthUserRecord) GetKeyName() string
Returns the Key name suitable for key-value databases.
type RecordWithID ¶
type RecordWithKeyName ¶
type RecordWithKeyName interface {
GetKeyName() string
}
type UserAuthDatabase ¶
type UserAuthDatabase interface {
UserExistsByEmail(email string) bool
StoreUser(user *AuthUserRecord) error
GetUserById(id uuid.UUID) (*AuthUserRecord, error)
GetUserByEmail(email string) (*AuthUserRecord, error)
GetUserCount() (int, error) // Slow
UsersExist() (bool, error) // Fast
}
When a new storage provider is created, it implements this interface. See the provided storage provided in the `storage` package.