@@ -324,6 +324,13 @@ func registerRoutes(m *web.Router) {
324
324
}
325
325
}
326
326
327
+ oauth2Enabled := func (ctx * context.Context ) {
328
+ if ! setting .OAuth2 .Enabled {
329
+ ctx .Error (http .StatusForbidden )
330
+ return
331
+ }
332
+ }
333
+
327
334
reqMilestonesDashboardPageEnabled := func (ctx * context.Context ) {
328
335
if ! setting .Service .ShowMilestonesDashboardPage {
329
336
ctx .Error (http .StatusForbidden )
@@ -546,16 +553,18 @@ func registerRoutes(m *web.Router) {
546
553
m .Any ("/user/events" , routing .MarkLongPolling , events .Events )
547
554
548
555
m .Group ("/login/oauth" , func () {
549
- m .Get ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
550
- m .Post ("/grant" , web .Bind (forms.GrantApplicationForm {}), auth .GrantApplicationOAuth )
551
- // TODO manage redirection
552
- m .Post ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
553
- }, ignSignInAndCsrf , reqSignIn )
554
-
555
- m .Methods ("GET, OPTIONS" , "/login/oauth/userinfo" , optionsCorsHandler (), ignSignInAndCsrf , auth .InfoOAuth )
556
- m .Methods ("POST, OPTIONS" , "/login/oauth/access_token" , optionsCorsHandler (), web .Bind (forms.AccessTokenForm {}), ignSignInAndCsrf , auth .AccessTokenOAuth )
557
- m .Methods ("GET, OPTIONS" , "/login/oauth/keys" , optionsCorsHandler (), ignSignInAndCsrf , auth .OIDCKeys )
558
- m .Methods ("POST, OPTIONS" , "/login/oauth/introspect" , optionsCorsHandler (), web .Bind (forms.IntrospectTokenForm {}), ignSignInAndCsrf , auth .IntrospectOAuth )
556
+ m .Group ("" , func () {
557
+ m .Get ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
558
+ m .Post ("/grant" , web .Bind (forms.GrantApplicationForm {}), auth .GrantApplicationOAuth )
559
+ // TODO manage redirection
560
+ m .Post ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
561
+ }, ignSignInAndCsrf , reqSignIn )
562
+
563
+ m .Methods ("GET, OPTIONS" , "/userinfo" , optionsCorsHandler (), ignSignInAndCsrf , auth .InfoOAuth )
564
+ m .Methods ("POST, OPTIONS" , "/access_token" , optionsCorsHandler (), web .Bind (forms.AccessTokenForm {}), ignSignInAndCsrf , auth .AccessTokenOAuth )
565
+ m .Methods ("GET, OPTIONS" , "/keys" , optionsCorsHandler (), ignSignInAndCsrf , auth .OIDCKeys )
566
+ m .Methods ("POST, OPTIONS" , "/introspect" , optionsCorsHandler (), web .Bind (forms.IntrospectTokenForm {}), ignSignInAndCsrf , auth .IntrospectOAuth )
567
+ }, oauth2Enabled )
559
568
560
569
m .Group ("/user/settings" , func () {
561
570
m .Get ("" , user_setting .Profile )
@@ -596,17 +605,24 @@ func registerRoutes(m *web.Router) {
596
605
}, openIDSignInEnabled )
597
606
m .Post ("/account_link" , linkAccountEnabled , security .DeleteAccountLink )
598
607
})
599
- m .Group ("/applications/oauth2" , func () {
600
- m .Get ("/{id}" , user_setting .OAuth2ApplicationShow )
601
- m .Post ("/{id}" , web .Bind (forms.EditOAuth2ApplicationForm {}), user_setting .OAuthApplicationsEdit )
602
- m .Post ("/{id}/regenerate_secret" , user_setting .OAuthApplicationsRegenerateSecret )
603
- m .Post ("" , web .Bind (forms.EditOAuth2ApplicationForm {}), user_setting .OAuthApplicationsPost )
604
- m .Post ("/{id}/delete" , user_setting .DeleteOAuth2Application )
605
- m .Post ("/{id}/revoke/{grantId}" , user_setting .RevokeOAuth2Grant )
608
+
609
+ m .Group ("/applications" , func () {
610
+ // oauth2 applications
611
+ m .Group ("/oauth2" , func () {
612
+ m .Get ("/{id}" , user_setting .OAuth2ApplicationShow )
613
+ m .Post ("/{id}" , web .Bind (forms.EditOAuth2ApplicationForm {}), user_setting .OAuthApplicationsEdit )
614
+ m .Post ("/{id}/regenerate_secret" , user_setting .OAuthApplicationsRegenerateSecret )
615
+ m .Post ("" , web .Bind (forms.EditOAuth2ApplicationForm {}), user_setting .OAuthApplicationsPost )
616
+ m .Post ("/{id}/delete" , user_setting .DeleteOAuth2Application )
617
+ m .Post ("/{id}/revoke/{grantId}" , user_setting .RevokeOAuth2Grant )
618
+ }, oauth2Enabled )
619
+
620
+ // access token applications
621
+ m .Combo ("" ).Get (user_setting .Applications ).
622
+ Post (web .Bind (forms.NewAccessTokenForm {}), user_setting .ApplicationsPost )
623
+ m .Post ("/delete" , user_setting .DeleteApplication )
606
624
})
607
- m .Combo ("/applications" ).Get (user_setting .Applications ).
608
- Post (web .Bind (forms.NewAccessTokenForm {}), user_setting .ApplicationsPost )
609
- m .Post ("/applications/delete" , user_setting .DeleteApplication )
625
+
610
626
m .Combo ("/keys" ).Get (user_setting .Keys ).
611
627
Post (web .Bind (forms.AddKeyForm {}), user_setting .KeysPost )
612
628
m .Post ("/keys/delete" , user_setting .DeleteKey )
@@ -780,12 +796,7 @@ func registerRoutes(m *web.Router) {
780
796
m .Post ("/regenerate_secret" , admin .ApplicationsRegenerateSecret )
781
797
m .Post ("/delete" , admin .DeleteApplication )
782
798
})
783
- }, func (ctx * context.Context ) {
784
- if ! setting .OAuth2 .Enabled {
785
- ctx .Error (http .StatusForbidden )
786
- return
787
- }
788
- })
799
+ }, oauth2Enabled )
789
800
790
801
m .Group ("/actions" , func () {
791
802
m .Get ("" , admin .RedirectToDefaultSetting )
@@ -909,12 +920,7 @@ func registerRoutes(m *web.Router) {
909
920
m .Post ("/regenerate_secret" , org .OAuthApplicationsRegenerateSecret )
910
921
m .Post ("/delete" , org .DeleteOAuth2Application )
911
922
})
912
- }, func (ctx * context.Context ) {
913
- if ! setting .OAuth2 .Enabled {
914
- ctx .Error (http .StatusForbidden )
915
- return
916
- }
917
- })
923
+ }, oauth2Enabled )
918
924
919
925
m .Group ("/hooks" , func () {
920
926
m .Get ("" , org .Webhooks )
0 commit comments