Documentation ¶
Index ¶
- Constants
- Variables
- func AccountIDFromContext(r *http.Request) string
- type API
- func (a *API) ConfirmRecovery(ctx context.Context, token, password string) error
- func (a *API) ConfirmSignupEmail(ctx context.Context, token string) error
- func (a *API) CurrentAccount(r *http.Request) (*Account, error)
- func (a *API) GetAccount(ctx context.Context, userID string) (*Account, error)
- func (a *API) IsAuthenticated(next http.Handler) http.Handler
- func (a *API) Login(w http.ResponseWriter, r *http.Request, email, password string) error
- func (a *API) LoginProviderCallback(w http.ResponseWriter, r *http.Request, attributes map[string]interface{}) error
- func (a *API) LoginWithPasswordlessToken(w http.ResponseWriter, r *http.Request, loginToken string) error
- func (a *API) LoginWithProvider(w http.ResponseWriter, r *http.Request) error
- func (a *API) Recovery(ctx context.Context, email string) error
- func (a *API) SendPasswordlessToken(ctx context.Context, email string) error
- func (a *API) Signup(ctx context.Context, email, password string, attributes map[string]interface{}) error
- type Account
- func (a *Account) Attributes() *Attributes
- func (a *Account) ChangeEmail(ctx context.Context, newEmail string) error
- func (a *Account) ConfirmEmailChange(ctx context.Context, token string) error
- func (a *Account) Delete(ctx context.Context) error
- func (a *Account) Email() string
- func (a *Account) ID() uuid.UUID
- func (a *Account) Logout(w http.ResponseWriter, r *http.Request) error
- type Attributes
- func (a *Attributes) Del(ctx context.Context, key string) error
- func (a *Attributes) DelBytes(ctx context.Context) error
- func (a *Attributes) DelMany(ctx context.Context, keys []string) error
- func (a *Attributes) Get(key string) (interface{}, error)
- func (a *Attributes) GetBytes() []byte
- func (a *Attributes) Map() M
- func (a *Attributes) Session() *SessionAttributes
- func (a *Attributes) Set(ctx context.Context, key string, val interface{}) error
- func (a *Attributes) SetBytes(ctx context.Context, attr []byte) error
- func (a *Attributes) SetMany(ctx context.Context, attrs map[string]interface{}) error
- type Config
- type M
- type MailType
- type SendMailFunc
- type SessionAttributes
- type SessionsStore
Constants ¶
const (
// AccountIDKey IsAuthenticated stores the account id in request context using this key. Used in AccountIDFromContext
AccountIDKey = "key_account_id"
)
Variables ¶
var ( ErrInvalidPassword = errors.New("password is invalid") ErrWrongPassword = errors.New("password is wrong") ErrInvalidEmail = errors.New("email is invalid") ErrUserNotFound = errors.New("user not found") ErrUserNotLoggedIn = errors.New("user is not logged in") ErrEmailNotConfirmed = errors.New("email has not been confirmed") ErrLoginSessionNotFound = errors.New("a valid login session wasn't found") ErrInternal = errors.New("internal server error") ErrUserExists = errors.New("email is already linked to a user") ErrSendingEmail = errors.New("problem sending the email") ErrInvalidToken = errors.New("token is invalid") ErrUpdatingUser = errors.New("failed updating user") ErrAttributeNotFound = errors.New("attribute not found") )
Functions ¶
func AccountIDFromContext ¶
AccountIDFromContext retrieves the account id stored by IsAuthenticated Middleware
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func (*API) ConfirmRecovery ¶
func (*API) ConfirmSignupEmail ¶
ConfirmSignupEmail confirms the email used in signup
func (*API) CurrentAccount ¶
CurrentAccount retrieves the current logged in current
func (*API) GetAccount ¶ added in v0.0.3
GetAccount retrieves an account by user ID
func (*API) IsAuthenticated ¶
IsAuthenticated is an authentication middleware It assumes form content type. For API authentication, please use CurrentAccount to implement your own mw.
func (*API) LoginProviderCallback ¶
func (a *API) LoginProviderCallback(w http.ResponseWriter, r *http.Request, attributes map[string]interface{}) error
LoginProviderCallback handles the callback from a provider. It authenticates an account using a third-party provider(https://github.com/markbates/goth). A new account is created if not present.
func (*API) LoginWithPasswordlessToken ¶
func (a *API) LoginWithPasswordlessToken(w http.ResponseWriter, r *http.Request, loginToken string) error
LoginWithPasswordlessToken authenticates the token sent to email previously with SendPasswordlessLoginLink and logs in the account
func (*API) LoginWithProvider ¶
LoginWithProvider attempts to log in an existing account. If not successful, redirects to the provider signup flow for authentication. The callback from the provider redirect is to be handled by `LoginProviderCallback`
func (*API) SendPasswordlessToken ¶
SendPasswordlessToken sends a passwordless login token to a previously signed up email
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
func (*Account) Attributes ¶
func (a *Account) Attributes() *Attributes
func (*Account) ChangeEmail ¶
func (*Account) ConfirmEmailChange ¶
type Attributes ¶
type Attributes struct {
// contains filtered or unexported fields
}
func (*Attributes) Del ¶
func (a *Attributes) Del(ctx context.Context, key string) error
Del deletes an attribute from the database for the account
func (*Attributes) DelBytes ¶
func (a *Attributes) DelBytes(ctx context.Context) error
DelBytes delete byte data from the database for the account
func (*Attributes) DelMany ¶
func (a *Attributes) DelMany(ctx context.Context, keys []string) error
DelMany deletes many attributes from the database for the account
func (*Attributes) Get ¶
func (a *Attributes) Get(key string) (interface{}, error)
Get gets an attribute from the database for the account
func (*Attributes) GetBytes ¶
func (a *Attributes) GetBytes() []byte
GetBytes gets byte data from the database for the account
func (*Attributes) Map ¶
func (a *Attributes) Map() M
Map gets all attributes from the database for the account
func (*Attributes) Session ¶
func (a *Attributes) Session() *SessionAttributes
func (*Attributes) Set ¶
func (a *Attributes) Set(ctx context.Context, key string, val interface{}) error
Set stores an attribute in the database for the account
type SendMailFunc ¶
type SessionAttributes ¶
type SessionAttributes struct {
// contains filtered or unexported fields
}
func (*SessionAttributes) Del ¶
func (a *SessionAttributes) Del(w http.ResponseWriter, key string) error
Del deletes an attribute from the temporary session store for the account
func (*SessionAttributes) Get ¶
func (a *SessionAttributes) Get(key string) (interface{}, error)
Get gets an attribute from the temporary session store for the account
func (*SessionAttributes) Map ¶
func (a *SessionAttributes) Map() (M, error)
Get gets an attribute from the temporary session store for the account
func (*SessionAttributes) Set ¶
func (a *SessionAttributes) Set(w http.ResponseWriter, key string, val interface{}) error
Set sets an attribute in the temporary session store for the account