Documentation ¶
Overview ¶
Package auth manages users, passwords, tokens and sessions.
Index ¶
- Constants
- Variables
- func CredentialsError(err error) bool
- func ExpireCookie(cookie *http.Cookie) *http.Cookie
- func UpdateCookie(session *Session, cookie *http.Cookie)
- type Auth
- func (a *Auth) AddUser(userid, pass string) error
- func (a *Auth) AssignMedia(email, media string) error
- func (a *Auth) AssignedMedia() []string
- func (a *Auth) AuthorizeCode(value, token string) error
- func (a *Auth) ChangePass(userid, newpass string) error
- func (a *Auth) Check(userid, pass string) (User, error)
- func (a *Auth) CheckAccessToken(signedToken string) error
- func (a *Auth) CheckAccessTokenUser(signedToken string) (User, error)
- func (a *Auth) CheckCodeToken(signedToken string) error
- func (a *Auth) CheckCookie(cookie *http.Cookie) error
- func (a *Auth) CheckFileToken(signedToken string, path string) error
- func (a *Auth) CheckMediaToken(signedToken string) error
- func (a *Auth) CheckMediaTokenUser(signedToken string) (User, error)
- func (a *Auth) Close()
- func (a *Auth) CookieSession(cookie *http.Cookie) *Session
- func (a *Auth) DeleteExpiredCodes() error
- func (a *Auth) DeleteExpiredSessions() error
- func (a *Auth) DeleteSession(session Session)
- func (a *Auth) DeleteSessions(u *User) error
- func (a *Auth) GenerateCode() *Code
- func (a *Auth) LinkedCode(value string) *Code
- func (a *Auth) Login(userid, pass string) (Session, error)
- func (a *Auth) LookupCode(value string) *Code
- func (a *Auth) NewAccessToken(s Session) (string, error)
- func (a *Auth) NewCodeToken(subject string) (string, error)
- func (a *Auth) NewCookie(session *Session) http.Cookie
- func (a *Auth) NewFileToken(path string) (string, error)
- func (a *Auth) NewMediaToken(s Session) (string, error)
- func (a *Auth) Open() (err error)
- func (a *Auth) Refresh(session *Session) error
- func (a *Auth) RefreshCookie(session *Session, cookie *http.Cookie) error
- func (a *Auth) SessionUser(session *Session) (*User, error)
- func (a *Auth) TokenSession(token string) *Session
- func (a *Auth) User(userid string) (User, error)
- func (a *Auth) ValidCode(value string) *Code
- type Code
- type Session
- type User
Constants ¶
const ( CodeChars = "123456789ABCDEFGHILKMNPQRSTUVWXYZ" CodeSize = 6 )
const (
CookieName = takeout.AppName
)
Variables ¶
var ( ErrBadDriver = errors.New("driver not supported") ErrUserNotFound = errors.New("user not found") ErrKeyMismatch = errors.New("key mismatch") ErrSessionNotFound = errors.New("session not found") ErrSessionExpired = errors.New("session expired") ErrCodeNotFound = errors.New("code not found") ErrCodeExpired = errors.New("code has expired") ErrCodeAlreadyUsed = errors.New("code already authorized") ErrInvalidTokenSubject = errors.New("invalid subject") ErrInvalidTokenAudience = errors.New("invalid audience") ErrInvalidTokenMethod = errors.New("invalid token method") ErrInvalidTokenIssuer = errors.New("invalid token issuer") ErrInvalidTokenClaims = errors.New("invalid token claims") ErrInvalidAccessTokenSecret = errors.New("invalid access token secret") ErrInvalidMediaTokenSecret = errors.New("invalid media token secret") ErrInvalidCodeTokenSecret = errors.New("invalid code token secret") ErrInvalidFileTokenSecret = errors.New("invalid file token secret") ErrInvalidTokenSecret = errors.New("invalid token secret") ErrTokenExpired = errors.New("token expired") )
Functions ¶
func CredentialsError ¶
func ExpireCookie ¶
ExpireCookie will update cookie fields to ensure it's expired.
func UpdateCookie ¶
UpdateCookie will update the cookie age based on the time left for the session.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
func (*Auth) AssignMedia ¶
func (*Auth) AssignedMedia ¶
func (*Auth) AuthorizeCode ¶
This assumes token is valid
func (*Auth) ChangePass ¶
ChangePass changes the password associated with the provided userid. User Check prior to this if you'd like to verify the current password.
func (*Auth) Check ¶
Check will check if the provided userid and password match a user in the database.
func (*Auth) CheckAccessToken ¶
func (*Auth) CheckAccessTokenUser ¶
func (*Auth) CheckCodeToken ¶
func (*Auth) CheckFileToken ¶ added in v0.14.0
func (*Auth) CheckMediaToken ¶
func (*Auth) CheckMediaTokenUser ¶
func (*Auth) CookieSession ¶
CookieSession will find the session associated with the provided cookie.
func (*Auth) DeleteExpiredCodes ¶
func (*Auth) DeleteExpiredSessions ¶
func (*Auth) DeleteSession ¶
DeleteSession will delete the provided session
func (*Auth) DeleteSessions ¶
func (*Auth) GenerateCode ¶
func (*Auth) LinkedCode ¶
func (*Auth) Login ¶
Login will create a new login session after authenticating the userid and password.
func (*Auth) LookupCode ¶
func (*Auth) NewAccessToken ¶
NewAccessToken creates a new JWT token associated with the provided session.
func (*Auth) NewCodeToken ¶
NewCodeToken creates a new JWT token for code-based authentication
func (*Auth) NewFileToken ¶ added in v0.14.0
NewFileToken creates a new JWT token for file auth
func (*Auth) NewMediaToken ¶
NewMediaToken creates a new JWT token associated with the provided session.
func (*Auth) RefreshCookie ¶
RefreshCookie will renew a session and cookie.
func (*Auth) TokenSession ¶
TokenSession will find the session associated with this provided token.
type Code ¶
type Session ¶
type Session struct { gorm.Model User string `gorm:"unique_index:idx_session_user"` Token string `gorm:"unique_index:idx_session_token"` Expires time.Time }
A Session is an authenticated user login session associated with a token and expiration date.