Skip to content

Commit d3f61a3

Browse files
committed
Add CORS config on to /login/oauth/access_token endpoint
Fix go-gitea#7204 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f878c82 commit d3f61a3

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"
@@ -388,7 +389,18 @@ func RegisterRoutes(m *web.Route) {
388389
// TODO manage redirection
389390
m.Post("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)
390391
}, ignSignInAndCsrf, reqSignIn)
391-
m.Post("/login/oauth/access_token", bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
392+
if setting.CORSConfig.Enabled {
393+
m.Post("/login/oauth/access_token", cors.Handler(cors.Options{
394+
//Scheme: setting.CORSConfig.Scheme, // FIXME: the cors middleware needs scheme option
395+
AllowedOrigins: setting.CORSConfig.AllowDomain,
396+
//setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
397+
AllowedMethods: setting.CORSConfig.Methods,
398+
AllowCredentials: setting.CORSConfig.AllowCredentials,
399+
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
400+
}), bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
401+
} else {
402+
m.Post("/login/oauth/access_token", bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
403+
}
392404

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

0 commit comments

Comments
 (0)