Skip to content
/ gitea Public
forked from go-gitea/gitea

Commit 15a475b

Browse files
lunny6543
andauthored
Fix recovery middleware to render gitea style page. (go-gitea#13857)
* Some changes to fix recovery * Move Recovery to middlewares * Remove trace code * Fix lint * add session middleware and remove dependent on macaron for sso * Fix panic 500 page rendering * Fix bugs * Fix fmt * Fix vendor * recover unnecessary change * Fix lint and addd some comments about the copied codes. * Use util.StatDir instead of com.StatDir Co-authored-by: 6543 <6543@obermui.de>
1 parent 126c933 commit 15a475b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+5233
-307
lines changed

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.14
55
require (
66
code.gitea.io/gitea-vet v0.2.1
77
code.gitea.io/sdk/gitea v0.13.1
8+
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27
89
gitea.com/lunny/levelqueue v0.3.0
910
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
1011
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b
@@ -33,7 +34,7 @@ require (
3334
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77
3435
github.com/gliderlabs/ssh v0.3.1
3536
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
36-
github.com/go-chi/chi v1.5.0
37+
github.com/go-chi/chi v1.5.1
3738
github.com/go-enry/go-enry/v2 v2.6.0
3839
github.com/go-git/go-billy/v5 v5.0.0
3940
github.com/go-git/go-git/v5 v5.2.0
@@ -78,7 +79,6 @@ require (
7879
github.com/niklasfasching/go-org v1.3.2
7980
github.com/oliamb/cutter v0.2.2
8081
github.com/olivere/elastic/v7 v7.0.21
81-
github.com/onsi/ginkgo v1.13.0 // indirect
8282
github.com/pelletier/go-toml v1.8.1
8383
github.com/pierrec/lz4/v4 v4.1.1 // indirect
8484
github.com/pkg/errors v0.9.1
@@ -98,6 +98,7 @@ require (
9898
github.com/unknwon/com v1.0.1
9999
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c
100100
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae
101+
github.com/unrolled/render v1.0.3
101102
github.com/urfave/cli v1.22.5
102103
github.com/willf/bitset v1.1.11 // indirect
103104
github.com/xanzy/go-gitlab v0.39.0
@@ -114,7 +115,6 @@ require (
114115
golang.org/x/text v0.3.4
115116
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
116117
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9
117-
google.golang.org/appengine v1.6.7 // indirect
118118
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
119119
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
120120
gopkg.in/ini.v1 v1.62.0

go.sum

+19-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFj
4040
code.gitea.io/sdk/gitea v0.13.1 h1:Y7bpH2iO6Q0KhhMJfjP/LZ0AmiYITeRQlCD8b0oYqhk=
4141
code.gitea.io/sdk/gitea v0.13.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
4242
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
43+
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27 h1:cdb1OTNXGLwQ55gg+9tIPWufdsnrHWcIq8Qs+j/E8JU=
44+
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
4345
gitea.com/lunny/levelqueue v0.3.0 h1:MHn1GuSZkxvVEDMyAPqlc7A3cOW+q8RcGhRgH/xtm6I=
4446
gitea.com/lunny/levelqueue v0.3.0/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
4547
gitea.com/lunny/log v0.0.0-20190322053110-01b5df579c4e h1:r1en/D7xJmcY24VkHkjkcJFa+7ZWubVWPBrvsHkmHxk=
@@ -227,6 +229,8 @@ github.com/couchbase/go-couchbase v0.0.0-20201026062457-7b3be89bbd89/go.mod h1:+
227229
github.com/couchbase/gomemcached v0.0.0-20190515232915-c4b4ca0eb21d/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
228230
github.com/couchbase/gomemcached v0.1.0 h1:whUde87n8CScx8ckMp2En5liqAlcuG3aKy/BQeBPu84=
229231
github.com/couchbase/gomemcached v0.1.0/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
232+
github.com/couchbase/gomemcached v0.1.1 h1:xCS8ZglJDhrlQg3jmK7Rn1V8f7bPjXABLC05CgLQauc=
233+
github.com/couchbase/gomemcached v0.1.1/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
230234
github.com/couchbase/goutils v0.0.0-20190315194238-f9d42b11473b/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
231235
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67 h1:NCqJ6fwen6YP0WlV/IyibaT0kPt3JEI1rA62V/UPKT4=
232236
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
@@ -264,6 +268,7 @@ github.com/denisenkom/go-mssqldb v0.9.0 h1:RSohk2RsiZqLZ0zCjtfn3S4Gp4exhpBWHyQ7D
264268
github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
265269
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
266270
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
271+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
267272
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
268273
github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
269274
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
@@ -283,6 +288,8 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP
283288
github.com/editorconfig/editorconfig-core-go/v2 v2.3.9 h1:4vZN3UCLAUbT408wDutTKGZwOlgGMpV3vhahYufNbV8=
284289
github.com/editorconfig/editorconfig-core-go/v2 v2.3.9/go.mod h1:yoHDFR3nO8O5ssvhITSRsf0owQqIs0c9+nBTtarunPo=
285290
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
291+
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o=
292+
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
286293
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
287294
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
288295
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
@@ -326,8 +333,8 @@ github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 h1:gclg6gY70GLy
326333
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
327334
github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us009o8=
328335
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
329-
github.com/go-chi/chi v1.5.0 h1:2ZcJZozJ+rj6BA0c19ffBUGXEKAT/aOLOtQjD46vBRA=
330-
github.com/go-chi/chi v1.5.0/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
336+
github.com/go-chi/chi v1.5.1 h1:kfTK3Cxd/dkMu/rKs5ZceWYp+t5CtiE7vmaTv3LjC6w=
337+
github.com/go-chi/chi v1.5.1/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
331338
github.com/go-enry/go-enry/v2 v2.6.0 h1:nbGWQBpO+D+cJuRxNgSDFnFY9QWz3QM/CeZxU7VAH20=
332339
github.com/go-enry/go-enry/v2 v2.6.0/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
333340
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
@@ -422,6 +429,7 @@ github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDA
422429
github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
423430
github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4=
424431
github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
432+
github.com/go-redis/redis/v8 v8.4.0/go.mod h1:A1tbYoHSa1fXwN+//ljcCYYJeLmVrwL9hbQN45Jdy0M=
425433
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
426434
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
427435
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
@@ -519,6 +527,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
519527
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
520528
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
521529
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
530+
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
522531
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
523532
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
524533
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
@@ -871,15 +880,17 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
871880
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
872881
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
873882
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
874-
github.com/onsi/ginkgo v1.13.0 h1:M76yO2HkZASFjXL0HSoZJ1AYEmQxNJmY41Jx1zNUq1Y=
875-
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
883+
github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M=
884+
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
876885
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
877886
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
878887
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
879888
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
880889
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
881890
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
882891
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
892+
github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA=
893+
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
883894
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
884895
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
885896
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
@@ -977,7 +988,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
977988
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
978989
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
979990
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
980-
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
981991
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
982992
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
983993
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
@@ -1086,6 +1096,8 @@ github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c h1:679/gJXwrsHC3RATr0
10861096
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
10871097
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae h1:ihaXiJkaca54IaCSnEXtE/uSZOmPxKZhDfVLrzZLFDs=
10881098
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae/go.mod h1:1fdkY6xxl6ExVs2QFv7R0F5IRZHKA8RahhB9fMC9RvM=
1099+
github.com/unrolled/render v1.0.3 h1:baO+NG1bZSF2WR4zwh+0bMWauWky7DVrTOfvE2w+aFo=
1100+
github.com/unrolled/render v1.0.3/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM=
10891101
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
10901102
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
10911103
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
@@ -1142,6 +1154,7 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
11421154
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
11431155
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
11441156
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
1157+
go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw=
11451158
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
11461159
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
11471160
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
@@ -1258,6 +1271,7 @@ golang.org/x/net v0.0.0-20200927032502-5d4f70055728/go.mod h1:/O7V0waA8r7cgGh81R
12581271
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 h1:YfxMZzv3PjGonQYNUaeU2+DhAdqOxerQ30JFB6WgAXo=
12591272
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
12601273
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
1274+
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
12611275
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
12621276
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
12631277
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=

modules/auth/auth.go

-25
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ import (
99
"reflect"
1010
"strings"
1111

12-
"code.gitea.io/gitea/models"
13-
"code.gitea.io/gitea/modules/auth/sso"
1412
"code.gitea.io/gitea/modules/validation"
1513

1614
"gitea.com/macaron/binding"
1715
"gitea.com/macaron/macaron"
18-
"gitea.com/macaron/session"
1916
"github.com/unknwon/com"
2017
)
2118

@@ -24,28 +21,6 @@ func IsAPIPath(url string) bool {
2421
return strings.HasPrefix(url, "/api/")
2522
}
2623

27-
// SignedInUser returns the user object of signed user.
28-
// It returns a bool value to indicate whether user uses basic auth or not.
29-
func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool) {
30-
if !models.HasEngine {
31-
return nil, false
32-
}
33-
34-
// Try to sign in with each of the enabled plugins
35-
for _, ssoMethod := range sso.Methods() {
36-
if !ssoMethod.IsEnabled() {
37-
continue
38-
}
39-
user := ssoMethod.VerifyAuthData(ctx, sess)
40-
if user != nil {
41-
_, isBasic := ssoMethod.(*sso.Basic)
42-
return user, isBasic
43-
}
44-
}
45-
46-
return nil, false
47-
}
48-
4924
// Form form binding interface
5025
type Form interface {
5126
binding.Validator

modules/auth/sso/basic.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
package sso
77

88
import (
9+
"net/http"
910
"strings"
1011

1112
"code.gitea.io/gitea/models"
1213
"code.gitea.io/gitea/modules/base"
1314
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/setting"
1516
"code.gitea.io/gitea/modules/timeutil"
16-
17-
"gitea.com/macaron/macaron"
18-
"gitea.com/macaron/session"
1917
)
2018

2119
// Ensure the struct implements the interface.
@@ -49,8 +47,8 @@ func (b *Basic) IsEnabled() bool {
4947
// "Authorization" header of the request and returns the corresponding user object for that
5048
// name/token on successful validation.
5149
// Returns nil if header is empty or validation fails.
52-
func (b *Basic) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models.User {
53-
baHead := ctx.Req.Header.Get("Authorization")
50+
func (b *Basic) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
51+
baHead := req.Header.Get("Authorization")
5452
if len(baHead) == 0 {
5553
return nil
5654
}
@@ -75,7 +73,7 @@ func (b *Basic) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models
7573
uid := CheckOAuthAccessToken(authToken)
7674
if uid != 0 {
7775
var err error
78-
ctx.Data["IsApiToken"] = true
76+
store.GetData()["IsApiToken"] = true
7977

8078
u, err = models.GetUserByID(uid)
8179
if err != nil {
@@ -108,7 +106,7 @@ func (b *Basic) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models
108106
return nil
109107
}
110108
} else {
111-
ctx.Data["IsApiToken"] = true
109+
store.GetData()["IsApiToken"] = true
112110
}
113111

114112
return u

modules/auth/sso/interface.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
package sso
66

77
import (
8-
"code.gitea.io/gitea/models"
8+
"net/http"
99

10-
"gitea.com/macaron/macaron"
11-
"gitea.com/macaron/session"
10+
"code.gitea.io/gitea/models"
1211
)
1312

13+
// DataStore represents a data store
14+
type DataStore interface {
15+
GetData() map[string]interface{}
16+
}
17+
18+
// SessionStore represents a session store
19+
type SessionStore interface {
20+
Get(interface{}) interface{}
21+
Set(interface{}, interface{}) error
22+
Delete(interface{}) error
23+
}
24+
1425
// SingleSignOn represents a SSO authentication method (plugin) for HTTP requests.
1526
type SingleSignOn interface {
1627
// Init should be called exactly once before using any of the other methods,
@@ -29,5 +40,5 @@ type SingleSignOn interface {
2940
// or a new user object (with id = 0) populated with the information that was found
3041
// in the authentication data (username or email).
3142
// Returns nil if verification fails.
32-
VerifyAuthData(ctx *macaron.Context, sess session.Store) *models.User
43+
VerifyAuthData(http *http.Request, store DataStore, sess SessionStore) *models.User
3344
}

modules/auth/sso/oauth2.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
package sso
77

88
import (
9+
"net/http"
910
"strings"
1011
"time"
1112

1213
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/timeutil"
15-
16-
"gitea.com/macaron/macaron"
17-
"gitea.com/macaron/session"
1816
)
1917

2018
// Ensure the struct implements the interface.
@@ -63,15 +61,15 @@ func (o *OAuth2) Free() error {
6361
}
6462

6563
// userIDFromToken returns the user id corresponding to the OAuth token.
66-
func (o *OAuth2) userIDFromToken(ctx *macaron.Context) int64 {
64+
func (o *OAuth2) userIDFromToken(req *http.Request, store DataStore) int64 {
6765
// Check access token.
68-
tokenSHA := ctx.Query("token")
66+
tokenSHA := req.Form.Get("token")
6967
if len(tokenSHA) == 0 {
70-
tokenSHA = ctx.Query("access_token")
68+
tokenSHA = req.Form.Get("access_token")
7169
}
7270
if len(tokenSHA) == 0 {
7371
// Well, check with header again.
74-
auHead := ctx.Req.Header.Get("Authorization")
72+
auHead := req.Header.Get("Authorization")
7573
if len(auHead) > 0 {
7674
auths := strings.Fields(auHead)
7775
if len(auths) == 2 && (auths[0] == "token" || strings.ToLower(auths[0]) == "bearer") {
@@ -87,7 +85,7 @@ func (o *OAuth2) userIDFromToken(ctx *macaron.Context) int64 {
8785
if strings.Contains(tokenSHA, ".") {
8886
uid := CheckOAuthAccessToken(tokenSHA)
8987
if uid != 0 {
90-
ctx.Data["IsApiToken"] = true
88+
store.GetData()["IsApiToken"] = true
9189
}
9290
return uid
9391
}
@@ -102,7 +100,7 @@ func (o *OAuth2) userIDFromToken(ctx *macaron.Context) int64 {
102100
if err = models.UpdateAccessToken(t); err != nil {
103101
log.Error("UpdateAccessToken: %v", err)
104102
}
105-
ctx.Data["IsApiToken"] = true
103+
store.GetData()["IsApiToken"] = true
106104
return t.UID
107105
}
108106

@@ -116,16 +114,16 @@ func (o *OAuth2) IsEnabled() bool {
116114
// or the "Authorization" header and returns the corresponding user object for that ID.
117115
// If verification is successful returns an existing user object.
118116
// Returns nil if verification fails.
119-
func (o *OAuth2) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models.User {
117+
func (o *OAuth2) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
120118
if !models.HasEngine {
121119
return nil
122120
}
123121

124-
if isInternalPath(ctx) || !isAPIPath(ctx) && !isAttachmentDownload(ctx) {
122+
if isInternalPath(req) || !isAPIPath(req) && !isAttachmentDownload(req) {
125123
return nil
126124
}
127125

128-
id := o.userIDFromToken(ctx)
126+
id := o.userIDFromToken(req, store)
129127
if id <= 0 {
130128
return nil
131129
}

0 commit comments

Comments
 (0)