Documentation ¶
Overview ¶
Package auth implements methods to handler users activities.
Index ¶
- Constants
- Variables
- func Authenticate(ctx context.Context) (context.Context, error)
- func CheckToken(ctx context.Context, r *http.Request, api bool) (context.Context, error)
- func EqualBytes(x, y []byte) bool
- func ExtractTokenKey(ctx context.Context) (string, error)
- func InitUsers(c *conf.Config) error
- type User
- type UserResult
Constants ¶
const ( // Anonymous is a name of anonymous user. Anonymous = "anonymous" // Administrator is a name of administrator user. Administrator = "admin" )
Variables ¶
var ( // AnonUser is anonymous user. AnonUser = &User{Name: Anonymous} // ErrAnonymous is error of anonymous authentication ErrAnonymous = errors.New("anonymous request") )
Functions ¶
func Authenticate ¶
Authenticate checks user's authentication. It doesn't validate user's token value and doesn't detect anonymous request as error, so this should be identified before. It writes User pointer to new context.
func CheckToken ¶
CheckToken verifies the token, checks length and hash value. If the token is valid, then its 2nd part (hash) will be added to the returned context. It also marks empty token as ErrAnonymous error.
func EqualBytes ¶
EqualBytes compares two byte slices. It is crypto-safe, because successful and unsuccessful attempts have around a same duration time.
func ExtractTokenKey ¶
ExtractTokenKey extracts user's from from context.
Types ¶
type User ¶
type User struct { Name string `bson:"_id"` Disabled bool `bson:"off"` Token string `bson:"token"` Roles []string `bson:"roles"` Modified time.Time `bson:"mt"` Created time.Time `bson:"ct"` }
User is structure of user's info.
func ExtractUser ¶
ExtractUser extracts user from from context.
func (*User) IsAnonymous ¶
IsAnonymous returns true if user is anonymous.
type UserResult ¶
UserResult is result of user creation.
func ChangeUsers ¶
func ChangeUsers(ctx context.Context, names []string) ([]UserResult, error)
ChangeUsers updates user's tokens. Administrator permissions should be checked before this call.
func CreateUsers ¶
func CreateUsers(ctx context.Context, names []string) ([]UserResult, error)
CreateUsers creates new users.
func DisableUsers ¶
func DisableUsers(ctx context.Context, names []string) ([]UserResult, error)
DisableUsers deactivates users' accounts. Administrator permissions should be checked before this call.