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
cadd7f54
Unverified
Commit
cadd7f54
authored
Feb 24, 2026
by
Wesley Liddick
Committed by
GitHub
Feb 24, 2026
Browse files
Merge pull request #621 from cagedbird043/fix/gemini-auth-url-613
fix: 修复 Gemini 授权链接生成失败(issue #613)
parents
7be5e173
9bd6a62a
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/gemini_oauth_handler.go
View file @
cadd7f54
...
@@ -61,7 +61,11 @@ func (h *GeminiOAuthHandler) GenerateAuthURL(c *gin.Context) {
...
@@ -61,7 +61,11 @@ func (h *GeminiOAuthHandler) GenerateAuthURL(c *gin.Context) {
if
err
!=
nil
{
if
err
!=
nil
{
msg
:=
err
.
Error
()
msg
:=
err
.
Error
()
// Treat missing/invalid OAuth client configuration as a user/config 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
)
response
.
BadRequest
(
c
,
"Failed to generate auth URL: "
+
msg
)
return
return
}
}
...
...
backend/internal/pkg/geminicli/constants.go
View file @
cadd7f54
...
@@ -38,10 +38,8 @@ const (
...
@@ -38,10 +38,8 @@ const (
// GeminiCLIOAuthClientID/Secret are the public OAuth client credentials used by Google Gemini CLI.
// GeminiCLIOAuthClientID/Secret are the public OAuth client credentials used by Google Gemini CLI.
// They enable the "login without creating your own OAuth client" experience, but Google may
// They enable the "login without creating your own OAuth client" experience, but Google may
// restrict which scopes are allowed for this client.
// restrict which scopes are allowed for this client.
GeminiCLIOAuthClientID
=
"681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
GeminiCLIOAuthClientID
=
"681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
// GeminiCLIOAuthClientSecret is intentionally not embedded in this repository.
GeminiCLIOAuthClientSecret
=
"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"
// If you rely on the built-in Gemini CLI OAuth client, you MUST provide its client_secret via config/env.
GeminiCLIOAuthClientSecret
=
""
// GeminiCLIOAuthClientSecretEnv is the environment variable name for the built-in client secret.
// GeminiCLIOAuthClientSecretEnv is the environment variable name for the built-in client secret.
GeminiCLIOAuthClientSecretEnv
=
"GEMINI_CLI_OAUTH_CLIENT_SECRET"
GeminiCLIOAuthClientSecretEnv
=
"GEMINI_CLI_OAUTH_CLIENT_SECRET"
...
...
backend/internal/pkg/geminicli/oauth_test.go
View file @
cadd7f54
...
@@ -408,11 +408,10 @@ func TestBuildAuthorizationURL_WithProjectID(t *testing.T) {
...
@@ -408,11 +408,10 @@ func TestBuildAuthorizationURL_WithProjectID(t *testing.T) {
}
}
}
}
func
TestBuildAuthorizationURL_OAuthConfigError
(
t
*
testing
.
T
)
{
func
TestBuildAuthorizationURL_UsesBuiltinSecretFallback
(
t
*
testing
.
T
)
{
// 不设置环境变量,也不提供 client 凭据,EffectiveOAuthConfig 应该报错
t
.
Setenv
(
GeminiCLIOAuthClientSecretEnv
,
""
)
t
.
Setenv
(
GeminiCLIOAuthClientSecretEnv
,
""
)
_
,
err
:=
BuildAuthorizationURL
(
authURL
,
err
:=
BuildAuthorizationURL
(
OAuthConfig
{},
OAuthConfig
{},
"test-state"
,
"test-state"
,
"test-challenge"
,
"test-challenge"
,
...
@@ -420,8 +419,11 @@ func TestBuildAuthorizationURL_OAuthConfigError(t *testing.T) {
...
@@ -420,8 +419,11 @@ func TestBuildAuthorizationURL_OAuthConfigError(t *testing.T) {
""
,
""
,
"code_assist"
,
"code_assist"
,
)
)
if
err
==
nil
{
if
err
!=
nil
{
t
.
Error
(
"当 EffectiveOAuthConfig 失败时,BuildAuthorizationURL 应该返回错误"
)
t
.
Fatalf
(
"BuildAuthorizationURL() 不应报错: %v"
,
err
)
}
if
!
strings
.
Contains
(
authURL
,
"client_id="
+
GeminiCLIOAuthClientID
)
{
t
.
Errorf
(
"应使用内置 Gemini CLI client_id,实际 URL: %s"
,
authURL
)
}
}
}
}
...
@@ -685,15 +687,17 @@ func TestEffectiveOAuthConfig_WhitespaceTriming(t *testing.T) {
...
@@ -685,15 +687,17 @@ func TestEffectiveOAuthConfig_WhitespaceTriming(t *testing.T) {
}
}
func
TestEffectiveOAuthConfig_NoEnvSecret
(
t
*
testing
.
T
)
{
func
TestEffectiveOAuthConfig_NoEnvSecret
(
t
*
testing
.
T
)
{
// 不设置环境变量且不提供凭据,应该报错
t
.
Setenv
(
GeminiCLIOAuthClientSecretEnv
,
""
)
t
.
Setenv
(
GeminiCLIOAuthClientSecretEnv
,
""
)
_
,
err
:=
EffectiveOAuthConfig
(
OAuthConfig
{},
"code_assist"
)
cfg
,
err
:=
EffectiveOAuthConfig
(
OAuthConfig
{},
"code_assist"
)
if
err
==
nil
{
if
err
!=
nil
{
t
.
Error
(
"没有内置 secret 且未提供凭据时应该报错"
)
t
.
Fatalf
(
"不设置环境变量时应回退到内置 secret,实际报错: %v"
,
err
)
}
if
strings
.
TrimSpace
(
cfg
.
ClientSecret
)
==
""
{
t
.
Error
(
"ClientSecret 不应为空"
)
}
}
if
!
strings
.
Contains
(
err
.
Error
(),
GeminiCLIOAuthClient
SecretEnv
)
{
if
cfg
.
ClientID
!=
GeminiCLIOAuthClient
ID
{
t
.
Errorf
(
"
错误消息应提及环境变量 %s
,实际: %
v
"
,
GeminiCLIOAuthClientSecretEnv
,
err
)
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