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