auth

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 23 Imported by: 8

Documentation

Index

Constants

View Source
const DefaultAdminTokenName = "defaultLocalToken"

DefaultAdminToken is the default admin token which is for local client user

Variables

View Source
var (
	ErrorNonRegisteredToken = xerrors.New("A non-registered token")
	ErrorVerificationFailed = xerrors.New("Verification Failed")
	ErrorPermissionDeny     = xerrors.New("Permission Deny")
	ErrorPermissionNotFound = errors.New("permission not found")
	ErrorUsernameNotFound   = errors.New("username not found")
)

Functions

func BadResponse

func BadResponse(c *gin.Context, err error)

func CorsMiddleWare

func CorsMiddleWare() gin.HandlerFunc

func DecodeToBytes

func DecodeToBytes(enc []byte) ([]byte, error)

func InitRouter

func InitRouter(app OAuthApp) http.Handler

todo: rm checkPermission after v1.13.0

func IsSignerAddress

func IsSignerAddress(addr address.Address) bool

func JwtUserFromToken

func JwtUserFromToken(token string) (string, error)

func Response

func Response(c *gin.Context, err error)

func RewriteAddressInUrl

func RewriteAddressInUrl() gin.HandlerFunc

func SuccessResponse

func SuccessResponse(c *gin.Context, obj interface{})

Types

type CreateUserRequest

type CreateUserRequest struct {
	Name    string         `form:"name" binding:"required"`
	Comment *string        `form:"comment"`
	State   core.UserState `form:"state"` // 0: disable, 1: enable
}

type CreateUserResponse

type CreateUserResponse = OutputUser

type DelMinerReq

type DelMinerReq struct {
	Miner address.Address `json:"miner"`
}

type DelSignerReq

type DelSignerReq struct {
	Signer address.Address `json:"signer"`
}

type DelUserRateLimitReq

type DelUserRateLimitReq struct {
	Name string `form:"name"`
	Id   string `form:"id"`
}

type DeleteUserRequest

type DeleteUserRequest struct {
	Name string `form:"name" binding:"required"`
}

type GenTokenRequest

type GenTokenRequest struct {
	Name  string `form:"name" json:"name" binding:"required"`
	Perm  string `form:"perm" json:"perm"`
	Extra string `form:"extra" json:"extra"`
}

type GenTokenResponse

type GenTokenResponse struct {
	Token string `json:"token"`
}

type GetTokenRequest

type GetTokenRequest struct {
	Token string `form:"token" json:"token"`
	Name  string `form:"name" json:"name"`
}

type GetTokensRequest

type GetTokensRequest struct {
	*core.Page
}

type GetTokensResponse

type GetTokensResponse = []*TokenInfo

type GetUserByMinerRequest

type GetUserByMinerRequest struct {
	Miner address.Address `form:"miner" binding:"required"`
}

type GetUserBySignerReq

type GetUserBySignerReq struct {
	Signer address.Address `form:"signer"`
}

type GetUserRateLimitResponse

type GetUserRateLimitResponse []*storage.UserRateLimit

func (GetUserRateLimitResponse) MatchedLimit

func (ls GetUserRateLimitResponse) MatchedLimit(service, api string) *storage.UserRateLimit

type GetUserRateLimitsReq

type GetUserRateLimitsReq struct {
	Id   string `form:"id"`
	Name string `form:"name" binding:"required"`
}

type GetUserRequest

type GetUserRequest struct {
	Name string `form:"name" binding:"required"`
}

type HasMinerRequest

type HasMinerRequest struct {
	Miner address.Address `form:"miner" binding:"required"`
}

type HasSignerReq

type HasSignerReq struct {
	Signer address.Address `form:"signer"`
}

type HasUserRequest

type HasUserRequest struct {
	Name string `form:"name" binding:"required"`
}

type JWTPayload

type JWTPayload struct {
	Name  string          `json:"name"`
	Perm  core.Permission `json:"perm"`
	Extra string          `json:"ext"`
}

func DecodeToken added in v1.15.0

func DecodeToken(token string) (*JWTPayload, error)

