auth

package
v0.0.0-...-3c05ffe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// RoleDatabaseManager role to save, delete and get info from database
	RoleDatabaseManager = iota

	// RoleImageManager role to save, delete and get info from image
	RoleImageManager

	// RoleScriptManager role to save, delete and get info from script
	RoleScriptManager

	// RoleUserManager role to save, delete and get info of database users
	RoleUserManager
)

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(reqUser User, expire int) (string, bool)

Authenticate authenticates user and returns token

func CheckUserPermission

func CheckUserPermission(user UserClaim, role int) bool

CheckUserPermission checks if UserClaim has the role

func LoadUserConfig

func LoadUserConfig(filePath string, dbConfig *db.SparrowConfig)

LoadUserConfig loads users from configuration file

Types

type Roles

type Roles struct {
	RoleDatabaseManager bool `xml:"database-manager" json:"database-manager"`
	RoleImageManager    bool `xml:"image-manager" json:"image-manager"`
	RoleScriptManager   bool `xml:"script-manager" json:"script-manager"`
	RoleUserManager     bool `xml:"user-manager" json:"user-manager"`
}

Roles holds user roles

type User

type User struct {
	Username string `xml:"username,attr" json:"username"`
	Password string `xml:"password,attr" json:"password"`
	Roles    Roles  `xml:"roles" json:"roles"`
}

User holds user info

type UserClaim

type UserClaim struct {
	Username string `json:"username"`
	Roles    Roles
	jwt.StandardClaims
}

UserClaim authorization claim

func ParseClaimFromRequest

func ParseClaimFromRequest(req *http.Request) (*jwt.Token, UserClaim, error)

ParseClaimFromRequest parse claims from user request

type UsersConfig

type UsersConfig struct {
	XMLName xml.Name `xml:"users"`
	Users   []User   `xml:"user"`
}

UsersConfig user from xml file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL