mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(iflow): add masked token logs; increase refresh lead to 24h
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
iflowauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/iflow"
|
iflowauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/iflow"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
||||||
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
||||||
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
||||||
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
|
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
|
||||||
@@ -214,18 +215,28 @@ func (e *IFlowExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshToken := ""
|
refreshToken := ""
|
||||||
|
oldAccessToken := ""
|
||||||
if auth.Metadata != nil {
|
if auth.Metadata != nil {
|
||||||
if v, ok := auth.Metadata["refresh_token"].(string); ok {
|
if v, ok := auth.Metadata["refresh_token"].(string); ok {
|
||||||
refreshToken = strings.TrimSpace(v)
|
refreshToken = strings.TrimSpace(v)
|
||||||
}
|
}
|
||||||
|
if v, ok := auth.Metadata["access_token"].(string); ok {
|
||||||
|
oldAccessToken = strings.TrimSpace(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if refreshToken == "" {
|
if refreshToken == "" {
|
||||||
return auth, nil
|
return auth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the old access token (masked) before refresh
|
||||||
|
if oldAccessToken != "" {
|
||||||
|
log.Debugf("iflow executor: refreshing access token, old: %s", util.HideAPIKey(oldAccessToken))
|
||||||
|
}
|
||||||
|
|
||||||
svc := iflowauth.NewIFlowAuth(e.cfg)
|
svc := iflowauth.NewIFlowAuth(e.cfg)
|
||||||
tokenData, err := svc.RefreshTokens(ctx, refreshToken)
|
tokenData, err := svc.RefreshTokens(ctx, refreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("iflow executor: token refresh failed: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +254,9 @@ func (e *IFlowExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*
|
|||||||
auth.Metadata["type"] = "iflow"
|
auth.Metadata["type"] = "iflow"
|
||||||
auth.Metadata["last_refresh"] = time.Now().Format(time.RFC3339)
|
auth.Metadata["last_refresh"] = time.Now().Format(time.RFC3339)
|
||||||
|
|
||||||
|
// Log the new access token (masked) after successful refresh
|
||||||
|
log.Debugf("iflow executor: token refresh successful, new: %s", util.HideAPIKey(tokenData.AccessToken))
|
||||||
|
|
||||||
if auth.Attributes == nil {
|
if auth.Attributes == nil {
|
||||||
auth.Attributes = make(map[string]string)
|
auth.Attributes = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (a *IFlowAuthenticator) Provider() string { return "iflow" }
|
|||||||
|
|
||||||
// RefreshLead indicates how soon before expiry a refresh should be attempted.
|
// RefreshLead indicates how soon before expiry a refresh should be attempted.
|
||||||
func (a *IFlowAuthenticator) RefreshLead() *time.Duration {
|
func (a *IFlowAuthenticator) RefreshLead() *time.Duration {
|
||||||
d := 3 * time.Hour
|
d := 24 * time.Hour
|
||||||
return &d
|
return &d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user