ucs

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

ucs-go-sdk

build Go Reference

用于集成ucs的开发包

快速开始

安装
go get -u github.com/Macrow/ucs-go-sdk
验证Jwt
validator := NewValidator(rsaPublicKey)
jwtUser, err := validator.ValidateJwt(token)
创建连接UCS的客户端
client := NewRpcClient("your.domain.com", yourPort) // Rpc客户端
// client := NewTLSRpcClient(certFile, "your.domain.com", yourPort) // TLS连接下的Rpc客户端,需要UCS服务也同时开启
// client := NewHttpClient("your.domain.com", yourPort, false, yourAccessCode) // Http客户端
client.SetToken(token)
UCS服务端验证Jwt
err := client.ValidateJwt()
UCS服务端验证操作码
err := client.ValidatePermOperationByCode("UCS_O_CODE")
UCS服务端验证接口
err := client.ValidatePermAction("ucs", "/api/v1/ucs/users", "get")
UCS服务端验证用户是否拥有机构权限
err := client.ValidatePermOrgById("org_id_is_here")

Documentation

Index

Constants

View Source
const (
	DefaultHeaderRandomKey  = "Random-Key"
	DefaultHeaderAccessCode = "Access-Code"
	DefaultNoPermMsg        = "权限不足"
	DefaultTimeout          = 3

	ValidateJwtURL                 = "/api/v1/ucs/current/blank"
	ValidatePermOperationByCodeURL = "/api/v1/ucs/current/check-operation"
	ValidatePermActionURL          = "/api/v1/ucs/current/check-action"
	ValidatePermOrgByIdURL         = "/api/v1/ucs/current/check-org"
)
View Source
const (
	JwtTokenClaimsId       = "id"
	JwtTokenClaimsName     = "name"
	JwtTokenClaimsDeviceId = "did"
	JwtTokenClaimsIssuer   = "iss"
	JwtTokenClaimsIssueAt  = "iat"
	JwtTokenClaimsExpireAt = "exp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	SetTimeout(timeout int) Client
	SetToken(token string) Client
	SetHttpHeaderNames(accessCodeHeader, randomKeyHeader string) Client
	ValidateJwt() error
	ValidatePermOperationByCode(operationCode string) error
	ValidatePermAction(service, path, method string) error
	ValidatePermOrgById(orgId string) error
}

func NewHttpClient added in v1.1.0

func NewHttpClient(addr string, port int, ssl bool, accessCode string) Client

func NewRpcClient added in v1.1.0

func NewRpcClient(addr string, port int) Client

func NewTLSRpcClient added in v1.1.0

func NewTLSRpcClient(cert []byte, addr string, port int) Client

type CommonPermitResult added in v1.1.0

type CommonPermitResult struct {
	Permit bool `json:"permit"`
}

type HttpClient added in v1.1.0

type HttpClient struct {
	// contains filtered or unexported fields
}

func (*HttpClient) SetHttpHeaderNames added in v1.1.0

func (c *HttpClient) SetHttpHeaderNames(accessCodeHeader, randomKeyHeader string) Client

func (*HttpClient) SetTimeout added in v1.1.0

func (c *HttpClient) SetTimeout(timeout int) Client

func (*HttpClient) SetToken added in v1.1.0

func (c *HttpClient) SetToken(token string) Client

func (*HttpClient) ValidateJwt added in v1.1.0

func (c *HttpClient) ValidateJwt() error

func (*HttpClient) ValidatePermAction added in v1.1.0

func (c *HttpClient) ValidatePermAction(service, path, method string) error

func (*HttpClient) ValidatePermOperationByCode added in v1.1.0

func (c *HttpClient) ValidatePermOperationByCode(operationCode string) error

func (*HttpClient) ValidatePermOrgById added in v1.1.0

func (c *HttpClient) ValidatePermOrgById(orgId string) error

type JwtUser

type JwtUser struct {
	Id       string  `json:"id"`    // 用户id
	Name     string  `json:"name"`  // 用户登录名
	DeviceId string  `json:"did"`   // 用户登录名
	Issuer   string  `json:"iss"`   // 签发者
	IssueAt  float64 `json:"iat"`   // 签发时间
	ExpireAt float64 `json:"exp"`   // 过期时间
	Token    string  `json:"token"` // 令牌字符串
}

func ValidateJwt

func ValidateJwt(publicKey []byte, tokenString string) (user *JwtUser, err error)

type NormalHttpResponse added in v1.1.0

type NormalHttpResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Result  interface{} `json:"result"`
}

type PermitHttpResponse added in v1.1.0

type PermitHttpResponse struct {
	Code    int                `json:"code"`
	Message string             `json:"message"`
	Result  CommonPermitResult `json:"result"`
}

type RpcClient added in v1.1.0

type RpcClient struct {
	// contains filtered or unexported fields
}

func (*RpcClient) SetHttpHeaderNames added in v1.1.0

func (c *RpcClient) SetHttpHeaderNames(accessCodeHeader, randomKeyHeader string) Client

func (*RpcClient) SetTimeout added in v1.1.0

func (c *RpcClient) SetTimeout(timeout int) Client

func (*RpcClient) SetToken added in v1.1.0

func (c *RpcClient) SetToken(token string) Client

func (*RpcClient) ValidateJwt added in v1.1.0

func (c *RpcClient) ValidateJwt() error

func (*RpcClient) ValidatePermAction added in v1.1.0

func (c *RpcClient) ValidatePermAction(service, path, method string) error

func (*RpcClient) ValidatePermOperationByCode added in v1.1.0

func (c *RpcClient) ValidatePermOperationByCode(operationCode string) error

func (*RpcClient) ValidatePermOrgById added in v1.1.0

func (c *RpcClient) ValidatePermOrgById(orgId string) error

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(publicKey []byte) *Validator

func (*Validator) ValidateJwt

func (v *Validator) ValidateJwt(tokenString string) (user *JwtUser, err error)

Directories

Path Synopsis
pkg
pb

Jump to

Keyboard shortcuts

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