iflow

package
v6.3.55 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CallbackPort = 11451

CallbackPort defines the local port used for OAuth callbacks.

View Source
const DefaultAPIBaseURL = "https://apis.iflow.cn/v1"

DefaultAPIBaseURL is the canonical chat completions endpoint.

View Source
const SuccessRedirectURL = iFlowSuccessRedirectURL

SuccessRedirectURL is exposed for consumers needing the official success page.

Variables

This section is empty.

Functions

func ShouldRefreshAPIKey added in v6.3.53

func ShouldRefreshAPIKey(expireTime string) (bool, time.Duration, error)

ShouldRefreshAPIKey checks if the API key needs to be refreshed (within 2 days of expiry)

Types

type IFlowAuth

type IFlowAuth struct {
	// contains filtered or unexported fields
}

IFlowAuth encapsulates the HTTP client helpers for the OAuth flow.

func NewIFlowAuth

func NewIFlowAuth(cfg *config.Config) *IFlowAuth

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

func (ia *IFlowAuth) AuthorizationURL(state string, port int) (authURL, redirectURI string)

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

func (ia *IFlowAuth) FetchUserInfo(ctx context.Context, accessToken string) (*userInfoData, error)

FetchUserInfo retrieves account metadata (including API key) for the provided access token.

func (*IFlowAuth) RefreshAPIKey added in v6.3.53

func (ia *IFlowAuth) RefreshAPIKey(ctx context.Context, cookie, name string) (*iFlowKeyData, error)

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

type OAuthResult struct {
	Code  string
	State string
	Error string
}

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.

Jump to

Keyboard shortcuts

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