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 IFlowAuth
- func (ia *IFlowAuth) AuthenticateWithCookie(ctx context.Context, cookie string) (*IFlowTokenData, error)
- func (ia *IFlowAuth) AuthorizationURL(state string, port int) (authURL, redirectURI string)
- func (ia *IFlowAuth) CreateCookieTokenStorage(data *IFlowTokenData) *IFlowTokenStorage
- func (ia *IFlowAuth) CreateTokenStorage(data *IFlowTokenData) *IFlowTokenStorage
- func (ia *IFlowAuth) ExchangeCodeForTokens(ctx context.Context, code, redirectURI string) (*IFlowTokenData, error)
- func (ia *IFlowAuth) FetchUserInfo(ctx context.Context, accessToken string) (*userInfoData, error)
- func (ia *IFlowAuth) RefreshAPIKey(ctx context.Context, cookie, name string) (*iFlowKeyData, error)
- func (ia *IFlowAuth) RefreshTokens(ctx context.Context, refreshToken string) (*IFlowTokenData, error)
- func (ia *IFlowAuth) UpdateCookieTokenStorage(storage *IFlowTokenStorage, keyData *iFlowKeyData)
- func (ia *IFlowAuth) UpdateTokenStorage(storage *IFlowTokenStorage, data *IFlowTokenData)
- type IFlowTokenData
- type IFlowTokenResponse
- type IFlowTokenStorage
- type OAuthResult
- type OAuthServer
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.
const SuccessRedirectURL = iFlowSuccessRedirectURL
SuccessRedirectURL is exposed for consumers needing the official success page.
Variables ¶
This section is empty.
Functions ¶
func CheckDuplicateBXAuth ¶ added in v6.6.7
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 ¶ added in v6.6.7
ExtractBXAuth extracts the BXAuth value from a cookie string.
func NormalizeCookie ¶ added in v6.3.58
NormalizeCookie normalizes raw cookie strings for iFlow authentication flows.
func SanitizeIFlowFileName ¶ added in v6.3.58
SanitizeIFlowFileName normalizes user identifiers for safe filename usage.
Types ¶
type IFlowAuth ¶
type IFlowAuth struct {
// contains filtered or unexported fields
}
IFlowAuth encapsulates the HTTP client helpers for the OAuth flow.
func NewIFlowAuth ¶
NewIFlowAuth constructs a new IFlowAuth with proxy-aware transport.
func (*IFlowAuth) AuthenticateWithCookie ¶ added in v6.3.53
func (ia *IFlowAuth) AuthenticateWithCookie(ctx context.Context, cookie string) (*IFlowTokenData, error)
AuthenticateWithCookie performs authentication using browser cookies
func (*IFlowAuth) AuthorizationURL ¶
AuthorizationURL builds the authorization URL and matching redirect URI.
func (*IFlowAuth) CreateCookieTokenStorage ¶ added in v6.3.53
func (ia *IFlowAuth) CreateCookieTokenStorage(data *IFlowTokenData) *IFlowTokenStorage
CreateCookieTokenStorage converts cookie-based token data into persistence storage
func (*IFlowAuth) CreateTokenStorage ¶
func (ia *IFlowAuth) CreateTokenStorage(data *IFlowTokenData) *IFlowTokenStorage
CreateTokenStorage converts token data into persistence storage.
func (*IFlowAuth) ExchangeCodeForTokens ¶
func (ia *IFlowAuth) ExchangeCodeForTokens(ctx context.Context, code, redirectURI string) (*IFlowTokenData, error)
ExchangeCodeForTokens exchanges an authorization code for access and refresh tokens.
func (*IFlowAuth) FetchUserInfo ¶
FetchUserInfo retrieves account metadata (including API key) for the provided access token.
func (*IFlowAuth) RefreshAPIKey ¶ added in v6.3.53
RefreshAPIKey refreshes the API key using POST request
func (*IFlowAuth) RefreshTokens ¶
func (ia *IFlowAuth) RefreshTokens(ctx context.Context, refreshToken string) (*IFlowTokenData, error)
RefreshTokens exchanges a refresh token for a new access token.
func (*IFlowAuth) UpdateCookieTokenStorage ¶ added in v6.3.53
func (ia *IFlowAuth) UpdateCookieTokenStorage(storage *IFlowTokenStorage, keyData *iFlowKeyData)
UpdateCookieTokenStorage updates the persisted token storage with refreshed API key data
func (*IFlowAuth) UpdateTokenStorage ¶
func (ia *IFlowAuth) UpdateTokenStorage(storage *IFlowTokenStorage, data *IFlowTokenData)
UpdateTokenStorage updates the persisted token storage with latest token data.
type IFlowTokenData ¶
type IFlowTokenData struct {
AccessToken string
RefreshToken string
TokenType string
Scope string
Expire string
APIKey string
Email string
Cookie string
}
IFlowTokenData captures processed token details.
type IFlowTokenResponse ¶
type IFlowTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
}
IFlowTokenResponse models the OAuth token endpoint response.
type IFlowTokenStorage ¶
type IFlowTokenStorage 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"`
}
IFlowTokenStorage persists iFlow OAuth credentials alongside the derived API key.
func (*IFlowTokenStorage) SaveTokenToFile ¶
func (ts *IFlowTokenStorage) SaveTokenToFile(authFilePath string) error
SaveTokenToFile serialises the token storage to disk.
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.