type ListMinerReq

type ListMinerReq struct {
	User string `form:"user" binding:"required"`
}

type ListMinerResp

type ListMinerResp []*OutputMiner

type ListSignerReq

type ListSignerReq struct {
	User string `form:"user"`
}

type ListSignerResp

type ListSignerResp []*OutputSigner

type ListUsersRequest

type ListUsersRequest struct {
	*core.Page
	State int `form:"state" json:"state"`
}

func NewListUsersRequest

func NewListUsersRequest(skip, limit int64, state int) *ListUsersRequest

type ListUsersResponse

type ListUsersResponse = []*OutputUser

type Mapper

type Mapper interface {
	ToOutPutUser(user *storage.User) *OutputUser
	ToOutPutUsers(arr []*storage.User) []*OutputUser
}

type MinerExistInUserRequest

type MinerExistInUserRequest struct {
	Miner address.Address `form:"miner"`
	User  string          `form:"user"`
}

type OAuthApp

type OAuthApp interface {
	GetDefaultAdminToken() (string, error)

	Verify(c *gin.Context)
	GenerateToken(c *gin.Context)
	RemoveToken(c *gin.Context)
	RecoverToken(c *gin.Context)
	Tokens(c *gin.Context)
	GetToken(c *gin.Context)

	CreateUser(c *gin.Context)
	GetUser(c *gin.Context)
	VerifyUsers(c *gin.Context)
	ListUsers(c *gin.Context)
	HasUser(c *gin.Context)
	UpdateUser(c *gin.Context)
	DeleteUser(c *gin.Context)
	RecoverUser(c *gin.Context)

	AddUserRateLimit(c *gin.Context)
	UpsertUserRateLimit(c *gin.Context)
	GetUserRateLimit(c *gin.Context)
	DelUserRateLimit(c *gin.Context)

	UpsertMiner(c *gin.Context)
	HasMiner(c *gin.Context)
	MinerExistInUser(c *gin.Context)
	ListMiners(c *gin.Context)
	DeleteMiner(c *gin.Context)
	GetUserByMiner(c *gin.Context)

	RegisterSigners(c *gin.Context)
	SignerExistInUser(c *gin.Context)
	ListSigner(c *gin.Context)
	UnregisterSigners(c *gin.Context)
	HasSigner(c *gin.Context)
	DelSigner(c *gin.Context)
	GetUserBySigner(c *gin.Context)
	// contains filtered or unexported methods
}

func NewOAuthApp

func NewOAuthApp(dbPath string, cnf *config.DBConfig) (OAuthApp, error)

type OAuthService

type OAuthService interface {
	GenerateToken(ctx context.Context, cp *JWTPayload) (string, error)
	Verify(ctx context.Context, token string) (*JWTPayload, error)
	RemoveToken(ctx context.Context, token string) error
	RecoverToken(ctx context.Context, token string) error
	Tokens(ctx context.Context, skip, limit int64) ([]*TokenInfo, error)
	GetToken(c context.Context, token string) (*TokenInfo, error)
	GetTokenByName(c context.Context, name string) ([]*TokenInfo, error)

	CreateUser(ctx context.Context, req *CreateUserRequest) (*CreateUserResponse, error)
	GetUser(ctx context.Context, req *GetUserRequest) (*OutputUser, error)
	VerifyUsers(ctx context.Context, req *VerifyUsersReq) error
	ListUsers(ctx context.Context, req *ListUsersRequest) (ListUsersResponse, error)
	HasUser(ctx context.Context, req *HasUserRequest) (bool, error)
	UpdateUser(ctx context.Context, req *UpdateUserRequest) error
	DeleteUser(ctx context.Context, req *DeleteUserRequest) error
	RecoverUser(ctx context.Context, req *RecoverUserRequest) error

	GetUserRateLimits(ctx context.Context, req *GetUserRateLimitsReq) (GetUserRateLimitResponse, error)
	UpsertUserRateLimit(ctx context.Context, req *UpsertUserRateLimitReq) (string, error)
	DelUserRateLimit(ctx context.Context, req *DelUserRateLimitReq) error

	UpsertMiner(ctx context.Context, req *UpsertMinerReq) (bool, error)
	HasMiner(ctx context.Context, req *HasMinerRequest) (bool, error)
	MinerExistInUser(ctx context.Context, req *MinerExistInUserRequest) (bool, error)
	ListMiners(ctx context.Context, req *ListMinerReq) (ListMinerResp, error)
	DelMiner(ctx context.Context, req *DelMinerReq) (bool, error)
	GetUserByMiner(ctx context.Context, req *GetUserByMinerRequest) (*OutputUser, error)

	RegisterSigners(ctx context.Context, req *RegisterSignersReq) error
	SignerExistInUser(ctx context.Context, req *SignerExistInUserReq) (bool, error)
	ListSigner(ctx context.Context, req *ListSignerReq) (ListSignerResp, error)
	UnregisterSigners(ctx context.Context, req *UnregisterSignersReq) error
	HasSigner(ctx context.Context, req *HasSignerReq) (bool, error)
	DelSigner(ctx context.Context, req *DelSignerReq) (bool, error)
	GetUserBySigner(ctx context.Context, req *GetUserBySignerReq) ([]*OutputUser, error)
}

