Documentation ¶
Overview ¶
Package credential mini program credentials
Index ¶
- type AccessToken
- type AccessTokenHandle
- type ClientToken
- type ContextConfig
- type DefaultAccessToken
- func (t *DefaultAccessToken) GetAccessToken(ctx context.Context, openID string) (accessToken string, err error)
- func (t *DefaultAccessToken) GetClientToken(ctx context.Context) (clientToken *ClientToken, err error)
- func (t *DefaultAccessToken) RefreshAccessToken(ctx context.Context, refreshToken string) (accessToken *AccessToken, err error)
- func (t *DefaultAccessToken) RenewRefreshToken(ctx context.Context, refreshToken string) (refreshTokenData *RefreshToken, err error)
- func (t *DefaultAccessToken) SetAccessToken(ctx context.Context, accessToken *AccessToken) (err error)
- func (t *DefaultAccessToken) SetClientToken(ctx context.Context, clientToken *ClientToken) (err error)
- type DefaultJsTicket
- type JsTicketHandle
- type RefreshToken
- type Ticket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type AccessToken struct { base.CommonError AccessToken string `json:"access_token"` ExpiresIn int64 `json:"expires_in"` RefreshToken string `json:"refresh_token"` RefreshTokenIn int64 `json:"refresh_expires_in"` OpenID string `json:"openid"` Scope string `json:"scope"` }
AccessToken struct
type AccessTokenHandle ¶
type AccessTokenHandle interface { GetAccessToken(ctx context.Context, openID string) (accessToken string, err error) SetAccessToken(ctx context.Context, accessToken *AccessToken) (err error) GetClientToken(ctx context.Context) (clientToken *ClientToken, err error) }
AccessTokenHandle AccessToken 接口
func NewDefaultAccessToken ¶
func NewDefaultAccessToken(_ context.Context, cfg *config.Config) AccessTokenHandle
NewDefaultAccessToken new DefaultAccessToken
type ClientToken ¶
type ClientToken struct { base.CommonError AccessToken string `json:"access_token"` ExpiresIn int64 `json:"expires_in"` }
ClientToken client token
type ContextConfig ¶
type ContextConfig struct { *config.Config AccessTokenHandle }
ContextConfig 公共配置
func NewContextConfigWithAccessTokenHandle ¶
func NewContextConfigWithAccessTokenHandle(ctx context.Context, cfg *config.Config, accessTokenHandle AccessTokenHandle) *ContextConfig
NewContextConfigWithAccessTokenHandle new context config with access_token handle
func NewContextConfigWithConfig ¶
func NewContextConfigWithConfig(ctx context.Context, cfg *config.Config) *ContextConfig
NewContextConfigWithConfig new context config with config
func (*ContextConfig) SetAccessTokenHandle ¶
func (cfg *ContextConfig) SetAccessTokenHandle(accessTokenHandle AccessTokenHandle) *ContextConfig
SetAccessTokenHandle 设置 AccessTokenHandle
type DefaultAccessToken ¶
type DefaultAccessToken struct { ClientKey string ClientSecret string // contains filtered or unexported fields }
DefaultAccessToken 默认 AccessToken 获取
func (*DefaultAccessToken) GetAccessToken ¶
func (t *DefaultAccessToken) GetAccessToken(ctx context.Context, openID string) (accessToken string, err error)
GetAccessToken 获取 access_token,先从 cache 中获取,没有则从服务端获取
func (*DefaultAccessToken) GetClientToken ¶
func (t *DefaultAccessToken) GetClientToken(ctx context.Context) (clientToken *ClientToken, err error)
GetClientToken 该接口用于获取接口调用的凭证 client_access_token,主要用于调用不需要用户授权就可以调用的接口。
func (*DefaultAccessToken) RefreshAccessToken ¶
func (t *DefaultAccessToken) RefreshAccessToken(ctx context.Context, refreshToken string) (accessToken *AccessToken, err error)
RefreshAccessToken 刷新 AccessToken. 当 access_token 过期(过期时间 15 天)后,可以通过该接口使用 refresh_token(过期时间 30 天)进行刷新
func (*DefaultAccessToken) RenewRefreshToken ¶
func (t *DefaultAccessToken) RenewRefreshToken(ctx context.Context, refreshToken string) (refreshTokenData *RefreshToken, err error)
RenewRefreshToken 刷新 refresh_token. 前提:client_key 需要具备 renew_refresh_token 这个权限 接口说明:可以通过旧的 refresh_token 获取新的 refresh_token,调用后旧 refresh_token 会失效,新 refresh_token 有 30 天有效期。最多只能获取 5 次新的 refresh_token,5 次过后需要用户重新授权。
func (*DefaultAccessToken) SetAccessToken ¶
func (t *DefaultAccessToken) SetAccessToken(ctx context.Context, accessToken *AccessToken) (err error)
SetAccessToken 设置 access_token
func (*DefaultAccessToken) SetClientToken ¶
func (t *DefaultAccessToken) SetClientToken(ctx context.Context, clientToken *ClientToken) (err error)
SetClientToken 设置 client_token
type DefaultJsTicket ¶
type DefaultJsTicket struct {
// contains filtered or unexported fields
}
DefaultJsTicket 默认获取 js ticket 方法
type JsTicketHandle ¶
type JsTicketHandle interface { // GetTicket 获取 ticket GetTicket(ctx context.Context, accessToken string) (ticket string, err error) }
JsTicketHandle js ticket 获取
func NewDefaultJsTicket ¶
func NewDefaultJsTicket(_ context.Context, appID, cacheKeyPrefix string, cache cache.Cache, req request.Request) JsTicketHandle
NewDefaultJsTicket new
type RefreshToken ¶
type RefreshToken struct { base.CommonError ExpiresIn int64 `json:"expires_in"` RefreshToken string `json:"refresh_token"` }
RefreshToken refresh token