@@ -47,6 +47,7 @@ import (
47
47
"gitea.com/go-chi/session"
48
48
"github.com/NYTimes/gziphandler"
49
49
"github.com/go-chi/chi/middleware"
50
+ "github.com/go-chi/cors"
50
51
"github.com/prometheus/client_golang/prometheus"
51
52
"github.com/tstranex/u2f"
52
53
"github.com/unknwon/com"
@@ -388,7 +389,18 @@ func RegisterRoutes(m *web.Route) {
388
389
// TODO manage redirection
389
390
m .Post ("/authorize" , bindIgnErr (auth.AuthorizationForm {}), user .AuthorizeOAuth )
390
391
}, 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
+ }
392
404
393
405
m .Group ("/user/settings" , func () {
394
406
m .Get ("" , userSetting .Profile )
0 commit comments