wechat

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AuthURL     = "https://open.weixin.qq.com/connect/qrconnect"
	TokenURL    = "https://api.weixin.qq.com/sns/oauth2/access_token"
	RefreshURL  = "https://api.weixin.qq.com/sns/oauth2/refresh_token"
	UserInfoURL = "https://api.weixin.qq.com/sns/userinfo"
)
View Source
var (
	OptionStyleWhite     toauth2.AuthCodeOption = toauth2.SetAuthURLParam("style", "white")
	OptionStyleBlack     toauth2.AuthCodeOption = toauth2.SetAuthURLParam("style", "black")
	OptionEmptyStyleType toauth2.AuthCodeOption = toauth2.SetAuthURLParam("styletype", "")
	OptionEmptySizeType  toauth2.AuthCodeOption = toauth2.SetAuthURLParam("sizetype", "")
)

Functions

func AuthCodeURL

func AuthCodeURL(c *oauth2.Config, state string, opts ...toauth2.AuthCodeOption) string

func Exchange

func Exchange(ctx context.Context, c *oauth2.Config, code string, opts ...toauth2.AuthCodeOption) (*oauth2.Token, error)

func GetOpenID

func GetOpenID(_ context.Context, token *oauth2.Token) (string, error)

func GetUnionID added in v0.2.0

func GetUnionID(_ context.Context, token *oauth2.Token) (string, error)

func GetUserID added in v0.2.0

func GetUserID(_ context.Context, token *oauth2.Token) (toauth2.UserID, error)

func RefreshToken added in v0.1.5

func RefreshToken(ctx context.Context, c *oauth2.Config, refreshToken string) (*oauth2.Token, error)

TODO: TokenSource?

Types

type Provider added in v0.1.5

type Provider struct {
	ClientKey   string
	Secret      string
	CallbackURL string
	HTTPClient  *http.Client
	// contains filtered or unexported fields
}

Provider is the implementation of `goth.Provider` for accessing Wechat.

func New added in v0.1.5

func New(clientKey, secret, callbackURL string, scopes ...string) *Provider

New creates a new Wechat provider and sets up important connection details. You should always call `wechat.New` to get a new provider. Never try to create one manually.

func NewCustomisedURL added in v0.1.5

func NewCustomisedURL(clientKey, secret, callbackURL, authURL, tokenURL, refreshURL, userInfoURL string, scopes ...string) *Provider

NewCustomisedURL is similar to New(...) but can be used to set custom URLs to connect to

func (*Provider) AuthCodeURLOptions added in v0.1.5

func (p *Provider) AuthCodeURLOptions(options ...toauth2.AuthCodeOption)

func (*Provider) BeginAuth added in v0.1.5

func (p *Provider) BeginAuth(state string) (goth.Session, error)

BeginAuth asks Wechat for an authentication end-point.

func (*Provider) Client added in v0.1.5

func (p *Provider) Client() *http.Client

func (*Provider) Debug added in v0.1.5

func (p *Provider) Debug(debug bool)

Debug is a no-op for the wechat package.

func (*Provider) ExchangeOptions added in v0.1.5

func (p *Provider) ExchangeOptions(options ...toauth2.AuthCodeOption)

func (*Provider) FetchUser added in v0.1.5

func (p *Provider) FetchUser(session goth.Session) (goth.User, error)

FetchUser will go to Wechat and access basic information about the user.

func (*Provider) Name added in v0.1.5

func (p *Provider) Name() string

Name is the name used to retrieve this provider later.

func (*Provider) RefreshToken added in v0.1.5

func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error)

RefreshToken get new access token based on the refresh token

func (*Provider) RefreshTokenAvailable added in v0.1.5

func (p *Provider) RefreshTokenAvailable() bool

RefreshTokenAvailable refresh token is provided by auth provider or not

func (*Provider) SetName added in v0.1.5

func (p *Provider) SetName(name string)

SetName is to update the name of the provider (needed in case of multiple providers of 1 type)

func (*Provider) UnmarshalSession added in v0.1.5

func (p *Provider) UnmarshalSession(data string) (goth.Session, error)

UnmarshalSession wil unmarshal a JSON string into a session.

func (*Provider) UserInfoOptions added in v0.1.5

func (p *Provider) UserInfoOptions(options ...toauth2.AuthCodeOption)

type Session added in v0.1.5

type Session struct {
	AuthURL      string
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
	OpenID       string
}

func (*Session) Authorize added in v0.1.5

func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error)

Authorize the session with Wechat and return the access token to be stored for future use.

func (Session) GetAuthURL added in v0.1.5

func (s Session) GetAuthURL() (string, error)

GetAuthURL will return the URL set by calling the `BeginAuth` function on the Wechat provider.

func (Session) Marshal added in v0.1.5

func (s Session) Marshal() string

Marshal the session into a string

func (Session) String added in v0.1.5

func (s Session) String() string

type User

type User struct {
	OpenID    string `json:"openid"`
	Nickname  string `json:"nickname"`
	Gender    int    `json:"sex"` // 值为1时是男性,值为2时是女性,值为0时是未知
	AvatarURL string `json:"headimgurl"`
	Email     string `json:"email"`
	UnionID   string `json:"unionid"`

	Raw map[string]interface{} `json:"-"`
}

func GetUser

func GetUser(ctx context.Context, _ *oauth2.Config, token *oauth2.Token, opts ...toauth2.AuthCodeOption) (*User, error)

Jump to

Keyboard shortcuts

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