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
0dbea6ca
Commit
0dbea6ca
authored
Feb 24, 2026
by
cagedbird043
Browse files
fix: 修复 Gemini 授权链接生成失败并改进错误提示
parent
7be5e173
Changes
3
Show whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/gemini_oauth_handler.go
View file @
0dbea6ca
...
...
@@ -61,7 +61,11 @@ func (h *GeminiOAuthHandler) GenerateAuthURL(c *gin.Context) {
if
err
!=
nil
{
msg
:=
err
.
Error
()
// Treat missing/invalid OAuth client configuration as a user/config error.
if
strings
.
Contains
(
msg
,
"OAuth client not configured"
)
||
strings
.
Contains
(
msg
,
"requires your own OAuth Client"
)
{
if
strings
.
Contains
(
msg
,
"OAuth client not configured"
)
||
strings
.
Contains
(
msg
,
"requires your own OAuth Client"
)
||
strings
.
Contains
(
msg
,
"requires a custom OAuth Client"
)
||
strings
.
Contains
(
msg
,
"GEMINI_CLI_OAUTH_CLIENT_SECRET_MISSING"
)
||
strings
.
Contains
(
msg
,
"built-in Gemini CLI OAuth client_secret is not configured"
)
{
response
.
BadRequest
(
c
,
"Failed to generate auth URL: "
+
msg
)
return
}
...
...
backend/internal/pkg/geminicli/constants.go
View file @
0dbea6ca
...
...
@@ -39,9 +39,7 @@ const (
// They enable the "login without creating your own OAuth client" experience, but Google may
// restrict which scopes are allowed for this client.
GeminiCLIOAuthClientID
=
"681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
// GeminiCLIOAuthClientSecret is intentionally not embedded in this repository.
// If you rely on the built-in Gemini CLI OAuth client, you MUST provide its client_secret via config/env.
GeminiCLIOAuthClientSecret
=
""
GeminiCLIOAuthClientSecret
=
"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"
// GeminiCLIOAuthClientSecretEnv is the environment variable name for the built-in client secret.
GeminiCLIOAuthClientSecretEnv
=
"GEMINI_CLI_OAUTH_CLIENT_SECRET"
...
...
backend/internal/pkg/geminicli/oauth_test.go
View file @
0dbea6ca
...
...
@@ -685,15 +685,17 @@ func TestEffectiveOAuthConfig_WhitespaceTriming(t *testing.T) {
}
func
TestEffectiveOAuthConfig_NoEnvSecret
(
t
*
testing
.
T
)
{
// 不设置环境变量且不提供凭据,应该报错
t
.
Setenv
(
GeminiCLIOAuthClientSecretEnv
,
""
)
_
,
err
:=
EffectiveOAuthConfig
(
OAuthConfig
{},
"code_assist"
)
if
err
==
nil
{
t
.
Error
(
"没有内置 secret 且未提供凭据时应该报错"
)
cfg
,
err
:=
EffectiveOAuthConfig
(
OAuthConfig
{},
"code_assist"
)
if
err
!=
nil
{
t
.
Fatalf
(
"不设置环境变量时应回退到内置 secret,实际报错: %v"
,
err
)
}
if
strings
.
TrimSpace
(
cfg
.
ClientSecret
)
==
""
{
t
.
Error
(
"ClientSecret 不应为空"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
GeminiCLIOAuthClient
SecretEnv
)
{
t
.
Errorf
(
"
错误消息应提及环境变量 %s
,实际: %
v
"
,
GeminiCLIOAuthClientSecretEnv
,
err
)
if
cfg
.
ClientID
!=
GeminiCLIOAuthClient
ID
{
t
.
Errorf
(
"
ClientID 应回退为内置客户端 ID
,实际: %
q
"
,
cfg
.
ClientID
)
}
}
...
...
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