func NewOAuthService

func NewOAuthService(dbPath string, cnf *config.DBConfig) (OAuthService, error)

type OutputMiner

type OutputMiner struct {
	Miner                address.Address
	User                 string
	OpenMining           bool
	CreatedAt, UpdatedAt time.Time
}

type OutputSigner

type OutputSigner struct {
	Signer               address.Address
	User                 string
	CreatedAt, UpdatedAt time.Time
}

type OutputUser

type OutputUser struct {
	Id         string         `json:"id"`
	Name       string         `json:"name"`
	Comment    string         `json:"comment"`
	State      core.UserState `json:"state"`
	CreateTime int64          `json:"createTime"`
	UpdateTime int64          `json:"updateTime"`
	// the field `Miners` is used for compound api `ListUserWithMiners`
	// which calls 'listuser' and for each 'user' calls 'listminers'
	Miners []*OutputMiner `json:"-"`
}

type RecoverTokenRequest

type RecoverTokenRequest struct {
	Token string `form:"token" json:"token" binding:"required"`
}

type RecoverUserRequest

type RecoverUserRequest struct {
	Name string `form:"name" binding:"required"`
}

type RegisterSignersReq

type RegisterSignersReq struct {
	User    string
	Signers []address.Address
}

type definitions for signer

type RemoveTokenRequest

type RemoveTokenRequest struct {
	Token string `form:"token" json:"token" binding:"required"`
}

type SignerExistInUserReq

type SignerExistInUserReq struct {
	Signer address.Address `form:"signer"`
	User   string          `form:"user"`
}

type TokenInfo

type TokenInfo struct {
	Token      string    `json:"token"`
	Name       string    `json:"name"`
	Perm       string    `json:"perm"`
	Custom     string    `json:"custom"`
	CreateTime time.Time `json:"createTime"`
}

type UnregisterSignersReq

type UnregisterSignersReq struct {
	User    string
	Signers []address.Address
}

type UpdateUserRequest

type UpdateUserRequest struct {
	Name    string         `form:"name"`
	Comment *string        `form:"comment"`
	State   core.UserState `form:"state"`
}

type UpsertMinerReq

type UpsertMinerReq struct {
	User       string          `binding:"required"`
	Miner      address.Address `binding:"required"`
	OpenMining *bool           `binding:"required"`
}

type UpsertUserRateLimitReq

type UpsertUserRateLimitReq storage.UserRateLimit

type VerifyAop

type VerifyAop interface {
	Verify(ctx context.Context, token string) (*JWTPayload, error)
}

type VerifyRequest

type VerifyRequest struct {
	Token string `form:"token" binding:"required"`
}

type VerifyResponse

type VerifyResponse = JWTPayload

type VerifyUsersReq

type VerifyUsersReq struct {
	Names []string `form:"names" binding:"required"`
}

Jump to

Keyboard shortcuts

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