Documentation
¶
Index ¶
- Constants
- type IFlowAuth
- func (ia *IFlowAuth) AuthorizationURL(state string, port int) (authURL, redirectURI string)
- 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) RefreshTokens(ctx context.Context, refreshToken string) (*IFlowTokenData, error)
- 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 ¶
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 ¶
NewIFlowAuth constructs a new IFlowAuth with proxy-aware transport.
func (*IFlowAuth) AuthorizationURL ¶
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 ¶
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 ¶
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.