token

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: Zlib Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NAccessToken  = "access:token"         /*自己本身的access token*/
	NRefreshToken = "access:token:refresh" /*刷新自己本身access token */

	NTicket      = "get:ticket"
	NCreateChild = "create:child"

	NOauth2       = "oauth2" /*网页,个人授权*/
	NOauthAccount = "oauth2:account"
	NOauth2App3   = "oauth2:app3"        /*第三方应用授权,比把公众号授权给某个应用*/
	NPreAuthCode  = "app3:pre_auth_code" /* for 公众号授权给第三方,需要先获取一个 预授权码,然后调用前端授权页面进行授权,授权成功后会给一个授权码 "authorization_code"
	然后用这个 authorization_code去调用 NOauth2App3,获取到 access token 相关信息 */

	NAccessTokenProxy = "access:token:proxy" /* 进行代理,中转,从别的服务器获取token相关信息 */
)

Variables

This section is empty.

Functions

func AddToken

func AddToken(appId string, app *AppItem)

func ComponentUrl

func ComponentUrl(acsKey string, uri string) string

func DefaultForm

func DefaultForm(w *multipart.Writer, field, filename string) error

func DefaultUrl

func DefaultUrl(acsKey string, uri string) string

func DeleteToken

func DeleteToken(appId string) error

func EmptyUrl added in v1.0.0

func EmptyUrl(acsKey string, uri string) string

func GetEmpty

func GetEmpty(tk Token, d data.D) (access.Token, error)

func SyncAddAlias added in v1.0.0

func SyncAddAlias(parent Token, realId []string, aliasId AliasId)

func SyncCreateChild added in v1.0.0

func SyncCreateChild(parent Token, service Service, ch *Child, acsToken access.Token)

Types

type AliasId

type AliasId string

func (AliasId) String

func (a AliasId) String() string

type Api added in v1.0.0

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

func NewApi added in v1.0.0

func NewApi(tk Token) *Api

func (*Api) AppId added in v1.0.0

func (api *Api) AppId() string

func (*Api) Clone added in v1.0.0

func (api *Api) Clone() *Api

func (*Api) Request added in v1.0.0

func (api *Api) Request(method, uri string, buf []byte, resCb ResCallBack) error

func (*Api) ResetToken added in v1.0.0

func (api *Api) ResetToken()

func (*Api) Secret added in v1.0.0

func (api *Api) Secret() string

func (*Api) Upload added in v1.0.0

func (api *Api) Upload(uri string, file interface{}, resCb ResCallBack) error

func (*Api) WithOptions added in v1.0.0

func (api *Api) WithOptions(options OptionsFunc) *Api

type ApiGetTokenFunc added in v1.0.0

type ApiGetTokenFunc func(appId string, d data.D) (string, error)

type ApiGetUrlFunc added in v1.0.0

type ApiGetUrlFunc func(acsToken string, d data.D, uri string) string

type ApiSetHeadFunc added in v1.0.0

type ApiSetHeadFunc func(acsToken string, h *http.Header)

type ApiSetTokenFunc added in v1.0.0

type ApiSetTokenFunc func(appId string, token string)

type App

type App struct {
	Type    string `json:"type"`
	AppId   string `json:"appid"`
	Secret  string `json:"secret"`
	Name    string `json:"name"`
	IsCache bool   `json:"cache"`
}

type AppItem added in v1.0.0

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

func NewAppItem added in v1.0.0

func NewAppItem(app App, tk Token, options ...AppOptionsFunc) *AppItem

type AppMgr

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

func Mgr

func Mgr() *AppMgr

func (*AppMgr) AddAlias

func (m *AppMgr) AddAlias(appId string, realId []string, aliasId AliasId) error

func (*AppMgr) AddToken

func (m *AppMgr) AddToken(appId string, app *AppItem)

func (*AppMgr) Clear

func (m *AppMgr) Clear(appId string, aliasId string, key string) error

func (*AppMgr) CreateChild

func (m *AppMgr) CreateChild(parent Token, info *Child, service Service) (Token, error)

func (*AppMgr) DeleteToken

func (m *AppMgr) DeleteToken(appId string) error

func (*AppMgr) GetAliasId

func (m *AppMgr) GetAliasId(appId string, realId string) (AliasId, error)

func (*AppMgr) GetToken

