security

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 3 Imported by: 12

Documentation

Index

Constants

This section is empty.

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

GenericIdentityFromContext get the user from context

func (*GenericIdentity) Claims

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

func (*GenericIdentity) Name

func (i *GenericIdentity) Name() string

func (*GenericIdentity) NameIntX added in v0.2.3

func (i *GenericIdentity) NameIntX() int

NameIntX return the user id as int

type GenericPrincipal

type GenericPrincipal struct {
	GenericIdentity *GenericIdentity
}

GenericPrincipal Represents a generic principal.

func GenericPrincipalFromContext

func GenericPrincipalFromContext(ctx context.Context) *GenericPrincipal

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