Documentation
¶
Index ¶
- func DelClient(names ...string)
- func Init(configs ...Config) (err error)
- type Config
- type Endpoint
- type GoOAuth
- func (c *GoOAuth) AuthUrl(state string, opts ...oauth2.AuthCodeOption) string
- func (c *GoOAuth) Exchange(ctx context.Context, authorizationCode string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (c *GoOAuth) GetAccessToken() string
- func (c *GoOAuth) GetRefreshToken() string
- func (c *GoOAuth) GetToken() *oauth2.Token
- func (c *GoOAuth) RefreshToken(ctx context.Context) (*oauth2.Token, error)
- func (c *GoOAuth) TokenSource(ctx context.Context) oauth2.TokenSource
- type GoogleUserInfo
- type IGoOAuth
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Name string `yaml:"Name" json:"name,optional"` // Token 信息 AccessToken string `yaml:"AccessToken" json:"accessToken,optional"` RefreshToken string `yaml:"RefreshToken" json:"refreshToken,optional"` ExpiresIn int64 `yaml:"ExpiresIn" json:"expiresIn,optional"` //秒s // 授权参数 OAuthConfig oauth2.Config ClientId string `yaml:"ClientId" json:"clientId,optional"` ClientSecret string `yaml:"ClientSecret" json:"clientSecret,optional"` RedirectURL string `yaml:"RedirectURL" json:"redirectURL,optional"` Endpoint *Endpoint `yaml:"Endpoint" json:"endpoint"` Scopes []string `yaml:"Scopes" json:"scopes,optional"` }
type Endpoint ¶ added in v1.2.122
type Endpoint struct { TokenURL string `yaml:"TokenURL" json:"tokenURL,optional"` AuthURL string `yaml:"AuthURL" json:"authURL,optional"` DeviceAuthURL string `yaml:"DeviceAuthURL" json:"deviceAuthURL,optional"` AuthStyle oauth2.AuthStyle `yaml:"AuthStyle" json:"authStyle,optional"` } // `yaml:"Endpoint" json:"endpoint"`
type GoOAuth ¶
func (*GoOAuth) AuthUrl ¶
func (c *GoOAuth) AuthUrl(state string, opts ...oauth2.AuthCodeOption) string
获取授权url
自定义参数
param1 := oauth2.SetAuthURLParam("param1", "value1") param2 := oauth2.SetAuthURLParam("param2", "value2")
func (*GoOAuth) Exchange ¶
func (c *GoOAuth) Exchange(ctx context.Context, authorizationCode string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
获取token
自定义参数
param1 := oauth2.SetAuthURLParam("param1", "value1") param2 := oauth2.SetAuthURLParam("param2", "value2")
func (*GoOAuth) GetAccessToken ¶
func (*GoOAuth) GetRefreshToken ¶
func (*GoOAuth) RefreshToken ¶
刷新token
func (*GoOAuth) TokenSource ¶
func (c *GoOAuth) TokenSource(ctx context.Context) oauth2.TokenSource
type GoogleUserInfo ¶ added in v1.2.225
type GoogleUserInfo struct { ID string `json:"id"` Email string `json:"email"` VerifiedEmail bool `json:"verified_email"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Picture string `json:"picture"` Locale string `json:"locale"` }
GoogleUserInfo 存储从 Google API 获取的用户信息
func GetUserInfoFromGoogle ¶ added in v1.2.225
func GetUserInfoFromGoogle(accessToken string) (*GoogleUserInfo, error)
func VerifyGoogleToken ¶ added in v1.2.225
type IGoOAuth ¶ added in v1.2.122
type IGoOAuth interface { // 自定义参数 // // param1 := oauth2.SetAuthURLParam("param1", "value1") // param2 := oauth2.SetAuthURLParam("param2", "value2") AuthUrl(opts ...oauth2.AuthCodeOption) string Exchange(ctx context.Context, authorizationCode string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) RefreshToken(ctx context.Context, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) GetToken() *oauth2.Token }
OAuth2.0 授权接口, 支持多种授权方式
Click to show internal directories.
Click to hide internal directories.