identity

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 9 Imported by: 18

Documentation

Index

Constants

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

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

Variables

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

Functions

This section is empty.

Types

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 represent Identity

func NewIdentity

func NewIdentity(iType TheIdentityType, 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 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

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
	jwt.StandardClaims
}

JWTCustomClaims represent JWT Custom claims structure

type RequestInfo

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

RequestInfo type

type TheIdentityType

type TheIdentityType string

TheIdentityType represent TheIdentityType

const (
	// DefaultIdentity represent Default Identity
	DefaultIdentity TheIdentityType = "default"
	// SystemIdentity represent System Identity
	SystemIdentity TheIdentityType = "system"
)

type TokenType

type TokenType string

TokenType represent TokenType

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