oauth

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OAuth提供商常量
	OAuthGoogle   = "google"
	OAuthApple    = "apple"
	OAuthTelegram = "telegram"
	OAuthGitHub   = "github"
	OAuthFacebook = "facebook"

	// Telegram特殊常量
	TelegramDomain = "npanel.com"
	AuthExpire     = 86400 // 24小时(秒)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppleCallbackParams

type AppleCallbackParams struct {
	Code    string // Authorization code
	IDToken string // ID token
	State   string // State code
}

AppleCallbackParams Apple回调参数

type OAuthParams

type OAuthParams struct {
	Method   string // OAuth提供商: google, apple, telegram, github, facebook
	Redirect string // 登录成功后的重定向URL
}

OAuthParams OAuth登录参数

type OAuthRepo

type OAuthRepo interface {
	// GetOAuthConfig 获取OAuth配置
	GetOAuthConfig(ctx context.Context, method string) (map[string]string, error)

	// SaveStateCode 保存state code到缓存
	SaveStateCode(ctx context.Context, provider, code, redirect string) error

	// GetStateCode 从缓存获取state code
	GetStateCode(ctx context.Context, provider, code string) (string, error)

	// FindUserByOAuth 通过OAuth查找用户
	FindUserByOAuth(ctx context.Context, method, openID string) (int, error)

	// CreateUserWithOAuth 创建OAuth用户
	CreateUserWithOAuth(ctx context.Context, method, openID, email, avatar, ip, userAgent string) (int, error)

	// GenerateJWTToken 生成JWT令牌
	GenerateJWTToken(ctx context.Context, userID int) (string, error)

	// RecordLoginLog 记录登录日志
	RecordLoginLog(ctx context.Context, userID int, method, ip, userAgent string, success bool) error
}

OAuthRepo OAuth数据仓储接口

type OAuthResult

type OAuthResult struct {
	Redirect string // OAuth提供商的授权URL
}

OAuthResult OAuth登录结果

type OAuthTokenParams

type OAuthTokenParams struct {
	Method    string // OAuth提供商
	Callback  string // OAuth回调数据(JSON格式)
	IP        string // 客户端IP
	UserAgent string // 用户代理
}

OAuthTokenParams OAuth获取令牌参数

type OAuthTokenResult

type OAuthTokenResult struct {
	Token string // JWT访问令牌
}

OAuthTokenResult OAuth令牌结果

type OAuthUseCase

type OAuthUseCase interface {
	// OAuthLogin 获取OAuth登录URL
	OAuthLogin(ctx context.Context, params *OAuthParams) (*OAuthResult, error)

	// OAuthLoginGetToken 处理OAuth回调并获取token
	OAuthLoginGetToken(ctx context.Context, params *OAuthTokenParams) (*OAuthTokenResult, error)

	// AppleLoginCallback 处理Apple登录回调
	AppleLoginCallback(ctx context.Context, params *AppleCallbackParams) error
}

OAuthUseCase OAuth业务用例接口

func NewOAuthUseCase

func NewOAuthUseCase(repo OAuthRepo, logger log.Logger) OAuthUseCase

NewOAuthUseCase 创建OAuth业务用例实例

Jump to

Keyboard shortcuts

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