Skip to content

Commit c5dcbc1

Browse files
authored
Merge pull request router-for-me#146 from router-for-me/iflow
feat(iflow): add masked token logs; increase refresh lead to 24h
2 parents 674393e + 4504ba5 commit c5dcbc1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

internal/runtime/executor/iflow_executor.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
iflowauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/iflow"
1414
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
15+
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
1516
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
1617
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
1718
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
@@ -214,18 +215,28 @@ func (e *IFlowExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*
214215
}
215216

216217
refreshToken := ""
218+
oldAccessToken := ""
217219
if auth.Metadata != nil {
218220
if v, ok := auth.Metadata["refresh_token"].(string); ok {
219221
refreshToken = strings.TrimSpace(v)
220222
}
223+
if v, ok := auth.Metadata["access_token"].(string); ok {
224+
oldAccessToken = strings.TrimSpace(v)
225+
}
221226
}
222227
if refreshToken == "" {
223228
return auth, nil
224229
}
225230

231+
// Log the old access token (masked) before refresh
232+
if oldAccessToken != "" {
233+
log.Debugf("iflow executor: refreshing access token, old: %s", util.HideAPIKey(oldAccessToken))
234+
}
235+
226236
svc := iflowauth.NewIFlowAuth(e.cfg)
227237
tokenData, err := svc.RefreshTokens(ctx, refreshToken)
228238
if err != nil {
239+
log.Errorf("iflow executor: token refresh failed: %v", err)
229240
return nil, err
230241
}
231242

@@ -243,6 +254,9 @@ func (e *IFlowExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*
243254
auth.Metadata["type"] = "iflow"
244255
auth.Metadata["last_refresh"] = time.Now().Format(time.RFC3339)
245256

257+
// Log the new access token (masked) after successful refresh
258+
log.Debugf("iflow executor: token refresh successful, new: %s", util.HideAPIKey(tokenData.AccessToken))
259+
246260
if auth.Attributes == nil {
247261
auth.Attributes = make(map[string]string)
248262
}

sdk/auth/iflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (a *IFlowAuthenticator) Provider() string { return "iflow" }
2626

2727
// RefreshLead indicates how soon before expiry a refresh should be attempted.
2828
func (a *IFlowAuthenticator) RefreshLead() *time.Duration {
29-
d := 3 * time.Hour
29+
d := 24 * time.Hour
3030
return &d
3131
}
3232

0 commit comments

Comments
 (0)