oauth

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCodeOption

type AuthCodeOption interface {
	// contains filtered or unexported methods
}

AuthCodeOption 授权码选项

func WithAuthCodeParam

func WithAuthCodeParam(key, value string) AuthCodeOption

WithAuthCodeParam 添加额外的授权参数

type OAuth2Client

type OAuth2Client struct {
	// 客户端ID
	ClientID string

	// 客户端密钥
	ClientSecret string

	// 授权端点
	AuthURL string

	// 令牌端点
	TokenURL string

	// 重定向URL
	RedirectURL string

	// 作用域
	Scopes []string

	// HTTP客户端
	HTTPClient *http.Client
}

OAuth2Client OAuth2客户端

func NewOAuth2Client

func NewOAuth2Client(config *OAuth2Client) *OAuth2Client

NewOAuth2Client 创建新的OAuth2客户端

func (*OAuth2Client) AuthCodeURL

func (c *OAuth2Client) AuthCodeURL(state string, opts ...AuthCodeOption) string

AuthCodeURL 生成授权URL

func (*OAuth2Client) Client

func (c *OAuth2Client) Client(ctx context.Context, token *Token) *http.Client

Client 返回一个配置了令牌的HTTP客户端

func (*OAuth2Client) Exchange

func (c *OAuth2Client) Exchange(ctx context.Context, code string) (*Token, error)

Exchange 使用授权码交换访问令牌

type OAuth2Config

type OAuth2Config interface {
	// AuthCodeURL 生成授权URL
	AuthCodeURL(state string, opts ...AuthCodeOption) string

	// Exchange 使用授权码交换访问令牌
	Exchange(ctx context.Context, code string) (*Token, error)

	// Client 返回一个配置了令牌的HTTP客户端
	Client(ctx context.Context, token *Token) *http.Client
}

OAuth2Config OAuth2配置接口

type Token

type Token struct {
	// 访问令牌
	AccessToken string `json:"access_token"`

	// 令牌类型
	TokenType string `json:"token_type,omitempty"`

	// 刷新令牌
	RefreshToken string `json:"refresh_token,omitempty"`

	// 过期时间
	ExpiresIn int64 `json:"expires_in,omitempty"`

	// 作用域
	Scope string `json:"scope,omitempty"`

	// 原始响应
	Raw interface{} `json:"-"`
}

Token OAuth2令牌

Jump to

Keyboard shortcuts

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