geniusAuth

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

README

GeniusAuthoritarianClient

Install
~$ go get github.com/ncuhome/GeniusAuthoritarianClient
Usage

Docs are available at wiki.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RpcJwtNotConnected            = errors.New("jwt parser rpc not connected")
	RpcJwtUserOperationIDNotFound = errors.New("user operation id not exist")
	RpcJwtTokenInvalid            = errors.New("token canceled")
)

Functions

func Request added in v1.1.9

func Request[T any](c Client, Type string, opt *DoReq) (*T, error)

Types

type ApiErr added in v1.1.9

type ApiErr struct {
	Code uint
	Msg  string
}

func (ApiErr) Error added in v1.1.9

func (e ApiErr) Error() string

type Client

type Client struct {
	Http *tool.Http

	Domain  string
	AppCode string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(domain, appCode, appSecret string, httpClient *http.Client) *Client

func (Client) CreateRpcClientCredential added in v1.2.1

func (c Client) CreateRpcClientCredential() (*RpcClientCredential, error)

func (Client) GetServerPublicKeys added in v1.2.1

func (c Client) GetServerPublicKeys() (*ServerPublicKeys, error)

func (Client) GetUserInfo added in v1.1.6

func (c Client) GetUserInfo(req *RequestVerifyToken) (*UserInfo, error)

func (Client) GetUserPublicInfo added in v1.1.10

func (c Client) GetUserPublicInfo(uid ...uint) ([]UserPublicInfo, error)

func (Client) LoginUrl

func (c Client) LoginUrl() string

func (Client) ModifyPayload added in v1.1.8

func (c Client) ModifyPayload(req *RequestModifyPayload) (*Tokens, error)

func (Client) NewRpcClient added in v1.2.1

func (c Client) NewRpcClient(addr string) (*RpcClient, error)

func (Client) RefreshToken

func (c Client) RefreshToken(req *RequestRefreshToken) (*RefreshToken, error)

func (Client) VerifyAccessToken

func (c Client) VerifyAccessToken(req *RequestVerifyAccessToken) (*VerifyAccessToken, error)

func (Client) VerifyToken

func (c Client) VerifyToken(req *RequestVerifyToken) (*VerifyToken, error)

type DoReq

type DoReq struct {
	Url  string
	Form interface{}
}

type Group added in v1.1.10

type Group struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

type RefreshToken added in v1.1.6

type RefreshToken struct {
	AccessToken string `json:"access_token"`
	Payload     string `json:"payload,omitempty"`
}

type RequestGetUserPublicInfo added in v1.1.10

type RequestGetUserPublicInfo struct {
	ID string `json:"id"`
}

type RequestModifyPayload added in v1.1.8

type RequestModifyPayload struct {
	Token       string `json:"token"`
	Payload     string `json:"payload"`
	AccessToken bool   `json:"accessToken"`
}

type RequestRefreshToken

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

type RequestVerifyAccessToken

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

type RequestVerifyToken

type RequestVerifyToken struct {
	Token     string `json:"token"`
	ClientIp  string `json:"clientIp,omitempty"`
	GrantType string `json:"grantType,omitempty"`

	Payload string `json:"payload,omitempty"`
	Valid   int64  `json:"valid,omitempty"`
}

type Response

type Response[T any] struct {
	Code uint   `json:"code"`
	Data T      `json:"data"`
	Msg  string `json:"msg"`
}

type RpcClient added in v1.2.1

type RpcClient struct {
	Api *Client

	appProto.AppClient
	// contains filtered or unexported fields
}

func (*RpcClient) Close added in v1.3.1

func (rpc *RpcClient) Close() error

func (*RpcClient) NewJwtParser added in v1.3.1

func (rpc *RpcClient) NewJwtParser() (*RpcJwtParser, error)

type RpcClientCredential added in v1.2.1

type RpcClientCredential struct {
	Cert        []byte `json:"cert"`        // pem format
	Key         []byte `json:"key"`         // pem format
	ValidBefore int64  `json:"validBefore"` // second
}

type RpcClientKeypair added in v1.2.1

type RpcClientKeypair struct {
	sync.RWMutex
	Cert *tls.Certificate
	Cred *RpcClientCredential
}

func (*RpcClientKeypair) Valid added in v1.2.1

func (k *RpcClientKeypair) Valid() bool

type RpcJwtParser added in v1.3.1

type RpcJwtParser struct {
	Rpc *RpcClient
	Jwt *jwt.Parser

	// UserOperationIDTable uint64 => uint64 uid => UserOperationID
	UserOperationIDTable sync.Map
	// CanceledTokenTable uint64 => time.Time TokenID => ValidBefore
	CanceledTokenTable sync.Map
	Connected          atomic.Bool

	// OnError process error produced in rpc watch stream
	OnError func(err error)
}

func (*RpcJwtParser) ParseAccessToken added in v1.3.1

func (p *RpcJwtParser) ParseAccessToken(token string) (*jwtClaims.AccessToken, bool, error)

func (*RpcJwtParser) ParseRefreshToken added in v1.3.1

func (p *RpcJwtParser) ParseRefreshToken(token string) (*jwtClaims.RefreshToken, bool, error)

func (*RpcJwtParser) TokenStatCheck added in v1.3.1

func (p *RpcJwtParser) TokenStatCheck(claims jwtClaims.ClaimsStandard) error

type ServerPublicKeys added in v1.2.1

type ServerPublicKeys struct {
	Jwt []byte `json:"jwt"`
	Ca  []byte `json:"ca"`
}

type Tokens added in v1.1.8

type Tokens struct {
	RefreshToken string `json:"refreshToken"`
	AccessToken  string `json:"accessToken,omitempty"`
}

type UserInfo added in v1.1.6

type UserInfo struct {
	UserID    uint     `json:"userID"`
	Name      string   `json:"name"`
	Groups    []string `json:"groups"`
	AvatarUrl string   `json:"avatarUrl"`
}

type UserPublicInfo added in v1.1.10

type UserPublicInfo struct {
	ID        uint    `json:"id"`
	Name      string  `json:"name"`
	AvatarUrl string  `json:"avatarUrl"`
	Groups    []Group `json:"groups"`
}

type VerifyAccessToken added in v1.1.6

type VerifyAccessToken struct {
	UID     uint   `json:"uid"`
	Payload string `json:"payload,omitempty"`
}

type VerifyToken added in v1.1.6

type VerifyToken struct {
	UserID       uint     `json:"userID"`
	Name         string   `json:"name"`
	Groups       []string `json:"groups"`
	AvatarUrl    string   `json:"avatarUrl"`
	RefreshToken string   `json:"refreshToken"`
	AccessToken  string   `json:"accessToken"`
}

Directories

Path Synopsis
jwt
rpc

Jump to

Keyboard shortcuts

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