iflow

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 17 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

This section is empty.

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) AuthorizationURL

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

AuthorizationURL builds the authorization URL and matching redirect URI.

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) RefreshTokens

func (ia *IFlowAuth) RefreshTokens(ctx context.Context, refreshToken string) (*IFlowTokenData, error)

RefreshTokens exchanges a refresh token for a new access token.

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
}

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"`
	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