authorize

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name          = "authorize"
	CurrentClaims = "claims"
)

Variables

This section is empty.

Functions

func AuthHttpRequest

func AuthHttpRequest(req *http.Request, needAdmin bool) error

func AuthMiddleware

func AuthMiddleware(needAdmin bool) mux.MiddlewareFunc

func DIMiddleware

func DIMiddleware(authorize Authorize) mux.MiddlewareFunc

func ToContext

func ToContext(ctx context.Context, claim *Claims) context.Context

Types

type Authorize

type Authorize interface {
	Authorize(auth authenticate.Authenticate, needAdmin bool) (*Claims, error)
}

type Claims

type Claims struct {
	UserID   string `json:"user_id" map:"id"`
	UnitID   string `json:"unit_id"`
	Username string `json:"username"`
	Name     string `json:"name"`
	Surname  string `json:"surname"`
	Email    string `json:"email"`
	Mobile   string `json:"mobile"`
}

func FromContext

func FromContext(ctx context.Context) *Claims

type Ldap

type Ldap struct {
	LdapConfigs
	Client *ldapext.Client
}

func NewLdap

func NewLdap(configs LdapConfigs) (*Ldap, error)

func (Ldap) Authorize

func (a Ldap) Authorize(auth authenticate.Authenticate, needAdmin bool) (*Claims, error)

type LdapConfigs

type LdapConfigs struct {
	Base       ldapext.Configs
	LdapAdmins string `env:"LDAP_ADMINS,required"`
}

type Static

type Static struct {
	StaticConfigs
}

func NewStatic deprecated

func NewStatic(configs StaticConfigs) *Static

Deprecated: This method will be removed soon, Use the NewLdap method instead

func (Static) Authorize

func (a Static) Authorize(auth authenticate.Authenticate, needAdmin bool) (*Claims, error)

type StaticConfigs

type StaticConfigs struct {
	StaticAdmins      []string          `env:"STATIC_ADMINS"`
	StaticCredentials map[string]string `env:"STATIC_CREDENTIALS"`
}

Jump to

Keyboard shortcuts

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