Documentation
¶
Overview ¶
This file taken with some modification from authboss github.com/go-authboss
Index ¶
- func GetInfo(info map[string]interface{}, name string) interface{}
- func GetInfoInts(info map[string]interface{}, name string) []int
- func GetInfoString(info map[string]interface{}, name string) string
- func GetInfoStrings(info map[string]interface{}, name string) []string
- type AuthError
- type AuthStorer
- type Backender
- type CookieStorer
- type Crypter
- type CryptoHashStore
- type EmailSendParams
- type Emailer
- type FakeStorer
- type FakeStorerConfig
- type LoginSession
- type Mailer
- type SendGridSender
- type SessionBackender
- type SmtpSender
- type User
- type UserBackender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetInfoInts ¶
GetInfoInts will return the named info as an array of integers
func GetInfoString ¶
GetInfoString will return the named info as a string
func GetInfoStrings ¶
GetInfoStrings will return the named info as an array of strings
Types ¶
type AuthError ¶
type AuthError struct {
// contains filtered or unexported fields
}
AuthError struct holds detailed auth error info
type AuthStorer ¶
type AuthStorer interface {
GetSession(w http.ResponseWriter, r *http.Request) (*LoginSession, error)
GetBasicAuth(w http.ResponseWriter, r *http.Request) (*LoginSession, error)
OAuthLogin(w http.ResponseWriter, r *http.Request) (string, error)
Login(w http.ResponseWriter, r *http.Request) (*LoginSession, error)
Register(w http.ResponseWriter, r *http.Request, params EmailSendParams, password string) error
RequestPasswordReset(w http.ResponseWriter, r *http.Request, params EmailSendParams) error
Logout(w http.ResponseWriter, r *http.Request) error
CreateProfile(w http.ResponseWriter, r *http.Request) (*LoginSession, error)
VerifyEmail(w http.ResponseWriter, r *http.Request, params EmailSendParams) (string, *User, error)
VerifyPasswordReset(w http.ResponseWriter, r *http.Request, emailVerificationCode string) (string, *User, error)
CreateSecondaryEmail(w http.ResponseWriter, r *http.Request, templateName, emailSubject string) error
SetPrimaryEmail(w http.ResponseWriter, r *http.Request, templateName, emailSubject string) error
UpdatePassword(w http.ResponseWriter, r *http.Request) (*LoginSession, error)
UpdateInfo(userID string, info map[string]interface{}) error
}
AuthStorer interface provides the necessary functionality to get and store authentication information
func NewAuthStore ¶
func NewAuthStore(b Backender, mailer Mailer, customPrefix, cookieDomain string, cookieKey []byte, secureOnly bool) AuthStorer
NewAuthStore is used to create an AuthStorer for most authentication needs
type Backender ¶
type Backender interface {
Clone() Backender
// contains filtered or unexported methods
}
Backender interface contains all the methods needed to read and write users, sessions and logins
func NewBackend ¶
func NewBackend(u UserBackender, s SessionBackender) Backender
NewBackend returns a Backender from a UserBackender, LoginBackender and SessionBackender
func NewBackendMemory ¶
NewBackendMemory creates a memory-backed Backender
type CookieStorer ¶
type CookieStorer interface {
Get(w http.ResponseWriter, r *http.Request, key string, result interface{}) error
Put(w http.ResponseWriter, key string, value interface{}) error
PutWithExpire(w http.ResponseWriter, key string, expireMins int, value interface{}) error
Delete(w http.ResponseWriter, key string)
}
CookieStorer interface provides the necessary methods for handling cookies
type Crypter ¶
type Crypter interface {
HashEquals(token, tokenHash string) error
Hash(token string) (string, error)
}
Crypter interface is used to store the password hash and to compare two password hashes together for equality
type CryptoHashStore ¶
type CryptoHashStore struct {
Crypter
}
CryptoHashStore encrypts using an iterated hash with configurable number of iterations
func (*CryptoHashStore) Hash ¶
func (c *CryptoHashStore) Hash(token string) (string, error)
Hash returns a hashed string that has been hashed 50000 times
func (*CryptoHashStore) HashEquals ¶
func (c *CryptoHashStore) HashEquals(token, tokenHash string) error
HashEquals does a constant-time compare to determine if a token is equal to the provided hash
type EmailSendParams ¶
type EmailSendParams struct {
VerificationCode string
Email string
BaseURL string
Info map[string]interface{}
TemplateSuccess string
SubjectSuccess string
TemplateFailure string
SubjectFailure string
}
EmailSendParams contains information necessary to send an email to the user
type Emailer ¶
Emailer struct contains parsed glob of email templates a Sender interface to send emails
func (*Emailer) SendMessage ¶
SendMessage prepares an email with the provided template and passes it to Send for mailing
type FakeStorer ¶
type FakeStorer interface {
AuthStorer
MethodsCalled() []string
}
FakeStorer is a fake AuthStorer for testing and includes MethodsCalled to track what was called
func NewFakeStorer ¶
func NewFakeStorer(config FakeStorerConfig) FakeStorer
NewFakeStorer returns a fake AuthStorer that can be used for testing
type FakeStorerConfig ¶
type FakeStorerConfig struct {
GetSessionVal *LoginSession
GetSessionErr error
GetBasicAuthVal *LoginSession
GetBasicAuthErr error
OAuthLoginVal string
OAuthLoginErr error
LoginVal *LoginSession
LoginErr error
RegisterErr error
RequestPasswordResetErr error
LogoutErr error
CreateProfileVal *LoginSession
CreateProfileErr error
VerifyEmailVal string
VerifyEmailVal2 *User
VerifyEmailErr error
VerifyPasswordResetVal string
VerifyPasswordResetVal2 *User
VerifyPasswordResetErr error
CreateSecondaryEmailErr error
SetPrimaryEmailErr error
UpdatePasswordVal *LoginSession
UpdatePasswordErr error
UpdateInfoErr error
}
FakeStorerConfig stores the config for a Fake AuthStorer
type LoginSession ¶
type LoginSession struct {
UserID string `bson:"userID" json:"userID"`
Email string `bson:"email" json:"email"`
Info map[string]interface{} `bson:"info" json:"info"`
SessionHash string `bson:"_id" json:"sessionHash"`
CSRFToken string `bson:"csrfToken" json:"csrfToken"`
RenewTimeUTC time.Time `bson:"renewTimeUTC" json:"renewTimeUTC"`
ExpireTimeUTC time.Time `bson:"expireTimeUTC" json:"expireTimeUTC"`
}
LoginSession is the struct which holds session information
func (*LoginSession) GetInfo ¶
func (l *LoginSession) GetInfo(name string) interface{}
GetInfo will return the named info as an interface{}
func (*LoginSession) GetInfoInts ¶
func (l *LoginSession) GetInfoInts(name string) []int
GetInfoInts will return the named info as an array of integers
func (*LoginSession) GetInfoString ¶
func (l *LoginSession) GetInfoString(name string) string
GetInfoString will return the named info as a string
func (*LoginSession) GetInfoStrings ¶
func (l *LoginSession) GetInfoStrings(name string) []string
GetInfoStrings will return the named info as an array of strings
type Mailer ¶
type Mailer interface {
SendMessage(to, templateName, emailSubject string, data interface{}) error
}
Mailer interface includes method needed to send communication to users on account updates
type SendGridSender ¶
func (*SendGridSender) Send ¶
func (s *SendGridSender) Send(to, subject, body string) error
Send mails the provided email body to recipient at "to" with subject "subject"
type SessionBackender ¶
type SessionBackender interface {
// contains filtered or unexported methods
}
SessionBackender interface holds methods for session management
func NewBackendRedisSession ¶
func NewBackendRedisSession(server string, port int, password string, maxIdle, maxConnections int, keyPrefix string) SessionBackender
NewBackendRedisSession returns a SessionBackender for Redis
type SmtpSender ¶
type SmtpSender struct {
SMTPServer string
SMTPPort int
SMTPFromEmail string
SMTPPassword string
EmailFromDisplayName string
}
func (*SmtpSender) Send ¶
func (s *SmtpSender) Send(to, subject, body string) error
Send mails the provided email body to recipient at "to" with subject "subject"
type User ¶
type User struct {
UserID string `json:"userID"`
Email string `json:"email"`
IsEmailVerified bool `json:"isEmailVerified"`
Info map[string]interface{} `json:"info"`
}
User is the struct which holds user information
func (*User) GetInfoInts ¶
GetInfoInts will return the named info as an array of integers
func (*User) GetInfoString ¶
GetInfoString will return the named info as a string
func (*User) GetInfoStrings ¶
GetInfoStrings will return the named info as an array of strings
type UserBackender ¶
type UserBackender interface {
// contains filtered or unexported methods
}
UserBackender interface holds methods for user management