func (m *AppMgr) GetToken(appId string) (Token, error)

func (*AppMgr) Read

func (m *AppMgr) Read(appId string, aliasId string, key string) (string, error)

func (*AppMgr) SetAccessToken

func (m *AppMgr) SetAccessToken(appId string, aliasId string, acs access.Token) string

func (*AppMgr) Write

func (m *AppMgr) Write(appId string, aliasId string, key string, v *validate.Data) error

type AppOptions

type AppOptions struct {
	Config
}

type AppOptionsFunc

type AppOptionsFunc func(opts *AppOptions)

type Base

type Base interface {
	GetAppId() string
	GetSecret() string
	GetAccessToken(options ...OptionsDataFunc) (string, error)
}

type Child

type Child struct {
	AliasId string
	Name    string
	VMap    VMap
}

type Config

type Config struct {
	Path    string `json:"path"`
	IsLocal bool   `json:"local"`
	IsRedis bool   `json:"redis"`
	RdsType string `json:"rdsType"`
}

type CreateChildFunc added in v1.0.0

type CreateChildFunc func(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error)

type FlagUpdate

type FlagUpdate int

FlagUpdate for fUpdate chan

type GetFunc

type GetFunc func(tk Token, d data.D) (access.Token, error)

type GetUrlFunc added in v1.0.0

type GetUrlFunc func(acsKey string, uri string) string

type Item added in v1.0.0

type Item struct {
	Apps []App `json:"apps"`
}

type Options added in v1.0.0

type Options struct {
	Data         data.D
	Token        string
	AppId        string
	Secret       string
	TryCount     int
	GetUrlFunc   ApiGetUrlFunc
	SetHeadFunc  ApiSetHeadFunc
	SetTokenFunc ApiSetTokenFunc
	GetTokenFunc ApiGetTokenFunc
}

type OptionsDataFunc

type OptionsDataFunc func(d data.D)

type OptionsFunc added in v1.0.0

type OptionsFunc func(opts *Options)

type ResCallBack added in v1.0.0

type ResCallBack func(hp *commonhttp.Http, body []byte) error

type ResCode

type ResCode struct {
	AppId string `json:"appid"`
	Type  string `json:"type"`
	Code  string `json:"code"`
}

type ResToken

type ResToken struct {
	AppId string `json:"appid"`
	Type  string `json:"type"`
	Token string `json:"token"`
}

type Service

type Service interface {
	GetUrl(tk Token, acsKey string, uri string) string
	SetHead(tk Token, acsKey string, r *http.Header)
	CreateForm(writer *multipart.Writer, form interface{}) error
	Execute(tk Token, cmd string, d data.D) (interface{}, error)
	CheckError(err error) error
}

type Ticket

type Ticket struct {
	Ticket   string `json:"ticket"`
	ExpireIn int64  `json:"expires_in"`
}

func (*Ticket) IsValid

func (at *Ticket) IsValid() bool

type Token

type Token interface {
	Parent() Token
	CreateChild(app *App, service Service) Token

	// GetUrl for request
	GetUrl(acsKey string, d data.D, uri string) string
	SetHead(acsKey string, h *http.Header)
	CreateForm(writer *multipart.Writer, form interface{}) error

	GetApp() *App
	GetAppId() string
	GetSecret() string

	GetAccessToken(options ...OptionsDataFunc) (string, error)
	SetAccessTokenWithAcs(acs access.Token) string
	SetAccessToken(tk string, expire int64) error
	ClearAccessToken()

	SetRefreshAccessToken(tk string, expire int64) error
	RefreshAccessToken(refToken string) (string, error)

	GetCode(name string) (string, error)
	ClearCode(name string) error
	SetCode(name, code string, expire int64) error

	// Execute data["appid"]
	Execute(cmd string, d data.D) (interface{}, error)
}

func CreateChild added in v1.0.0

func CreateChild(parent Token, service Service, ch *Child, acsToken access.Token) (Token, error)

func CreateChildEmpty added in v1.0.0

func CreateChildEmpty(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error)

func GetChild

func GetChild(appId string, realId string) (Token, error)

func GetToken

func GetToken(appId string) (Token, error)

func New

func New(app *App, service Service) Token

type VMap

type VMap map[string]*validate.Data

VMap [string] = access_token, refresh_token, code...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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