Skip to content

Commit 0044e80

Browse files
zeripath6543lafriks
authored
Add CORS config on to /login/oauth/access_token endpoint (#14850)
Fix #7204 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 59d1cc4 commit 0044e80

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

routers/routes/web.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"gitea.com/go-chi/session"
4848
"github.com/NYTimes/gziphandler"
4949
"github.com/go-chi/chi/middleware"
50+
"github.com/go-chi/cors"
5051
"github.com/prometheus/client_golang/prometheus"
5152
"github.com/tstranex/u2f"
5253
"github.com/unknwon/com"
@@ -389,7 +390,18 @@ func RegisterRoutes(m *web.Route) {
389390
// TODO manage redirection
390391
m.Post("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)
391392
}, ignSignInAndCsrf, reqSignIn)
392-
m.Post("/login/oauth/access_token", bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
393+
if setting.CORSConfig.Enabled {
394+
m.Post("/login/oauth/access_token", cors.Handler(cors.Options{
395+
//Scheme: setting.CORSConfig.Scheme, // FIXME: the cors middleware needs scheme option
396+
AllowedOrigins: setting.CORSConfig.AllowDomain,
397+
//setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
398+
AllowedMethods: setting.CORSConfig.Methods,
399+
AllowCredentials: setting.CORSConfig.AllowCredentials,
400+
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
401+
}), bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
402+
} else {
403+
m.Post("/login/oauth/access_token", bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
404+
}
393405

394406
m.Group("/user/settings", func() {
395407
m.Get("", userSetting.Profile)

0 commit comments

Comments
 (0)