Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
a5275595
Commit
a5275595
authored
Jan 04, 2026
by
shaw
Browse files
fix(test): 修复claude、openai oauth账号test刷新token的bug
parent
678b088a
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/cmd/server/wire_gen.go
View file @
a5275595
...
...
@@ -100,7 +100,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
antigravityTokenProvider
:=
service
.
NewAntigravityTokenProvider
(
accountRepository
,
geminiTokenCache
,
antigravityOAuthService
)
httpUpstream
:=
repository
.
NewHTTPUpstream
(
configConfig
)
antigravityGatewayService
:=
service
.
NewAntigravityGatewayService
(
accountRepository
,
gatewayCache
,
antigravityTokenProvider
,
rateLimitService
,
httpUpstream
)
accountTestService
:=
service
.
NewAccountTestService
(
accountRepository
,
oAuthService
,
openAIOAuthService
,
geminiTokenProvider
,
antigravityGatewayService
,
httpUpstream
)
accountTestService
:=
service
.
NewAccountTestService
(
accountRepository
,
geminiTokenProvider
,
antigravityGatewayService
,
httpUpstream
)
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyService
:=
service
.
ProvideConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
crsSyncService
:=
service
.
NewCRSSyncService
(
accountRepository
,
proxyRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
)
...
...
backend/internal/service/account_test_service.go
View file @
a5275595
...
...
@@ -13,7 +13,6 @@ import (
"net/http"
"regexp"
"strings"
"time"
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
"github.com/Wei-Shaw/sub2api/internal/pkg/geminicli"
...
...
@@ -28,7 +27,6 @@ var sseDataPrefix = regexp.MustCompile(`^data:\s*`)
const
(
testClaudeAPIURL
=
"https://api.anthropic.com/v1/messages"
testOpenAIAPIURL
=
"https://api.openai.com/v1/responses"
chatgptCodexAPIURL
=
"https://chatgpt.com/backend-api/codex/responses"
)
...
...
@@ -44,8 +42,6 @@ type TestEvent struct {
// AccountTestService handles account testing operations
type
AccountTestService
struct
{
accountRepo
AccountRepository
oauthService
*
OAuthService
openaiOAuthService
*
OpenAIOAuthService
geminiTokenProvider
*
GeminiTokenProvider
antigravityGatewayService
*
AntigravityGatewayService
httpUpstream
HTTPUpstream
...
...
@@ -54,16 +50,12 @@ type AccountTestService struct {
// NewAccountTestService creates a new AccountTestService
func
NewAccountTestService
(
accountRepo
AccountRepository
,
oauthService
*
OAuthService
,
openaiOAuthService
*
OpenAIOAuthService
,
geminiTokenProvider
*
GeminiTokenProvider
,
antigravityGatewayService
*
AntigravityGatewayService
,
httpUpstream
HTTPUpstream
,
)
*
AccountTestService
{
return
&
AccountTestService
{
accountRepo
:
accountRepo
,
oauthService
:
oauthService
,
openaiOAuthService
:
openaiOAuthService
,
geminiTokenProvider
:
geminiTokenProvider
,
antigravityGatewayService
:
antigravityGatewayService
,
httpUpstream
:
httpUpstream
,
...
...
@@ -183,22 +175,6 @@ func (s *AccountTestService) testClaudeAccountConnection(c *gin.Context, account
if
authToken
==
""
{
return
s
.
sendErrorAndEnd
(
c
,
"No access token available"
)
}
// Check if token needs refresh
needRefresh
:=
false
if
expiresAt
:=
account
.
GetCredentialAsTime
(
"expires_at"
);
expiresAt
!=
nil
{
if
time
.
Now
()
.
Add
(
5
*
time
.
Minute
)
.
After
(
*
expiresAt
)
{
needRefresh
=
true
}
}
if
needRefresh
&&
s
.
oauthService
!=
nil
{
tokenInfo
,
err
:=
s
.
oauthService
.
RefreshAccountToken
(
ctx
,
account
)
if
err
!=
nil
{
return
s
.
sendErrorAndEnd
(
c
,
fmt
.
Sprintf
(
"Failed to refresh token: %s"
,
err
.
Error
()))
}
authToken
=
tokenInfo
.
AccessToken
}
}
else
if
account
.
Type
==
"apikey"
{
// API Key - use x-api-key header
useBearer
=
false
...
...
@@ -310,15 +286,6 @@ func (s *AccountTestService) testOpenAIAccountConnection(c *gin.Context, account
return
s
.
sendErrorAndEnd
(
c
,
"No access token available"
)
}
// Check if token is expired and refresh if needed
if
account
.
IsOpenAITokenExpired
()
&&
s
.
openaiOAuthService
!=
nil
{
tokenInfo
,
err
:=
s
.
openaiOAuthService
.
RefreshAccountToken
(
ctx
,
account
)
if
err
!=
nil
{
return
s
.
sendErrorAndEnd
(
c
,
fmt
.
Sprintf
(
"Failed to refresh token: %s"
,
err
.
Error
()))
}
authToken
=
tokenInfo
.
AccessToken
}
// OAuth uses ChatGPT internal API
apiURL
=
chatgptCodexAPIURL
chatgptAccountID
=
account
.
GetChatGPTAccountID
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment