Version: v0.2.2 Latest Latest

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 9 Imported by: 0




View Source
const (
	AnonymousID          uint64 = 0
	AnonymousUUID        string = "anonymo-anonym-anonym-anonym-anonymous"
	AnonymousUserName    string = "anonymous.d3tago"
	AnonymousNickName    string = "Anonymous"
	AnonymousAuthorityID string = "group:anonymous"

	SystemID          uint64 = 0
	SystemUUID        string = "system-system-system-system-system"
	SystemUserName    string = "system.d3tago"
	SystemNickName    string = "System"
	SystemAuthorityID string = "group:system"


View Source
var (
	ErrTokenExpired     = errors.New("Token is expired [TokenExpired]")
	ErrTokenNotValidYet = errors.New("Token not active yet [TokenNotValidYet]")
	ErrTokenMalformed   = errors.New("That's not even a token [TokenMalformed]")
	ErrTokenInvalid     = errors.New("Couldn't handle this token [IvalidToken]")


This section is empty.


type ClientDevices

type ClientDevices struct {
	UserAgent string
	IPAddress string

ClientDevices type

type Identity

type Identity struct {
	IsLogin     bool
	IsAnonymous bool
	TokenType   TokenType
	Token       string
	Claims      *JWTCustomClaims

	ClientDevices ClientDevices
	RequestInfo   RequestInfo
	// contains filtered or unexported fields

Identity type

func NewIdentity

func NewIdentity(iType IdentityType, tokenType TokenType, token string, claims *JWTCustomClaims, ctx interface{}, h *handler.Handler) (Identity, error)

NewIdentity new Identity

func (*Identity) CanAccess

func (i *Identity) CanAccess(domain, obj, act string, enforcer *casbin.Enforcer) bool

CanAccess can access

func (*Identity) CanAccessCurrentRequest

func (i *Identity) CanAccessCurrentRequest() bool

CanAccessCurrentRequest ca access current request

func (*Identity) SetCasbinEnforcer

func (i *Identity) SetCasbinEnforcer(modelPath string) error

SetCasbinEnforcer set CasbinEnforcer

type IdentityType added in v0.2.0

type IdentityType string

IdentityType Type

const (
	DefaultIdentity IdentityType = "default"
	SystemIdentity  IdentityType = "system"

type JWT

type JWT struct {
	SigningKey []byte
	Issuer     string
	// contains filtered or unexported fields

JWT type

func NewJWT

func NewJWT(h *handler.Handler) (*JWT, error)

NewJWT new JWT

func (*JWT) CreateCustomClaims

func (j *JWT) CreateCustomClaims(ID uint64, UUID, username, nickName, authorityID string) JWTCustomClaims

CreateCustomClaims create custom claims

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims JWTCustomClaims) (string, error)

CreateToken Create a token

func (*JWT) GenerateAnonymousToken

func (j *JWT) GenerateAnonymousToken() (c *JWTCustomClaims, token string, expiredAt int64, err error)

GenerateAnonymousToken generate anonymous token

func (*JWT) GenerateSystemToken added in v0.2.0

func (j *JWT) GenerateSystemToken() (c *JWTCustomClaims, token string, expiredAt int64, err error)

GenerateSystemToken generate system (identity) token

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(claims JWTCustomClaims) (token string, expiredAt int64, err error)

GenerateToken generate token

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*JWTCustomClaims, error)

ParseToken Parse token

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(tokenString string) (string, error)

RefreshToken update token

type JWTCustomClaims

type JWTCustomClaims struct {
	ID          uint64
	UUID        string
	Username    string
	NickName    string
	AuthorityID string

JWTCustomClaims represent JWT Custom claims structure

type RequestInfo

type RequestInfo struct {
	Host          string
	RemoteAddr    string
	RequestObject string
	RequestAction string

RequestInfo type

type TokenType

type TokenType string

TokenType type

const (
	// TokenJWT jwt Token
	TokenJWT TokenType = "JWT"
	// TokenSimple simple Token
	TokenSimple TokenType = "Simple"

Jump to

Keyboard shortcuts

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