security

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 3 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// UserContextKey is the key of context which store the user.
	UserContextKey = "woocoo_user"
)

Variables

This section is empty.

Functions

func GetSubjectFromToken

func GetSubjectFromToken(ctx context.Context, key string) (any, bool)

GetSubjectFromToken Get Sub(User) from context with Jwt default token using jwt.MapClaims. if not found, return nil and false. key is the key of context which store the jwt token.

func WithContext

func WithContext(ctx context.Context, user Principal) context.Context

WithContext Add user to context.

Types

type GenericIdentity

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

GenericIdentity Represents a generic user.

func GenericIdentityFromContext

func GenericIdentityFromContext(ctx context.Context) (*GenericIdentity, bool)

GenericIdentityFromContext get the user from context

func (*GenericIdentity) Claims

func (i *GenericIdentity) Claims() jwt.MapClaims

func (*GenericIdentity) Name

func (i *GenericIdentity) Name() string

Name returns the id of the user.

func (*GenericIdentity) NameInt added in v0.4.0

func (i *GenericIdentity) NameInt() int

NameInt returns the id of the user. if not int, return 0

type GenericPrincipal

type GenericPrincipal struct {
	GenericIdentity *GenericIdentity
}

GenericPrincipal Represents a generic principal.

func GenericPrincipalFromContext

func GenericPrincipalFromContext(ctx context.Context) (*GenericPrincipal, bool)

GenericPrincipalFromContext get the user from context

func NewGenericPrincipalByClaims

func NewGenericPrincipalByClaims(claims jwt.MapClaims) *GenericPrincipal

NewGenericPrincipalByClaims return GenericPrincipal

func (*GenericPrincipal) Identity

func (p *GenericPrincipal) Identity() Identity

type Identity

type Identity interface {
	Name() string
	Claims() jwt.MapClaims
}

Identity defines the basic functionality of an identity object.

An identity object represents the user on whose behalf the code is running

type PermissionItem

type PermissionItem struct {
	// AppCode is the application code which the action belongs to.
	AppCode string
	// Action name
	Action string
	// Operator name
	Operator string
}

PermissionItem is for describing a permission.

type Principal

type Principal interface {
	Identity() Identity
}

Principal Defines the basic functionality of a principal object.

A principal object represents the security context of the user on whose behalf the code is running, including that user's identity (IIdentity) and any roles to which they belong.

Jump to

Keyboard shortcuts

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