auth

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package auth handles QR code login and credential persistence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCredentials

func ClearCredentials(path string) error

ClearCredentials removes stored credentials.

func DefaultCredPath

func DefaultCredPath() string

DefaultCredPath returns ~/.wechatbot/credentials.json

func SaveCredentials

func SaveCredentials(creds *Credentials, path string) error

SaveCredentials persists credentials to disk with 0600 permissions.

Types

type Credentials

type Credentials struct {
	Token     string `json:"token"`
	BaseURL   string `json:"baseUrl"`
	AccountID string `json:"accountId"`
	UserID    string `json:"userId"`
	SavedAt   string `json:"savedAt,omitempty"`
}

Credentials holds bot authentication data.

func LoadCredentials

func LoadCredentials(path string) (*Credentials, error)

LoadCredentials loads stored credentials from disk.

func Login

func Login(ctx context.Context, client *protocol.Client, opts LoginOptions) (*Credentials, error)

Login performs QR code login, returning credentials. If stored credentials exist and Force is false, returns them directly. Handles IDC redirect (scaned_but_redirect), verify codes, already-bound accounts, and limits QR refreshes.

type LoginOptions

type LoginOptions struct {
	BaseURL      string
	CredPath     string
	Force        bool
	OnQRURL      func(url string)
	OnScanned    func()
	OnExpired    func()
	OnVerifyCode func() (string, error)
}

LoginOptions configures the login flow.

Jump to

Keyboard shortcuts

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