acl

package
v0.0.0-...-6d0effa Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 19 Imported by: 6

Documentation

Index

Constants

View Source
const (
	AM_SERVER aclmMode = "server"
	AM_CLIENT aclmMode = "client"
)
View Source
const (
	TokenExpiredDuration = time.Hour * 24 * 30
	TokenDeviceKey       = "dev"
	TokenHasuraKey       = "https://hasura.io/jwt/claims"
)
View Source
const (
	QueueRoleAdd    = "queue_role_add"
	QueueRoleRemove = "queue_role_remove"
	QueueTokenCheck = "queue_token_check"
)
View Source
const (
	RoleAdmin = "admin"
	RoleUser  = "user"
)

builtin roles

Variables

This section is empty.

Functions

func AddRole

func AddRole(userID string, roleID ...string) error

func CheckDeviceToken

func CheckDeviceToken(ctx context.Context, deviceToken string, tokenStr string) (context.Context, error)

CheckDeviceToken 检查设备token 如果token中包含设备ID,检查设备ID是否匹配

func GetAllRoles

func GetAllRoles(ctx context.Context) []string

func GetJwtToken

func GetJwtToken(accountID, deviceID string, roles []string) (string, error)

func GetUserID

func GetUserID(ctx context.Context) string

func HasRole

func HasRole(ctx context.Context, roles ...string) bool

HasRole check if the user has the roles Auto add admin role to check if the user is admin

func RemoveRole

func RemoveRole(userID string, roleID ...string) error

func SetAllDeviceRemoveFlag

func SetAllDeviceRemoveFlag(accountID string)

标记所有设备需要重新登录

func SetDeviceRemoveFlag

func SetDeviceRemoveFlag(accountID, deviceID string)

标记设备需要重新登录

func WrapAuth

func WrapAuth(c AuthConfig) func(next http.Handler) http.Handler

Types

type ACLM

type ACLM struct {
	// contains filtered or unexported fields
}

func Aclm

func Aclm() *ACLM

func (*ACLM) Close

func (a *ACLM) Close() error

func (*ACLM) Mode

func (a *ACLM) Mode() aclmMode

type AuthConfig

type AuthConfig struct {
	NoNeedAuth bool
}

type HasuraClaims

type HasuraClaims struct {
	Roles  []string `json:"x-hasura-allowed-roles"`
	Role   string   `json:"x-hasura-default-role"`
	UserID string   `json:"x-hasura-user-id"`
}

Jump to

Keyboard shortcuts

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