Documentation
¶
Index ¶
- Constants
- func CheckDuplicateBXAuth(authDir, bxAuth string) (string, error)
- func ExtractBXAuth(cookie string) string
- func NormalizeCookie(raw string) (string, error)
- func SanitizeIFlowFileName(raw string) string
- func ShouldRefreshAPIKey(expireTime string) (bool, time.Duration, error)
- type Auth
- func (ia *Auth) AuthenticateWithCookie(ctx context.Context, cookie string) (*TokenData, error)
- func (ia *Auth) AuthorizationURL(state string, port int) (authURL, redirectURI string)
- func (ia *Auth) CreateCookieTokenStorage(data *TokenData) *TokenStorage
- func (ia *Auth) CreateTokenStorage(data *TokenData) *TokenStorage
- func (ia *Auth) ExchangeCodeForTokens(ctx context.Context, code, redirectURI string) (*TokenData, error)
- func (ia *Auth) RefreshAPIKey(ctx context.Context, cookie, name string) (*KeyData, error)
- func (ia *Auth) RefreshTokens(ctx context.Context, refreshToken string) (*TokenData, error)
- func (ia *Auth) UpdateCookieTokenStorage(storage *TokenStorage, KeyData *KeyData)
- func (ia *Auth) UpdateTokenStorage(storage *TokenStorage, data *TokenData)
- type KeyData
- type OAuthResult
- type OAuthServer
- type TokenData
- type TokenStorage
Constants ¶
const CallbackPort = 11451
CallbackPort defines the local port used for OAuth callbacks.
const DefaultAPIBaseURL = "https://apis.iflow.cn/v1"
DefaultAPIBaseURL is the canonical chat completions endpoint.
Variables ¶
This section is empty.
Functions ¶
func CheckDuplicateBXAuth ¶
CheckDuplicateBXAuth checks if the given BXAuth value already exists in any iflow auth file. Returns the path of the existing file if found, empty string otherwise.
func ExtractBXAuth ¶
ExtractBXAuth extracts the BXAuth value from a cookie string.
func NormalizeCookie ¶
NormalizeCookie normalizes raw cookie strings for iFlow authentication flows.
func SanitizeIFlowFileName ¶
SanitizeIFlowFileName normalizes user identifiers for safe filename usage.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth encapsulates the HTTP client helpers for the OAuth flow.
func (*Auth) AuthenticateWithCookie ¶
AuthenticateWithCookie performs authentication using browser cookies
func (*Auth) AuthorizationURL ¶
AuthorizationURL builds the authorization URL and matching redirect URI.
func (*Auth) CreateCookieTokenStorage ¶
func (ia *Auth) CreateCookieTokenStorage(data *TokenData) *TokenStorage
CreateCookieTokenStorage converts cookie-based token data into persistence storage
func (*Auth) CreateTokenStorage ¶
func (ia *Auth) CreateTokenStorage(data *TokenData) *TokenStorage
CreateTokenStorage converts token data into persistence storage.
func (*Auth) ExchangeCodeForTokens ¶
func (ia *Auth) ExchangeCodeForTokens(ctx context.Context, code, redirectURI string) (*TokenData, error)
ExchangeCodeForTokens exchanges an authorization code for access and refresh tokens.
func (*Auth) RefreshAPIKey ¶
RefreshAPIKey refreshes the API key using POST request
func (*Auth) RefreshTokens ¶
RefreshTokens exchanges a refresh token for a new access token.
func (*Auth) UpdateCookieTokenStorage ¶
func (ia *Auth) UpdateCookieTokenStorage(storage *TokenStorage, KeyData *KeyData)
UpdateCookieTokenStorage updates the persisted token storage with refreshed API key data.
func (*Auth) UpdateTokenStorage ¶
func (ia *Auth) UpdateTokenStorage(storage *TokenStorage, data *TokenData)
UpdateTokenStorage updates the persisted token storage with latest token data.
type KeyData ¶
type KeyData struct {
HasExpired bool `json:"hasExpired"`
ExpireTime string `json:"expireTime"`
Name string `json:"name"`
APIKey string `json:"apiKey"`
APIKeyMask string `json:"apiKeyMask"`
}
KeyData contains the API key information
type OAuthResult ¶
OAuthResult captures the outcome of the local OAuth callback.
type OAuthServer ¶
type OAuthServer struct {
// contains filtered or unexported fields
}
OAuthServer provides a minimal HTTP server for handling the iFlow OAuth callback.
func NewOAuthServer ¶
func NewOAuthServer(port int) *OAuthServer
NewOAuthServer constructs a new OAuthServer bound to the provided port.
func (*OAuthServer) Start ¶
func (s *OAuthServer) Start() error
Start launches the callback listener.
func (*OAuthServer) Stop ¶
func (s *OAuthServer) Stop(ctx context.Context) error
Stop gracefully terminates the callback listener.
func (*OAuthServer) WaitForCallback ¶
func (s *OAuthServer) WaitForCallback(timeout time.Duration) (*OAuthResult, error)
WaitForCallback blocks until a callback result, server error, or timeout occurs.
type TokenData ¶
type TokenData struct {
AccessToken string
RefreshToken string
TokenType string
Scope string
Expire string
APIKey string
Email string
Cookie string
}
TokenData captures processed token details.
type TokenStorage ¶
type TokenStorage struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
LastRefresh string `json:"last_refresh"`
Expire string `json:"expired"`
APIKey string `json:"api_key"`
Email string `json:"email"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
Cookie string `json:"cookie"`
Type string `json:"type"`
// Metadata holds arbitrary key-value pairs injected via hooks.
// It is not exported to JSON directly to allow flattening during serialization.
Metadata map[string]any `json:"-"`
}
TokenStorage persists iFlow OAuth credentials alongside the derived API key.
func (*TokenStorage) SaveTokenToFile ¶
func (ts *TokenStorage) SaveTokenToFile(authFilePath string) error
SaveTokenToFile serialises the token storage to disk.
func (*TokenStorage) SetMetadata ¶
func (ts *TokenStorage) SetMetadata(meta map[string]any)
SetMetadata allows external callers to inject metadata into the storage before saving.