chore: drop "oidc_wellknown" tmpl, use json directly (#38731)

`testOAuth2WellKnown` already covers the endpoint's response.
This commit is contained in:
wxiaoguang
2026-08-01 00:32:01 +08:00
committed by GitHub
parent f0a95eebe3
commit 76a787a79d
9 changed files with 81 additions and 90 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ func (b *Base) HTTPError(status int, contents ...string) {
func (b *Base) JSON(status int, content any) {
b.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
b.Resp.WriteHeader(status)
if err := json.NewEncoder(b.Resp).Encode(content); err != nil {
if err := json.MarshalWrite(b.Resp, content); err != nil {
log.Error("Render JSON failed: %v", err)
}
}
-14
View File
@@ -104,20 +104,6 @@ func (ctx *Context) HTML(status int, name templates.TplName) {
}
}
// JSONTemplate renders the template as JSON response
// keep in mind that the template is processed in HTML context, so JSON things should be handled carefully, e.g.: use JSEscape
func (ctx *Context) JSONTemplate(tmpl templates.TplName) {
t, err := ctx.Render.TemplateLookup(string(tmpl), nil)
if err != nil {
ctx.ServerError("unable to find template", err)
return
}
ctx.Resp.Header().Set("Content-Type", "application/json")
if err = t.Execute(ctx.Resp, ctx.Data); err != nil {
ctx.ServerError("unable to execute template", err)
}
}
// RenderToHTML renders the template content to a HTML string
func (ctx *Context) RenderToHTML(name templates.TplName, data any) (template.HTML, error) {
var buf strings.Builder
+4 -4
View File
@@ -360,7 +360,7 @@ func UploadHandler(ctx *context.Context) {
return err
}
} else {
log.Error("Unable to check if LFS OID[%s] stat. Error: %v", p.Oid, err)
log.Error("Unable to check LFS OID[%s] stat. Error: %v", p.Oid, err)
return err
}
_, err = git_model.NewLFSMetaObject(ctx, repository.ID, p)
@@ -378,10 +378,10 @@ func UploadHandler(ctx *context.Context) {
}
// Do not remove the LFS MetaObject here: this request only creates it after the content is verified and stored,
// an invalid request should not remove the existing correct record.
// If two requests are loading (the file is incomplete):
// If two requests are uploading (the file is incomplete):
// * one will keep writing the file content
// * one will fail the verification because it reads an incomplete file, the failure should be just ignore
// In the end, the first one will complete the upload and insert a LFS MetaObject record.
// * one will fail the verification because it reads an incomplete file, the failure should be just be ignored
// In the end, the first one will complete the upload and insert a new LFS MetaObject record.
return
}
+6 -4
View File
@@ -74,16 +74,18 @@ type AccessTokenResponse struct {
IDToken string `json:"id_token,omitempty"`
}
// GrantAdditionalScopes returns valid scopes coming from grant
func GrantAdditionalScopes(grantScopes string) auth.AccessTokenScope {
// scopes_supported from templates/user/auth/oidc_wellknown.tmpl
generalScopesSupported := []string{
func GeneralScopesSupported() []string {
return []string{
"openid",
"profile",
"email",
"groups",
}
}
// GrantAdditionalScopes returns valid scopes coming from grant
func GrantAdditionalScopes(grantScopes string) auth.AccessTokenScope {
generalScopesSupported := GeneralScopesSupported()
var accessScopes []string // the scopes for access control, but not for general information
for scope := range strings.SplitSeq(grantScopes, " ") {
if scope != "" && !slices.Contains(generalScopesSupported, scope) {