From 279473f467f6af558293c2147a08241f8b934eea Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Mar 2025 20:50:39 +0800 Subject: [PATCH] Fix oauth2 auth and UI (#33961) --- routers/web/auth/oauth2_provider.go | 2 +- templates/user/auth/grant.tmpl | 60 ++++++++++++++-------------- templates/user/auth/grant_error.tmpl | 19 ++++----- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 00b5b2db52..ff571fbf2c 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -249,7 +249,7 @@ func AuthorizeOAuth(ctx *context.Context) { }, form.RedirectURI) return } - if err := ctx.Session.Set("CodeChallengeMethod", form.CodeChallenge); err != nil { + if err := ctx.Session.Set("CodeChallenge", form.CodeChallenge); err != nil { handleAuthorizeError(ctx, AuthorizeError{ ErrorCode: ErrorCodeServerError, ErrorDescription: "cannot set code challenge", diff --git a/templates/user/auth/grant.tmpl b/templates/user/auth/grant.tmpl index 7a6f156e36..e56241b0f8 100644 --- a/templates/user/auth/grant.tmpl +++ b/templates/user/auth/grant.tmpl @@ -1,35 +1,33 @@ {{template "base/head" .}} -
-
-
-

- {{ctx.Locale.Tr "auth.authorize_title" .Application.Name}} -

-
- {{template "base/alert" .}} -

- {{if not .AdditionalScopes}} - {{ctx.Locale.Tr "auth.authorize_application_description"}}
- {{end}} - {{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}
- {{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "%s" .Scope)}} -

-
-
-

{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}

-
-
-
- {{.CsrfTokenHtml}} - - - - - - - -
-
+
+
+

+ {{ctx.Locale.Tr "auth.authorize_title" .Application.Name}} +

+
+ {{template "base/alert" .}} +

+ {{if not .AdditionalScopes}} + {{ctx.Locale.Tr "auth.authorize_application_description"}}
+ {{end}} + {{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}
+ {{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "%s" .Scope)}} +

+
+
+

{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}

+
+
+
+ {{.CsrfTokenHtml}} + + + + + + + +
diff --git a/templates/user/auth/grant_error.tmpl b/templates/user/auth/grant_error.tmpl index e37c4f6544..7a4521d331 100644 --- a/templates/user/auth/grant_error.tmpl +++ b/templates/user/auth/grant_error.tmpl @@ -1,15 +1,12 @@ {{template "base/head" .}} -
- {{if .IsRepo}}{{template "repo/header" .}}{{end}} -
-
-

- {{ctx.Locale.Tr "auth.authorization_failed"}} -

-

{{.Error.ErrorDescription}}

-
-

{{ctx.Locale.Tr "auth.authorization_failed_desc"}}

-
+
+
+

+ {{ctx.Locale.Tr "auth.authorization_failed"}} +

+

{{.Error.ErrorDescription}}

+
+

{{ctx.Locale.Tr "auth.authorization_failed_desc"}}