From 19ef56845ae77d70312d8c876d39bfe8f1aa1c80 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 22 Nov 2025 10:54:04 +0800 Subject: [PATCH] fix --- routers/web/repo/githttp.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/githttp.go b/routers/web/repo/githttp.go index c6f5f74e4b0ac..c7b53dcbfb1b5 100644 --- a/routers/web/repo/githttp.go +++ b/routers/web/repo/githttp.go @@ -146,7 +146,13 @@ func httpBase(ctx *context.Context) *serviceHandler { // rely on the results of Contexter if !ctx.IsSigned { // TODO: support digit auth - which would be Authorization header with digit - ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`) + if setting.OAuth2.Enabled { + // `Basic realm="Gitea"` tells the GCM to use builtin OAuth2 application: https://github.com/git-ecosystem/git-credential-manager/pull/1442 + ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`) + } else { + // If OAuth2 is disabled, then use another realm to avoid GCM OAuth2 attempt + ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea (Basic Auth)"`) + } ctx.HTTPError(http.StatusUnauthorized) return nil }