From 69a484228af8f9838ef7802dfbb27370bd061049 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Mon, 26 Aug 2024 09:35:25 +0530 Subject: [PATCH 01/20] Updates Login and Registration Flow --- go.mod | 58 ++- go.sum | 492 +++--------------- pkg/wrapper/kratos/login/login.go | 31 +- .../kratos/registration/registration.go | 13 +- 4 files changed, 111 insertions(+), 483 deletions(-) diff --git a/go.mod b/go.mod index 2ee5374..2ad17d6 100644 --- a/go.mod +++ b/go.mod @@ -1,41 +1,45 @@ module github.com/sdslabs/nymeria -go 1.18 +go 1.23 require ( - github.com/gin-contrib/cors v1.4.0 - github.com/gin-gonic/gin v1.8.1 - github.com/lib/pq v1.10.7 - github.com/ory/client-go v0.2.0-alpha.60 - github.com/sirupsen/logrus v1.9.0 + github.com/gin-contrib/cors v1.7.2 + github.com/gin-gonic/gin v1.10.0 + github.com/lib/pq v1.10.9 + github.com/ory/client-go v1.14.3 + github.com/sirupsen/logrus v1.9.3 gopkg.in/yaml.v2 v2.4.0 ) -require ( - github.com/google/go-cmp v0.5.9 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect - github.com/stretchr/testify v1.8.1 // indirect -) +require github.com/rogpeppe/go-internal v1.12.0 // indirect require ( + github.com/bytedance/sonic v1.12.1 // indirect + github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.5 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-playground/locales v0.14.0 // indirect - github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/go-playground/validator/v10 v10.11.0 // indirect - github.com/goccy/go-json v0.9.7 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.22.0 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.5 // indirect - github.com/ugorji/go/codec v1.2.7 // indirect - golang.org/x/crypto v0.1.0 // indirect - golang.org/x/net v0.3.0 // indirect - golang.org/x/oauth2 v0.3.0 // indirect - golang.org/x/sys v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.9.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e75d0f4..440ab2d 100644 --- a/go.sum +++ b/go.sum @@ -1,465 +1,105 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/bytedance/sonic v1.12.1 h1:jWl5Qz1fy7X1ioY74WqO0KjAMtAGQs4sYnjiEBiyX24= +github.com/bytedance/sonic v1.12.1/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= +github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= -github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= +github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= +github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= +github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= +github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= -github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= -github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw= -github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= -github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao= +github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= +github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/ory/client-go v0.2.0-alpha.60 h1:sMAqrKP5eUNYyyOYbSjDTwr8EucDxYLGrQC093ZX5pU= -github.com/ory/client-go v0.2.0-alpha.60/go.mod h1:dWbi9DBEjiDXwyuJ1+A2WT1/bIp9HwvVxZxzHzp4YHU= -github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= -github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= -github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/ory/client-go v1.14.3 h1:jNMzO0kNgSvemeN5miWgVm+F+DtrqR71PAUR0jVQajY= +github.com/ory/client-go v1.14.3/go.mod h1:GSRIUSsTcnMnRnj2Dd0fLc1XQ4juvkrA3aQW0gWlqtk= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= -github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= -golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk= -golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8= -golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.9.0 h1:ub9TgUInamJ8mrZIGlBG6/4TqWeMszd4N8lNorbrr6k= +golang.org/x/arch v0.9.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= -golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= diff --git a/pkg/wrapper/kratos/login/login.go b/pkg/wrapper/kratos/login/login.go index d3b9775..930cb24 100644 --- a/pkg/wrapper/kratos/login/login.go +++ b/pkg/wrapper/kratos/login/login.go @@ -9,12 +9,12 @@ import ( ) func InitializeLoginFlowWrapper(aal string, cookie string) (string, string, string, error) { - refresh := false // bool | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. (optional) - returnTo := "" // string | The URL to return the browser to after the flow was completed. (optional) + refresh := false // bool | Refresh a login session If set to true, this will refresh an existing login session by asking the user to sign in again. This will reset the authenticated_at time of the session. (optional) + returnTo := "" // string | The URL to return the browser to after the flow was completed. (optional) apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, r, err := apiClient.V0alpha2Api.InitializeSelfServiceLoginFlowForBrowsers(context.Background()).Refresh(refresh).Aal(aal).ReturnTo(returnTo).Cookie(cookie).Execute() + resp, r, err := apiClient.FrontendAPI.CreateBrowserLoginFlow(context.Background()).Refresh(refresh).Aal(aal).ReturnTo(returnTo).Cookie(cookie).Execute() if err != nil { return "", "", "", err @@ -35,35 +35,18 @@ func InitializeLoginFlowWrapper(aal string, cookie string) (string, string, stri } func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass string, identifier string) (client.Session, string, error) { - submitDataBody := client.SubmitSelfServiceLoginFlowBody{SubmitSelfServiceLoginFlowWithPasswordMethodBody: client.NewSubmitSelfServiceLoginFlowWithPasswordMethodBody(identifier, "password", pass)} // SubmitSelfServiceLoginFlowBody | - submitDataBody.SubmitSelfServiceLoginFlowWithPasswordMethodBody.SetCsrfToken(csrfToken) + submitDataBody := client.UpdateLoginFlowBody{UpdateLoginFlowWithPasswordMethod: client.NewUpdateLoginFlowWithPasswordMethod(identifier, "password", pass)} // SubmitSelfServiceLoginFlowBody | + submitDataBody.UpdateLoginFlowWithPasswordMethod.SetCsrfToken(csrfToken) apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, r, err := apiClient.V0alpha2Api.SubmitSelfServiceLoginFlow(context.Background()).Flow(flowID).SubmitSelfServiceLoginFlowBody(submitDataBody).XSessionToken("").Cookie(cookie).Execute() - if err != nil { - return *client.NewSessionWithDefaults(), "", err - } - - responseCookies := r.Header["Set-Cookie"] - - return resp.Session, responseCookies[1], nil -} - -func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, totp string) (client.Session, string, error) { - submitDataBody := client.SubmitSelfServiceLoginFlowBody{SubmitSelfServiceLoginFlowWithTotpMethodBody: client.NewSubmitSelfServiceLoginFlowWithTotpMethodBody("totp", totp)} // SubmitSelfServiceLoginFlowBody | - - submitDataBody.SubmitSelfServiceLoginFlowWithTotpMethodBody.SetCsrfToken(csrfToken) - - apiClient := client.NewAPIClient(config.KratosClientConfig) - - resp, r, err := apiClient.V0alpha2Api.SubmitSelfServiceLoginFlow(context.Background()).Flow(flowID).SubmitSelfServiceLoginFlowBody(submitDataBody).XSessionToken("").Cookie(cookie).Execute() + resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Cookie(cookie).Flow(flowID).XSessionToken("").UpdateLoginFlowBody(submitDataBody).Execute() if err != nil { return *client.NewSessionWithDefaults(), "", err } responseCookies := r.Header["Set-Cookie"] - return resp.Session, responseCookies[0], nil + return resp.Session, responseCookies[1], nil } diff --git a/pkg/wrapper/kratos/registration/registration.go b/pkg/wrapper/kratos/registration/registration.go index 387308d..67ba128 100644 --- a/pkg/wrapper/kratos/registration/registration.go +++ b/pkg/wrapper/kratos/registration/registration.go @@ -15,7 +15,8 @@ func InitializeRegistrationFlowWrapper() (string, string, string, error) { returnTo := "" apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, r, err := apiClient.V0alpha2Api.InitializeSelfServiceRegistrationFlowForBrowsers(context.Background()).ReturnTo(returnTo).Execute() + + resp, r, err := apiClient.FrontendAPI.CreateBrowserRegistrationFlow(context.Background()).ReturnTo(returnTo).Execute() if err != nil { return "", "", "", err } @@ -48,14 +49,14 @@ func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken strin "totp_enabled": false, } - submitDataBody := client.SubmitSelfServiceRegistrationFlowBody{ - SubmitSelfServiceRegistrationFlowWithPasswordMethodBody: client.NewSubmitSelfServiceRegistrationFlowWithPasswordMethodBody("password", password, trait), - } + submitDataBody := client.UpdateRegistrationFlowBody{UpdateRegistrationFlowWithPasswordMethod: client.NewUpdateRegistrationFlowWithPasswordMethod("password", password, trait)} - submitDataBody.SubmitSelfServiceRegistrationFlowWithPasswordMethodBody.SetCsrfToken(csrfToken) + submitDataBody.UpdateRegistrationFlowWithPasswordMethod.SetCsrfToken(csrfToken) apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceRegistrationFlow(context.Background()).Flow(flowID).SubmitSelfServiceRegistrationFlowBody(submitDataBody).Cookie(cookie).Execute() + + _, r, err := apiClient.FrontendAPI.UpdateRegistrationFlow(context.Background()).Flow(flowID).UpdateRegistrationFlowBody(submitDataBody).Cookie(cookie).Execute() + if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRegistrationFlow``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) From 1d7c8947c8e5ac8e01aaaf8d63829debf23866ce Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Mon, 26 Aug 2024 10:24:24 +0530 Subject: [PATCH 02/20] Updates all routes except Admin routes --- api/admin.go | 548 +++++++++--------- api/main.go | 14 +- api/status.go | 2 +- pkg/middleware/rolecheck.go | 2 +- pkg/middleware/session.go | 2 +- pkg/wrapper/kratos/admin/admin.go | 142 ++--- pkg/wrapper/kratos/login/login.go | 18 + pkg/wrapper/kratos/logout/logout.go | 21 +- pkg/wrapper/kratos/recovery/recovery.go | 10 +- pkg/wrapper/kratos/settings/settings.go | 34 +- .../kratos/verification/verification.go | 10 +- 11 files changed, 404 insertions(+), 399 deletions(-) diff --git a/api/admin.go b/api/admin.go index 4d41164..7bbc134 100644 --- a/api/admin.go +++ b/api/admin.go @@ -1,276 +1,276 @@ package api -import ( - "encoding/json" - "fmt" - "net/http" - "os" - "strconv" - "strings" - - "github.com/gin-gonic/gin" - - "github.com/sdslabs/nymeria/log" - "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" -) - -func HandleCreateIdentityFlow(c *gin.Context) { - - var t admin.Identity - - err := c.BindJSON(&t) - - if err != nil { - log.ErrorLogger("Unable to process JSON body", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process JSON body", - }) - return - } - - if err != nil { - log.ErrorLogger("Unable to convert JSON to map", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to convert JSON to map", - }) - return - } - - createdIdentity, r, err := admin.CreateIdentityFlowWrapper(t) - - if err != nil { - log.ErrorLogger("Error while calling `AdminCreateIdentity`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "identity": createdIdentity.Id, - }) -} - -func HandleGetIdentityFlow(c *gin.Context) { - createdIdentity := c.Query("identity") - getIdentity, r, err := admin.GetIdentityFlowWrapper(createdIdentity) - - if err != nil { - log.ErrorLogger("Error while calling `AdminGetIdentity`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - return - } - - jsonString, err := json.Marshal(getIdentity.Traits) - - if err != nil { - log.ErrorLogger("Unable to convert map to json", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to convert map to json", - }) - return - } - - var identity admin.Identity - - err = json.Unmarshal(jsonString, &identity) - - if err != nil { - log.ErrorLogger("Unable to convert JSON to map", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to convert JSON to map", - }) - return - } - - fmt.Fprintf(os.Stdout, "Identity details for id %v. Traits: %v\n", createdIdentity, identity) - c.JSON(http.StatusOK, gin.H{ - "Identity": createdIdentity, - "Traits": identity, - }) -} - -func HandleDeleteIdentityFlow(c *gin.Context) { - - var t IdentityBody - err := c.BindJSON(&t) - - if err != nil { - log.ErrorLogger("Unable to process JSON body", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process JSON body", - }) - return - } - - r, err := admin.DeleteIdentityFlowWrapper(t.Identity) - - if err != nil { - log.ErrorLogger("Error while calling `AdminDeleteIdentity`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "INternal server error", - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "message": "removed identity", - }) -} - -func HandleListIdentity(c *gin.Context) { - identities, r, err := admin.ListIdentityFlowWrapper() - if err != nil { - log.ErrorLogger("Error while calling `AdminListIdentities`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - - return - } - c.JSON(http.StatusOK, gin.H{ - "identities": identities, - }) -} - -func HandleBanIdentity(c *gin.Context) { - var t IdentityBody - err := c.BindJSON(&t) - - if err != nil { - log.ErrorLogger("Unable to process JSON body", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process JSON body", - }) - return - } - - identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - - if err != nil { - log.ErrorLogger("Error while fetching Identity details", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - return - } - - id, r, err := admin.BanIdentityFlowWrapper(identityResult) - - if err != nil { - log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": err.Error(), - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "identity": id, - }) -} - -func HandleRemoveBanIdentity(c *gin.Context) { - var t IdentityBody - err := c.BindJSON(&t) - - if err != nil { - log.ErrorLogger("Unable to process JSON body", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process JSON body", - }) - return - } - - identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - - if err != nil { - log.ErrorLogger("Error while fetching Identity details", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - return - } - - id, r, err := admin.RemoveBanIdentityFlowWrapper(identityResult) - - if err != nil { - log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": err.Error(), - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "identity": id, - }) -} - -func HandleRoleSwitch(c *gin.Context) { - var t IdentityBody - err := c.BindJSON(&t) - - if err != nil { - log.ErrorLogger("Unable to process JSON body", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process JSON body", - }) - return - } - - identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - - if err != nil { - log.ErrorLogger("Error while fetching Identity details", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Internal server error", - }) - return - } - - id, r, err := admin.RoleSwitchFlowWrapper(identityResult) - - if err != nil { - log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": err.Error(), - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "identity": id, - }) -} +// import ( +// "encoding/json" +// "fmt" +// "net/http" +// "os" +// "strconv" +// "strings" + +// "github.com/gin-gonic/gin" + +// "github.com/sdslabs/nymeria/log" +// "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" +// ) + +// func HandleCreateIdentityFlow(c *gin.Context) { + +// var t admin.Identity + +// err := c.BindJSON(&t) + +// if err != nil { +// log.ErrorLogger("Unable to process JSON body", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to process JSON body", +// }) +// return +// } + +// if err != nil { +// log.ErrorLogger("Unable to convert JSON to map", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to convert JSON to map", +// }) +// return +// } + +// createdIdentity, r, err := admin.CreateIdentityFlowWrapper(t) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminCreateIdentity`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "identity": createdIdentity.Id, +// }) +// } + +// func HandleGetIdentityFlow(c *gin.Context) { +// createdIdentity := c.Query("identity") +// getIdentity, r, err := admin.GetIdentityFlowWrapper(createdIdentity) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminGetIdentity`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) +// return +// } + +// jsonString, err := json.Marshal(getIdentity.Traits) + +// if err != nil { +// log.ErrorLogger("Unable to convert map to json", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to convert map to json", +// }) +// return +// } + +// var identity admin.Identity + +// err = json.Unmarshal(jsonString, &identity) + +// if err != nil { +// log.ErrorLogger("Unable to convert JSON to map", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to convert JSON to map", +// }) +// return +// } + +// fmt.Fprintf(os.Stdout, "Identity details for id %v. Traits: %v\n", createdIdentity, identity) +// c.JSON(http.StatusOK, gin.H{ +// "Identity": createdIdentity, +// "Traits": identity, +// }) +// } + +// func HandleDeleteIdentityFlow(c *gin.Context) { + +// var t IdentityBody +// err := c.BindJSON(&t) + +// if err != nil { +// log.ErrorLogger("Unable to process JSON body", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to process JSON body", +// }) +// return +// } + +// r, err := admin.DeleteIdentityFlowWrapper(t.Identity) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminDeleteIdentity`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "INternal server error", +// }) +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "message": "removed identity", +// }) +// } + +// func HandleListIdentity(c *gin.Context) { +// identities, r, err := admin.ListIdentityFlowWrapper() +// if err != nil { +// log.ErrorLogger("Error while calling `AdminListIdentities`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) + +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "identities": identities, +// }) +// } + +// func HandleBanIdentity(c *gin.Context) { +// var t IdentityBody +// err := c.BindJSON(&t) + +// if err != nil { +// log.ErrorLogger("Unable to process JSON body", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to process JSON body", +// }) +// return +// } + +// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + +// if err != nil { +// log.ErrorLogger("Error while fetching Identity details", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) +// return +// } + +// id, r, err := admin.BanIdentityFlowWrapper(identityResult) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": err.Error(), +// }) +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "identity": id, +// }) +// } + +// func HandleRemoveBanIdentity(c *gin.Context) { +// var t IdentityBody +// err := c.BindJSON(&t) + +// if err != nil { +// log.ErrorLogger("Unable to process JSON body", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to process JSON body", +// }) +// return +// } + +// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + +// if err != nil { +// log.ErrorLogger("Error while fetching Identity details", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) +// return +// } + +// id, r, err := admin.RemoveBanIdentityFlowWrapper(identityResult) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": err.Error(), +// }) +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "identity": id, +// }) +// } + +// func HandleRoleSwitch(c *gin.Context) { +// var t IdentityBody +// err := c.BindJSON(&t) + +// if err != nil { +// log.ErrorLogger("Unable to process JSON body", err) + +// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) +// c.JSON(errCode, gin.H{ +// "error": err.Error(), +// "message": "Unable to process JSON body", +// }) +// return +// } + +// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + +// if err != nil { +// log.ErrorLogger("Error while fetching Identity details", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": "Internal server error", +// }) +// return +// } + +// id, r, err := admin.RoleSwitchFlowWrapper(identityResult) + +// if err != nil { +// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) +// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +// c.JSON(http.StatusInternalServerError, gin.H{ +// "error": err.Error(), +// }) +// return +// } +// c.JSON(http.StatusOK, gin.H{ +// "identity": id, +// }) +// } diff --git a/api/main.go b/api/main.go index efc3ae6..b788394 100644 --- a/api/main.go +++ b/api/main.go @@ -36,13 +36,13 @@ func Start() { r.GET("/mfa", HandleGetMFAFlow) r.POST("/mfa", HandlePostMFAFlow) - r.POST("/create-identity", middleware.OnlyAdmin, HandleCreateIdentityFlow) - r.GET("/get-identity", middleware.OnlyAdmin, HandleGetIdentityFlow) - r.POST("/delete-identity", middleware.OnlyAdmin, HandleDeleteIdentityFlow) - r.GET("/list-identity", middleware.OnlyAdmin, HandleListIdentity) - r.PUT("/update-identity/ban", middleware.OnlyAdmin, HandleBanIdentity) - r.PUT("/update-identity/remove-ban", middleware.OnlyAdmin, HandleRemoveBanIdentity) - r.PUT("/update-identity/switch-roles", middleware.OnlyAdmin, HandleRoleSwitch) + // r.POST("/create-identity", middleware.OnlyAdmin, HandleCreateIdentityFlow) + // r.GET("/get-identity", middleware.OnlyAdmin, HandleGetIdentityFlow) + // r.POST("/delete-identity", middleware.OnlyAdmin, HandleDeleteIdentityFlow) + // r.GET("/list-identity", middleware.OnlyAdmin, HandleListIdentity) + // r.PUT("/update-identity/ban", middleware.OnlyAdmin, HandleBanIdentity) + // r.PUT("/update-identity/remove-ban", middleware.OnlyAdmin, HandleRemoveBanIdentity) + // r.PUT("/update-identity/switch-roles", middleware.OnlyAdmin, HandleRoleSwitch) r.GET("/register", HandleGetRegistrationFlow) r.POST("/register", HandlePostRegistrationFlow) diff --git a/api/status.go b/api/status.go index 03476e9..5276767 100644 --- a/api/status.go +++ b/api/status.go @@ -24,7 +24,7 @@ func HandleStatus(c *gin.Context) { } apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, _, err := apiClient.V0alpha2Api.ToSession(context.Background()).Cookie(cookie).Execute() + resp, _, err := apiClient.FrontendAPI.ToSession(context.Background()).Cookie(cookie).Execute() if err != nil { fmt.Println(err) } diff --git a/pkg/middleware/rolecheck.go b/pkg/middleware/rolecheck.go index a9a3cb4..184bffd 100644 --- a/pkg/middleware/rolecheck.go +++ b/pkg/middleware/rolecheck.go @@ -24,7 +24,7 @@ func GetSession(c *gin.Context) (*client.Session, error) { return nil, err } apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, r, err := apiClient.V0alpha2Api.ToSession(context.Background()).Cookie(cookie).Execute() + resp, r, err := apiClient.FrontendAPI.ToSession(context.Background()).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.ToSession``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) diff --git a/pkg/middleware/session.go b/pkg/middleware/session.go index 5b3f5c2..52d4e8b 100644 --- a/pkg/middleware/session.go +++ b/pkg/middleware/session.go @@ -60,7 +60,7 @@ func (k *kratosMiddleware) validateSession(r *http.Request) (*client.Session, er if cookie == nil { return nil, errors.New("no session found in cookie") } - resp, _, err := k.client.V0alpha2Api.ToSession(context.Background()).Cookie(cookie.String()).Execute() + resp, _, err := k.client.FrontendAPI.ToSession(context.Background()).Cookie(cookie.String()).Execute() if err != nil { return nil, err } diff --git a/pkg/wrapper/kratos/admin/admin.go b/pkg/wrapper/kratos/admin/admin.go index 1c2fdff..c93b6d2 100644 --- a/pkg/wrapper/kratos/admin/admin.go +++ b/pkg/wrapper/kratos/admin/admin.go @@ -1,103 +1,103 @@ package admin -import ( - "context" - "net/http" +// import ( +// "context" +// "net/http" - client "github.com/ory/client-go" +// client "github.com/ory/client-go" - "github.com/sdslabs/nymeria/config" - "github.com/sdslabs/nymeria/pkg/middleware" -) +// "github.com/sdslabs/nymeria/config" +// "github.com/sdslabs/nymeria/pkg/middleware" +// ) -func CreateIdentityFlowWrapper(data Identity) (*client.Identity, *http.Response, error) { - timeStamp := middleware.CurrentTimeStamp() +// func CreateIdentityFlowWrapper(data Identity) (*client.Identity, *http.Response, error) { +// timeStamp := middleware.CurrentTimeStamp() - trait := map[string]interface{}{ - "email": data.Email, - "name": data.Name, - "phone_number": data.PhoneNumber, - "img_url": data.ImgURL, - "invite_status": "pending", - "role": data.Role, - "created_at": timeStamp, - "totp_enabled": false, - } +// trait := map[string]interface{}{ +// "email": data.Email, +// "name": data.Name, +// "phone_number": data.PhoneNumber, +// "img_url": data.ImgURL, +// "invite_status": "pending", +// "role": data.Role, +// "created_at": timeStamp, +// "totp_enabled": false, +// } - adminCreateIdentityBody := *client.NewAdminCreateIdentityBody("default", trait) // AdminCreateIdentityBody | (optional) +// adminCreateIdentityBody := *client.NewAdminCreateIdentityBody("default", trait) // AdminCreateIdentityBody | (optional) - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - createdIdentity, r, err := apiClient.V0alpha2Api.AdminCreateIdentity(context.Background()).AdminCreateIdentityBody(adminCreateIdentityBody).Execute() +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// createdIdentity, r, err := apiClient.V0alpha2Api.AdminCreateIdentity(context.Background()).AdminCreateIdentityBody(adminCreateIdentityBody).Execute() - return createdIdentity, r, err -} +// return createdIdentity, r, err +// } -func GetIdentityFlowWrapper(createdIdentity string) (*client.Identity, *http.Response, error) { - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// func GetIdentityFlowWrapper(createdIdentity string) (*client.Identity, *http.Response, error) { +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - getIdentity, r, err := apiClient.V0alpha2Api.AdminGetIdentity(context.Background(), createdIdentity).Execute() +// getIdentity, r, err := apiClient.V0alpha2Api.AdminGetIdentity(context.Background(), createdIdentity).Execute() - return getIdentity, r, err -} +// return getIdentity, r, err +// } -func DeleteIdentityFlowWrapper(identity string) (*http.Response, error) { - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// func DeleteIdentityFlowWrapper(identity string) (*http.Response, error) { +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - r, err := apiClient.V0alpha2Api.AdminDeleteIdentity(context.Background(), identity).Execute() +// r, err := apiClient.V0alpha2Api.AdminDeleteIdentity(context.Background(), identity).Execute() - return r, err -} +// return r, err +// } -func ListIdentityFlowWrapper() ([]client.Identity, *http.Response, error) { - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// func ListIdentityFlowWrapper() ([]client.Identity, *http.Response, error) { +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - identities, r, err := apiClient.V0alpha2Api.AdminListIdentities(context.Background()).Execute() +// identities, r, err := apiClient.V0alpha2Api.AdminListIdentities(context.Background()).Execute() - return identities, r, err +// return identities, r, err -} +// } -func BanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { - newState, err := client.NewIdentityStateFromValue("inactive") - if err != nil { - return nil, nil, err - } +// func BanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { +// newState, err := client.NewIdentityStateFromValue("inactive") +// if err != nil { +// return nil, nil, err +// } - submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) +// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() - return id, r, err -} +// return id, r, err +// } -func RemoveBanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { - newState, err := client.NewIdentityStateFromValue("active") - if err != nil { - return nil, nil, err - } +// func RemoveBanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { +// newState, err := client.NewIdentityStateFromValue("active") +// if err != nil { +// return nil, nil, err +// } - submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) +// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() - return id, r, err -} +// return id, r, err +// } -func RoleSwitchFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { - traits := identity.GetTraits().(map[string]interface{}) +// func RoleSwitchFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { +// traits := identity.GetTraits().(map[string]interface{}) - if traits["role"] == "user" { - traits["role"] = "admin" - } else if traits["role"] == "admin" { - traits["role"] = "user" - } +// if traits["role"] == "user" { +// traits["role"] = "admin" +// } else if traits["role"] == "admin" { +// traits["role"] = "user" +// } - submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *identity.State, traits) +// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *identity.State, traits) - apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) - id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() +// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() - return id, r, err -} +// return id, r, err +// } diff --git a/pkg/wrapper/kratos/login/login.go b/pkg/wrapper/kratos/login/login.go index 930cb24..62a1d14 100644 --- a/pkg/wrapper/kratos/login/login.go +++ b/pkg/wrapper/kratos/login/login.go @@ -50,3 +50,21 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass return resp.Session, responseCookies[1], nil } + +func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, totp string) (client.Session, string, error) { + submitDataBody := client.UpdateLoginFlowBody{UpdateLoginFlowWithTotpMethod: client.NewUpdateLoginFlowWithTotpMethod("totp", totp)} // SubmitSelfServiceLoginFlowBody | + + submitDataBody.UpdateLoginFlowWithTotpMethod.SetCsrfToken(csrfToken) + + apiClient := client.NewAPIClient(config.KratosClientConfig) + + resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Flow(flowID).UpdateLoginFlowBody(submitDataBody).XSessionToken("").Cookie(cookie).Execute() + + if err != nil { + return *client.NewSessionWithDefaults(), "", err + } + + responseCookies := r.Header["Set-Cookie"] + + return resp.Session, responseCookies[0], nil +} diff --git a/pkg/wrapper/kratos/logout/logout.go b/pkg/wrapper/kratos/logout/logout.go index 03dc3d6..b5e048d 100644 --- a/pkg/wrapper/kratos/logout/logout.go +++ b/pkg/wrapper/kratos/logout/logout.go @@ -2,17 +2,16 @@ package logout import ( "context" - "net/http" client "github.com/ory/client-go" "github.com/sdslabs/nymeria/config" ) -func InitializeLogoutFlowWrapper(cookie string) (*client.SelfServiceLogoutUrl, error) { +func InitializeLogoutFlowWrapper(cookie string) (*client.LogoutFlow, error) { apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, _, err := apiClient.V0alpha2Api.CreateSelfServiceLogoutFlowUrlForBrowsers(context.Background()).Cookie(cookie).Execute() + resp, _, err := apiClient.FrontendAPI.CreateBrowserLogoutFlow(context.Background()).Cookie(cookie).Execute() if err != nil { return nil, err @@ -22,21 +21,9 @@ func InitializeLogoutFlowWrapper(cookie string) (*client.SelfServiceLogoutUrl, e } func SubmitLogoutFlowWrapper(cookie string, token string, returnToUrl string) error { - client := &http.Client{} - req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:4433/self-service/logout", nil) - if err != nil { - return err - } - - q := req.URL.Query() - q.Add("token", token) - - req.URL.RawQuery = q.Encode() - req.Header.Set("Cookie", cookie) - req.Header.Set("Accept", "application/json") - - _, err = client.Do(req) + apiClient := client.NewAPIClient(config.KratosClientConfig) + _, err := apiClient.FrontendAPI.UpdateLogoutFlow(context.Background()).Cookie(cookie).Token(token).Execute() if err != nil { return err } diff --git a/pkg/wrapper/kratos/recovery/recovery.go b/pkg/wrapper/kratos/recovery/recovery.go index 413224d..a5cedf1 100644 --- a/pkg/wrapper/kratos/recovery/recovery.go +++ b/pkg/wrapper/kratos/recovery/recovery.go @@ -16,7 +16,7 @@ func InitializeRecoveryFlowWrapper() (string, string, string, error) { apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, httpRes, err := apiClient.V0alpha2Api.InitializeSelfServiceRecoveryFlowForBrowsers(context.Background()).ReturnTo(returnTo).Execute() + resp, httpRes, err := apiClient.FrontendAPI.CreateBrowserRecoveryFlow(context.Background()).ReturnTo(returnTo).Execute() if err != nil { return "", "", "", err } @@ -37,13 +37,13 @@ func InitializeRecoveryFlowWrapper() (string, string, string, error) { func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, email string) (string, error) { - submitFlowBody := client.SubmitSelfServiceRecoveryFlowBody{ - SubmitSelfServiceRecoveryFlowWithLinkMethodBody: client.NewSubmitSelfServiceRecoveryFlowWithLinkMethodBody(email, "link"), + submitFlowBody := client.UpdateRecoveryFlowBody{ + UpdateRecoveryFlowWithLinkMethod: client.NewUpdateRecoveryFlowWithLinkMethod(email, "link"), } - submitFlowBody.SubmitSelfServiceRecoveryFlowWithLinkMethodBody.SetCsrfToken(csrfToken) + submitFlowBody.UpdateRecoveryFlowWithLinkMethod.SetCsrfToken(csrfToken) apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceRecoveryFlow(context.Background()).Flow(flowID).SubmitSelfServiceRecoveryFlowBody(submitFlowBody).Cookie(cookie).Execute() + _, r, err := apiClient.FrontendAPI.UpdateRecoveryFlow(context.Background()).Flow(flowID).UpdateRecoveryFlowBody(submitFlowBody).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRecoveryFlow``: %v\n", err) diff --git a/pkg/wrapper/kratos/settings/settings.go b/pkg/wrapper/kratos/settings/settings.go index a81a3c4..8ad78a2 100644 --- a/pkg/wrapper/kratos/settings/settings.go +++ b/pkg/wrapper/kratos/settings/settings.go @@ -11,7 +11,7 @@ import ( "github.com/sdslabs/nymeria/config" ) -func InitializeSettingsFlowWrapper(session_cookie string, recovery_cookie string) (client.SelfServiceSettingsFlow, string, error) { +func InitializeSettingsFlowWrapper(session_cookie string, recovery_cookie string) (client.SettingsFlow, string, error) { returnTo := "" // string | The URL to return the browser to after the flow was completed. (optional) @@ -24,9 +24,9 @@ func InitializeSettingsFlowWrapper(session_cookie string, recovery_cookie string } apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, httpRes, err := apiClient.V0alpha2Api.InitializeSelfServiceSettingsFlowForBrowsers(context.Background()).ReturnTo(returnTo).Cookie(cookie).Execute() + resp, httpRes, err := apiClient.FrontendAPI.CreateBrowserSettingsFlow(context.Background()).ReturnTo(returnTo).Cookie(cookie).Execute() if err != nil { - return *client.NewSelfServiceSettingsFlowWithDefaults(), "", err + return *client.NewSettingsFlowWithDefaults(), "", err } cookie = httpRes.Header.Get("Set-Cookie") @@ -35,15 +35,15 @@ func InitializeSettingsFlowWrapper(session_cookie string, recovery_cookie string } func SubmitSettingsFlowPasswordMethod(flow_cookie string, session_cookie string, flowID string, csrfToken string, password string) (string, error) { - submitFlowBody := client.SubmitSelfServiceSettingsFlowBody{ - SubmitSelfServiceSettingsFlowWithPasswordMethodBody: client.NewSubmitSelfServiceSettingsFlowWithPasswordMethodBody("password", password), + submitFlowBody := client.UpdateSettingsFlowBody{ + UpdateSettingsFlowWithPasswordMethod: client.NewUpdateSettingsFlowWithPasswordMethod("password", password), } - submitFlowBody.SubmitSelfServiceSettingsFlowWithPasswordMethodBody.SetCsrfToken(csrfToken) + submitFlowBody.UpdateSettingsFlowWithPasswordMethod.SetCsrfToken(csrfToken) cookie := strings.Split(flow_cookie, ";")[0] + "; " + strings.Split(session_cookie, ";")[0] + "; x-csrf-token=" + csrfToken apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).SubmitSelfServiceSettingsFlowBody(submitFlowBody).Execute() + _, r, err := apiClient.FrontendAPI.UpdateSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).UpdateSettingsFlowBody(submitFlowBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) @@ -55,16 +55,16 @@ func SubmitSettingsFlowPasswordMethod(flow_cookie string, session_cookie string, } func SubmitSettingsFlowProfileMethod(flow_cookie string, session_cookie string, flowID string, csrfToken string, traits map[string]interface{}) (string, error) { - submitFlowBody := client.SubmitSelfServiceSettingsFlowBody{ - SubmitSelfServiceSettingsFlowWithProfileMethodBody: client.NewSubmitSelfServiceSettingsFlowWithProfileMethodBody("profile", traits), + submitFlowBody := client.UpdateSettingsFlowBody{ + UpdateSettingsFlowWithProfileMethod: client.NewUpdateSettingsFlowWithProfileMethod("profile", traits), } - submitFlowBody.SubmitSelfServiceSettingsFlowWithProfileMethodBody.SetCsrfToken(csrfToken) + submitFlowBody.UpdateSettingsFlowWithProfileMethod.SetCsrfToken(csrfToken) cookie := strings.Split(flow_cookie, ";")[0] + "; " + strings.Split(session_cookie, ";")[0] + "; x-csrf-token=" + csrfToken apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).SubmitSelfServiceSettingsFlowBody(submitFlowBody).Execute() + _, r, err := apiClient.FrontendAPI.UpdateSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).UpdateSettingsFlowBody(submitFlowBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) @@ -76,18 +76,18 @@ func SubmitSettingsFlowProfileMethod(flow_cookie string, session_cookie string, } func SubmitSettingsFlowTOTPMethod(flow_cookie string, session_cookie string, flowID string, csrfToken string, TOTPcode string, TOTPUnlink bool) (string, error) { - submitFlowBody := client.SubmitSelfServiceSettingsFlowBody{ - SubmitSelfServiceSettingsFlowWithTotpMethodBody: client.NewSubmitSelfServiceSettingsFlowWithTotpMethodBody("totp"), + submitFlowBody := client.UpdateSettingsFlowBody{ + UpdateSettingsFlowWithTotpMethod: client.NewUpdateSettingsFlowWithTotpMethod("totp"), } - submitFlowBody.SubmitSelfServiceSettingsFlowWithTotpMethodBody.SetCsrfToken(csrfToken) - submitFlowBody.SubmitSelfServiceSettingsFlowWithTotpMethodBody.SetTotpCode(TOTPcode) - submitFlowBody.SubmitSelfServiceSettingsFlowWithTotpMethodBody.SetTotpUnlink(TOTPUnlink) + submitFlowBody.UpdateSettingsFlowWithTotpMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateSettingsFlowWithTotpMethod.SetTotpCode(TOTPcode) + submitFlowBody.UpdateSettingsFlowWithTotpMethod.SetTotpUnlink(TOTPUnlink) cookie := strings.Split(flow_cookie, ";")[0] + "; " + strings.Split(session_cookie, ";")[0] + "; x-csrf-token=" + csrfToken apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).SubmitSelfServiceSettingsFlowBody(submitFlowBody).Execute() + _, r, err := apiClient.FrontendAPI.UpdateSettingsFlow(context.Background()).Flow(flowID).Cookie(cookie).UpdateSettingsFlowBody(submitFlowBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) diff --git a/pkg/wrapper/kratos/verification/verification.go b/pkg/wrapper/kratos/verification/verification.go index 6f87672..8352303 100644 --- a/pkg/wrapper/kratos/verification/verification.go +++ b/pkg/wrapper/kratos/verification/verification.go @@ -13,7 +13,7 @@ import ( func InitializeVerificationFlowWrapper() (string, string, string, error) { apiClient := client.NewAPIClient(config.KratosClientConfig) - resp, r, err := apiClient.V0alpha2Api.InitializeSelfServiceVerificationFlowForBrowsers(context.Background()).Execute() + resp, r, err := apiClient.FrontendAPI.CreateBrowserVerificationFlow(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.InitializeSelfServiceVerificationFlowForBrowsers``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) @@ -35,15 +35,15 @@ func InitializeVerificationFlowWrapper() (string, string, string, error) { func SubmitVerificationFlowWrapper(cookie string, flowID string, csrfToken string, email string) (string, error) { - submitFlowBody := client.SubmitSelfServiceVerificationFlowBody{ - SubmitSelfServiceVerificationFlowWithLinkMethodBody: client.NewSubmitSelfServiceVerificationFlowWithLinkMethodBody(email, "link"), + submitFlowBody := client.UpdateVerificationFlowBody{ + UpdateVerificationFlowWithLinkMethod: client.NewUpdateVerificationFlowWithLinkMethod(email, "link"), } - submitFlowBody.SubmitSelfServiceVerificationFlowWithLinkMethodBody.SetCsrfToken(csrfToken) + submitFlowBody.UpdateVerificationFlowWithLinkMethod.SetCsrfToken(csrfToken) apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.V0alpha2Api.SubmitSelfServiceVerificationFlow(context.Background()).Flow(flowID).SubmitSelfServiceVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() + _, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) From a76c837c4f27d2c651a4e50c7df38c5199270786 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Mon, 26 Aug 2024 19:01:21 +0530 Subject: [PATCH 03/20] Updates Admin Routes to latest Kratos --- api/admin.go | 548 +++++++++++++++--------------- pkg/wrapper/kratos/admin/admin.go | 134 ++++---- 2 files changed, 337 insertions(+), 345 deletions(-) diff --git a/api/admin.go b/api/admin.go index 7bbc134..4d41164 100644 --- a/api/admin.go +++ b/api/admin.go @@ -1,276 +1,276 @@ package api -// import ( -// "encoding/json" -// "fmt" -// "net/http" -// "os" -// "strconv" -// "strings" - -// "github.com/gin-gonic/gin" - -// "github.com/sdslabs/nymeria/log" -// "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" -// ) - -// func HandleCreateIdentityFlow(c *gin.Context) { - -// var t admin.Identity - -// err := c.BindJSON(&t) - -// if err != nil { -// log.ErrorLogger("Unable to process JSON body", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to process JSON body", -// }) -// return -// } - -// if err != nil { -// log.ErrorLogger("Unable to convert JSON to map", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to convert JSON to map", -// }) -// return -// } - -// createdIdentity, r, err := admin.CreateIdentityFlowWrapper(t) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminCreateIdentity`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "identity": createdIdentity.Id, -// }) -// } - -// func HandleGetIdentityFlow(c *gin.Context) { -// createdIdentity := c.Query("identity") -// getIdentity, r, err := admin.GetIdentityFlowWrapper(createdIdentity) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminGetIdentity`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) -// return -// } - -// jsonString, err := json.Marshal(getIdentity.Traits) - -// if err != nil { -// log.ErrorLogger("Unable to convert map to json", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to convert map to json", -// }) -// return -// } - -// var identity admin.Identity - -// err = json.Unmarshal(jsonString, &identity) - -// if err != nil { -// log.ErrorLogger("Unable to convert JSON to map", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to convert JSON to map", -// }) -// return -// } - -// fmt.Fprintf(os.Stdout, "Identity details for id %v. Traits: %v\n", createdIdentity, identity) -// c.JSON(http.StatusOK, gin.H{ -// "Identity": createdIdentity, -// "Traits": identity, -// }) -// } - -// func HandleDeleteIdentityFlow(c *gin.Context) { - -// var t IdentityBody -// err := c.BindJSON(&t) - -// if err != nil { -// log.ErrorLogger("Unable to process JSON body", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to process JSON body", -// }) -// return -// } - -// r, err := admin.DeleteIdentityFlowWrapper(t.Identity) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminDeleteIdentity`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "INternal server error", -// }) -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "message": "removed identity", -// }) -// } - -// func HandleListIdentity(c *gin.Context) { -// identities, r, err := admin.ListIdentityFlowWrapper() -// if err != nil { -// log.ErrorLogger("Error while calling `AdminListIdentities`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) - -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "identities": identities, -// }) -// } - -// func HandleBanIdentity(c *gin.Context) { -// var t IdentityBody -// err := c.BindJSON(&t) - -// if err != nil { -// log.ErrorLogger("Unable to process JSON body", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to process JSON body", -// }) -// return -// } - -// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - -// if err != nil { -// log.ErrorLogger("Error while fetching Identity details", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) -// return -// } - -// id, r, err := admin.BanIdentityFlowWrapper(identityResult) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": err.Error(), -// }) -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "identity": id, -// }) -// } - -// func HandleRemoveBanIdentity(c *gin.Context) { -// var t IdentityBody -// err := c.BindJSON(&t) - -// if err != nil { -// log.ErrorLogger("Unable to process JSON body", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to process JSON body", -// }) -// return -// } - -// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - -// if err != nil { -// log.ErrorLogger("Error while fetching Identity details", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) -// return -// } - -// id, r, err := admin.RemoveBanIdentityFlowWrapper(identityResult) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": err.Error(), -// }) -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "identity": id, -// }) -// } - -// func HandleRoleSwitch(c *gin.Context) { -// var t IdentityBody -// err := c.BindJSON(&t) - -// if err != nil { -// log.ErrorLogger("Unable to process JSON body", err) - -// errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) -// c.JSON(errCode, gin.H{ -// "error": err.Error(), -// "message": "Unable to process JSON body", -// }) -// return -// } - -// identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) - -// if err != nil { -// log.ErrorLogger("Error while fetching Identity details", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": "Internal server error", -// }) -// return -// } - -// id, r, err := admin.RoleSwitchFlowWrapper(identityResult) - -// if err != nil { -// log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) -// fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) -// c.JSON(http.StatusInternalServerError, gin.H{ -// "error": err.Error(), -// }) -// return -// } -// c.JSON(http.StatusOK, gin.H{ -// "identity": id, -// }) -// } +import ( + "encoding/json" + "fmt" + "net/http" + "os" + "strconv" + "strings" + + "github.com/gin-gonic/gin" + + "github.com/sdslabs/nymeria/log" + "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" +) + +func HandleCreateIdentityFlow(c *gin.Context) { + + var t admin.Identity + + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process JSON body", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process JSON body", + }) + return + } + + if err != nil { + log.ErrorLogger("Unable to convert JSON to map", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to convert JSON to map", + }) + return + } + + createdIdentity, r, err := admin.CreateIdentityFlowWrapper(t) + + if err != nil { + log.ErrorLogger("Error while calling `AdminCreateIdentity`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "identity": createdIdentity.Id, + }) +} + +func HandleGetIdentityFlow(c *gin.Context) { + createdIdentity := c.Query("identity") + getIdentity, r, err := admin.GetIdentityFlowWrapper(createdIdentity) + + if err != nil { + log.ErrorLogger("Error while calling `AdminGetIdentity`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + + jsonString, err := json.Marshal(getIdentity.Traits) + + if err != nil { + log.ErrorLogger("Unable to convert map to json", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to convert map to json", + }) + return + } + + var identity admin.Identity + + err = json.Unmarshal(jsonString, &identity) + + if err != nil { + log.ErrorLogger("Unable to convert JSON to map", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to convert JSON to map", + }) + return + } + + fmt.Fprintf(os.Stdout, "Identity details for id %v. Traits: %v\n", createdIdentity, identity) + c.JSON(http.StatusOK, gin.H{ + "Identity": createdIdentity, + "Traits": identity, + }) +} + +func HandleDeleteIdentityFlow(c *gin.Context) { + + var t IdentityBody + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process JSON body", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process JSON body", + }) + return + } + + r, err := admin.DeleteIdentityFlowWrapper(t.Identity) + + if err != nil { + log.ErrorLogger("Error while calling `AdminDeleteIdentity`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "INternal server error", + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "message": "removed identity", + }) +} + +func HandleListIdentity(c *gin.Context) { + identities, r, err := admin.ListIdentityFlowWrapper() + if err != nil { + log.ErrorLogger("Error while calling `AdminListIdentities`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + + return + } + c.JSON(http.StatusOK, gin.H{ + "identities": identities, + }) +} + +func HandleBanIdentity(c *gin.Context) { + var t IdentityBody + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process JSON body", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process JSON body", + }) + return + } + + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + + if err != nil { + log.ErrorLogger("Error while fetching Identity details", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + + id, r, err := admin.BanIdentityFlowWrapper(identityResult) + + if err != nil { + log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "identity": id, + }) +} + +func HandleRemoveBanIdentity(c *gin.Context) { + var t IdentityBody + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process JSON body", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process JSON body", + }) + return + } + + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + + if err != nil { + log.ErrorLogger("Error while fetching Identity details", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + + id, r, err := admin.RemoveBanIdentityFlowWrapper(identityResult) + + if err != nil { + log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "identity": id, + }) +} + +func HandleRoleSwitch(c *gin.Context) { + var t IdentityBody + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process JSON body", err) + + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process JSON body", + }) + return + } + + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) + + if err != nil { + log.ErrorLogger("Error while fetching Identity details", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Internal server error", + }) + return + } + + id, r, err := admin.RoleSwitchFlowWrapper(identityResult) + + if err != nil { + log.ErrorLogger("Error while calling `AdminPatchIdentities`", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + c.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + c.JSON(http.StatusOK, gin.H{ + "identity": id, + }) +} diff --git a/pkg/wrapper/kratos/admin/admin.go b/pkg/wrapper/kratos/admin/admin.go index c93b6d2..140cd4a 100644 --- a/pkg/wrapper/kratos/admin/admin.go +++ b/pkg/wrapper/kratos/admin/admin.go @@ -1,103 +1,95 @@ package admin -// import ( -// "context" -// "net/http" +import ( + "context" + "net/http" -// client "github.com/ory/client-go" + client "github.com/ory/client-go" -// "github.com/sdslabs/nymeria/config" -// "github.com/sdslabs/nymeria/pkg/middleware" -// ) + "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/pkg/middleware" +) -// func CreateIdentityFlowWrapper(data Identity) (*client.Identity, *http.Response, error) { -// timeStamp := middleware.CurrentTimeStamp() +func CreateIdentityFlowWrapper(data Identity) (*client.Identity, *http.Response, error) { + timeStamp := middleware.CurrentTimeStamp() -// trait := map[string]interface{}{ -// "email": data.Email, -// "name": data.Name, -// "phone_number": data.PhoneNumber, -// "img_url": data.ImgURL, -// "invite_status": "pending", -// "role": data.Role, -// "created_at": timeStamp, -// "totp_enabled": false, -// } + trait := map[string]interface{}{ + "email": data.Email, + "name": data.Name, + "phone_number": data.PhoneNumber, + "img_url": data.ImgURL, + "invite_status": "pending", + "role": data.Role, + "created_at": timeStamp, + "totp_enabled": false, + } -// adminCreateIdentityBody := *client.NewAdminCreateIdentityBody("default", trait) // AdminCreateIdentityBody | (optional) + adminCreateIdentityBody := *client.NewCreateIdentityBody("default", trait) // AdminCreateIdentityBody | (optional) -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// createdIdentity, r, err := apiClient.V0alpha2Api.AdminCreateIdentity(context.Background()).AdminCreateIdentityBody(adminCreateIdentityBody).Execute() + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) + createdIdentity, r, err := apiClient.IdentityAPI.CreateIdentity(context.Background()).CreateIdentityBody(adminCreateIdentityBody).Execute() -// return createdIdentity, r, err -// } + return createdIdentity, r, err +} -// func GetIdentityFlowWrapper(createdIdentity string) (*client.Identity, *http.Response, error) { -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +func GetIdentityFlowWrapper(createdIdentity string) (*client.Identity, *http.Response, error) { + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// getIdentity, r, err := apiClient.V0alpha2Api.AdminGetIdentity(context.Background(), createdIdentity).Execute() + getIdentity, r, err := apiClient.IdentityAPI.GetIdentity(context.Background(), createdIdentity).Execute() -// return getIdentity, r, err -// } + return getIdentity, r, err +} -// func DeleteIdentityFlowWrapper(identity string) (*http.Response, error) { -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +func DeleteIdentityFlowWrapper(identity string) (*http.Response, error) { + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// r, err := apiClient.V0alpha2Api.AdminDeleteIdentity(context.Background(), identity).Execute() + r, err := apiClient.IdentityAPI.DeleteIdentity(context.Background(), identity).Execute() -// return r, err -// } + return r, err +} -// func ListIdentityFlowWrapper() ([]client.Identity, *http.Response, error) { -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) +func ListIdentityFlowWrapper() ([]client.Identity, *http.Response, error) { + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// identities, r, err := apiClient.V0alpha2Api.AdminListIdentities(context.Background()).Execute() + identities, r, err := apiClient.IdentityAPI.ListIdentities(context.Background()).Execute() -// return identities, r, err + return identities, r, err -// } +} -// func BanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { -// newState, err := client.NewIdentityStateFromValue("inactive") -// if err != nil { -// return nil, nil, err -// } +func BanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { -// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) + submitDataBody := *client.NewUpdateIdentityBody(identity.SchemaId, "inactive", identity.Traits.(map[string]interface{})) -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) + id, r, err := apiClient.IdentityAPI.UpdateIdentity(context.Background(), identity.Id).UpdateIdentityBody(submitDataBody).Execute() -// return id, r, err -// } + return id, r, err +} -// func RemoveBanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { -// newState, err := client.NewIdentityStateFromValue("active") -// if err != nil { -// return nil, nil, err -// } +func RemoveBanIdentityFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { -// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *newState, identity.Traits.(map[string]interface{})) + submitDataBody := *client.NewUpdateIdentityBody(identity.SchemaId, "active", identity.Traits.(map[string]interface{})) -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) + id, r, err := apiClient.IdentityAPI.UpdateIdentity(context.Background(), identity.Id).UpdateIdentityBody(submitDataBody).Execute() -// return id, r, err -// } + return id, r, err +} -// func RoleSwitchFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { -// traits := identity.GetTraits().(map[string]interface{}) +func RoleSwitchFlowWrapper(identity *client.Identity) (*client.Identity, *http.Response, error) { + traits := identity.GetTraits().(map[string]interface{}) -// if traits["role"] == "user" { -// traits["role"] = "admin" -// } else if traits["role"] == "admin" { -// traits["role"] = "user" -// } + if traits["role"] == "user" { + traits["role"] = "admin" + } else if traits["role"] == "admin" { + traits["role"] = "user" + } -// submitDataBody := *client.NewAdminUpdateIdentityBody(identity.SchemaId, *identity.State, traits) + submitDataBody := *client.NewUpdateIdentityBody(identity.SchemaId, *identity.State, traits) -// apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) -// id, r, err := apiClient.V0alpha2Api.AdminUpdateIdentity(context.Background(), identity.Id).AdminUpdateIdentityBody(submitDataBody).Execute() + apiClient := client.NewAPIClient(config.KratosClientConfigAdmin) + id, r, err := apiClient.IdentityAPI.UpdateIdentity(context.Background(), identity.Id).UpdateIdentityBody(submitDataBody).Execute() -// return id, r, err -// } + return id, r, err +} From 01a24f0757157c49b0395ae8a32f938d6cb39192 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Tue, 27 Aug 2024 10:24:39 +0530 Subject: [PATCH 04/20] Fixes admin routes --- api/admin.go | 11 ----------- api/main.go | 14 +++++++------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/api/admin.go b/api/admin.go index 4d41164..2316192 100644 --- a/api/admin.go +++ b/api/admin.go @@ -31,17 +31,6 @@ func HandleCreateIdentityFlow(c *gin.Context) { return } - if err != nil { - log.ErrorLogger("Unable to convert JSON to map", err) - - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to convert JSON to map", - }) - return - } - createdIdentity, r, err := admin.CreateIdentityFlowWrapper(t) if err != nil { diff --git a/api/main.go b/api/main.go index b788394..efc3ae6 100644 --- a/api/main.go +++ b/api/main.go @@ -36,13 +36,13 @@ func Start() { r.GET("/mfa", HandleGetMFAFlow) r.POST("/mfa", HandlePostMFAFlow) - // r.POST("/create-identity", middleware.OnlyAdmin, HandleCreateIdentityFlow) - // r.GET("/get-identity", middleware.OnlyAdmin, HandleGetIdentityFlow) - // r.POST("/delete-identity", middleware.OnlyAdmin, HandleDeleteIdentityFlow) - // r.GET("/list-identity", middleware.OnlyAdmin, HandleListIdentity) - // r.PUT("/update-identity/ban", middleware.OnlyAdmin, HandleBanIdentity) - // r.PUT("/update-identity/remove-ban", middleware.OnlyAdmin, HandleRemoveBanIdentity) - // r.PUT("/update-identity/switch-roles", middleware.OnlyAdmin, HandleRoleSwitch) + r.POST("/create-identity", middleware.OnlyAdmin, HandleCreateIdentityFlow) + r.GET("/get-identity", middleware.OnlyAdmin, HandleGetIdentityFlow) + r.POST("/delete-identity", middleware.OnlyAdmin, HandleDeleteIdentityFlow) + r.GET("/list-identity", middleware.OnlyAdmin, HandleListIdentity) + r.PUT("/update-identity/ban", middleware.OnlyAdmin, HandleBanIdentity) + r.PUT("/update-identity/remove-ban", middleware.OnlyAdmin, HandleRemoveBanIdentity) + r.PUT("/update-identity/switch-roles", middleware.OnlyAdmin, HandleRoleSwitch) r.GET("/register", HandleGetRegistrationFlow) r.POST("/register", HandlePostRegistrationFlow) From f27290b128eedacfb6270c0a525529a45eb58132 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Tue, 27 Aug 2024 10:30:47 +0530 Subject: [PATCH 05/20] Change Recovery method from link to code --- api/main.go | 1 + api/recovery.go | 52 +++++++++++++++++++++++-- api/settings.go | 20 ++-------- pkg/wrapper/kratos/recovery/recovery.go | 38 ++++++++++++++++-- pkg/wrapper/kratos/recovery/types.go | 7 ++-- pkg/wrapper/kratos/settings/settings.go | 11 ++---- 6 files changed, 96 insertions(+), 33 deletions(-) diff --git a/api/main.go b/api/main.go index efc3ae6..675e29d 100644 --- a/api/main.go +++ b/api/main.go @@ -54,6 +54,7 @@ func Start() { r.GET("/recovery", HandleGetRecoveryFlow) r.POST("/recovery", HandlePostRecoveryFlow) + r.POST("/recovery-code", HandlePostRecoveryCodeFlow) r.GET("/settings", HandleGetSettingsFlow) r.POST("/updateprofile", HandleUpdateProfile) diff --git a/api/recovery.go b/api/recovery.go index 1515a19..3bd6b03 100644 --- a/api/recovery.go +++ b/api/recovery.go @@ -60,8 +60,8 @@ func HandlePostRecoveryFlow(c *gin.Context) { }) return } - - _, err = recovery.SubmitRecoveryFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Email) + var csrf_token string + csrf_token, err = recovery.SubmitRecoveryFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Email) if err != nil { log.ErrorLogger("POST Recovery flow failed", err) @@ -74,6 +74,52 @@ func HandlePostRecoveryFlow(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{ - "message": "Mail sent with recovery link", + "message": "Mail sent with recovery code", + "csrf_token": csrf_token, + }) +} + +func HandlePostRecoveryCodeFlow(c *gin.Context) { + var t recovery.SubmitRecoveryAPIBody + err := c.BindJSON(&t) + + if err != nil { + log.ErrorLogger("Unable to process json body", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process json body", + }) + return + } + + cookie, err := c.Cookie("recovery_flow") + + if err != nil { + log.ErrorLogger("Recovery Flow Cookie not found", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Recovery Flow Cookie not found", + }) + return + } + + session, err := recovery.SubmitRecoveryCodeFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.RecoveryCode) + + if err != nil { + log.ErrorLogger("POST Recovery flow failed", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "POST Recovery Code flow failed", + }) + return + } + + c.SetCookie("sdslabs_session", session, 3600, "/", config.NymeriaConfig.URL.Domain, true, true) + + c.JSON(http.StatusOK, gin.H{ + "message": "Session cookie set for password change", }) } diff --git a/api/settings.go b/api/settings.go index 27771fc..79be25c 100644 --- a/api/settings.go +++ b/api/settings.go @@ -15,16 +15,9 @@ import ( func HandleGetSettingsFlow(c *gin.Context) { log.Logger.Debug("Get Settings") - session_cookie, err1 := c.Cookie("sdslabs_session") - recovery_cookie, err2 := c.Cookie("ory_kratos_session") - - if err1 != nil && err2 != nil { - var err error - if err1 != nil { - err = err1 - } else { - err = err2 - } + session_cookie, err := c.Cookie("sdslabs_session") + + if err != nil { log.ErrorLogger("Initialize Settings Failed", err) errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) c.JSON(errCode, gin.H{ @@ -34,7 +27,7 @@ func HandleGetSettingsFlow(c *gin.Context) { return } - flow, flow_cookie, err := settings.InitializeSettingsFlowWrapper(session_cookie, recovery_cookie) + flow, flow_cookie, err := settings.InitializeSettingsFlowWrapper(session_cookie) if err != nil { log.ErrorLogger("Initialize Settings flow Failed", err) @@ -46,11 +39,6 @@ func HandleGetSettingsFlow(c *gin.Context) { c.SetCookie("settings_flow", flow_cookie, 3600, "/", config.NymeriaConfig.URL.Domain, true, true) - if recovery_cookie != "" { - recovery_cookie = "ory_kratos_session=" + recovery_cookie - c.SetCookie("sdslabs_session", recovery_cookie, 900, "/", config.NymeriaConfig.URL.Domain, false, true) - } - flowID := flow.GetId() var csrf_token string diff --git a/pkg/wrapper/kratos/recovery/recovery.go b/pkg/wrapper/kratos/recovery/recovery.go index a5cedf1..0046d8b 100644 --- a/pkg/wrapper/kratos/recovery/recovery.go +++ b/pkg/wrapper/kratos/recovery/recovery.go @@ -38,9 +38,39 @@ func InitializeRecoveryFlowWrapper() (string, string, string, error) { func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, email string) (string, error) { submitFlowBody := client.UpdateRecoveryFlowBody{ - UpdateRecoveryFlowWithLinkMethod: client.NewUpdateRecoveryFlowWithLinkMethod(email, "link"), + UpdateRecoveryFlowWithCodeMethod: client.NewUpdateRecoveryFlowWithCodeMethod("code"), } - submitFlowBody.UpdateRecoveryFlowWithLinkMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateRecoveryFlowWithCodeMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateRecoveryFlowWithCodeMethod.SetEmail(email) + + apiClient := client.NewAPIClient(config.KratosClientConfig) + resp, r, err := apiClient.FrontendAPI.UpdateRecoveryFlow(context.Background()).Flow(flowID).UpdateRecoveryFlowBody(submitFlowBody).Cookie(cookie).Execute() + + var csrf_token string + + for _, node := range resp.Ui.Nodes { + if node.Attributes.UiNodeInputAttributes.Name == "csrf_token" { + csrf_token_interface := node.Attributes.UiNodeInputAttributes.Value + csrf_token, _ = csrf_token_interface.(string) + break + } + } + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRecoveryFlow``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + return "", err + } + + return csrf_token, nil +} + +func SubmitRecoveryCodeFlowWrapper(cookie string, flowID string, csrfToken string, recoveryCode string) (string, error) { + submitFlowBody := client.UpdateRecoveryFlowBody{ + UpdateRecoveryFlowWithCodeMethod: client.NewUpdateRecoveryFlowWithCodeMethod("code"), + } + submitFlowBody.UpdateRecoveryFlowWithCodeMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateRecoveryFlowWithCodeMethod.SetCode(recoveryCode) apiClient := client.NewAPIClient(config.KratosClientConfig) _, r, err := apiClient.FrontendAPI.UpdateRecoveryFlow(context.Background()).Flow(flowID).UpdateRecoveryFlowBody(submitFlowBody).Cookie(cookie).Execute() @@ -51,5 +81,7 @@ func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, e return "", err } - return "", nil + responseCookies := r.Header["Set-Cookie"] + + return responseCookies[1], nil } diff --git a/pkg/wrapper/kratos/recovery/types.go b/pkg/wrapper/kratos/recovery/types.go index 6cfee10..f6a3300 100644 --- a/pkg/wrapper/kratos/recovery/types.go +++ b/pkg/wrapper/kratos/recovery/types.go @@ -1,7 +1,8 @@ package recovery type SubmitRecoveryAPIBody struct { - CsrfToken string `json:"csrf_token"` - FlowID string `json:"flowID"` - Email string `json:"email"` + CsrfToken string `json:"csrf_token"` + FlowID string `json:"flowID"` + Email string `json:"email"` + RecoveryCode string `json:"recovery_code"` } diff --git a/pkg/wrapper/kratos/settings/settings.go b/pkg/wrapper/kratos/settings/settings.go index 8ad78a2..b4f686d 100644 --- a/pkg/wrapper/kratos/settings/settings.go +++ b/pkg/wrapper/kratos/settings/settings.go @@ -11,20 +11,15 @@ import ( "github.com/sdslabs/nymeria/config" ) -func InitializeSettingsFlowWrapper(session_cookie string, recovery_cookie string) (client.SettingsFlow, string, error) { +func InitializeSettingsFlowWrapper(session_cookie string) (client.SettingsFlow, string, error) { returnTo := "" // string | The URL to return the browser to after the flow was completed. (optional) - var cookie string - - if recovery_cookie != "" { - cookie = "ory_kratos_session=" + recovery_cookie - } else { - cookie = strings.Split(session_cookie, ";")[0] - } + cookie := strings.Split(session_cookie, ";")[0] apiClient := client.NewAPIClient(config.KratosClientConfig) resp, httpRes, err := apiClient.FrontendAPI.CreateBrowserSettingsFlow(context.Background()).ReturnTo(returnTo).Cookie(cookie).Execute() + if err != nil { return *client.NewSettingsFlowWithDefaults(), "", err } From 3d5b966e5f515444cb691fe75f5d44f5d6f2ec0d Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Tue, 27 Aug 2024 15:04:25 +0530 Subject: [PATCH 06/20] Updates Verification Flow from link method to OTP method --- api/main.go | 2 + api/registration.go | 6 +- api/verification.go | 93 ++++++++++++++++++- pkg/wrapper/kratos/recovery/recovery.go | 12 +-- .../kratos/registration/registration.go | 9 +- pkg/wrapper/kratos/verification/types.go | 7 +- .../kratos/verification/verification.go | 62 ++++++++++++- 7 files changed, 171 insertions(+), 20 deletions(-) diff --git a/api/main.go b/api/main.go index 675e29d..c05dcf7 100644 --- a/api/main.go +++ b/api/main.go @@ -62,7 +62,9 @@ func Start() { r.POST("/toggletotp", HandleToggleTOTP) r.GET("/verification", HandleGetVerificationFlow) + r.POST("/verification-after-registration", HandleGetVerificationAfterRegistrationFlow) r.POST("/verification", HandlePostVerificationFlow) + r.POST("/verification-code", HandlePostVerificationCodeFlow) r.POST("/get_profile", HandlePostProfile) r.POST("/get_verified_status", HandleGetVerifiedStatus) diff --git a/api/registration.go b/api/registration.go index 3f1b7c5..2e8b706 100644 --- a/api/registration.go +++ b/api/registration.go @@ -60,7 +60,7 @@ func HandlePostRegistrationFlow(c *gin.Context) { return } - session, err := registration.SubmitRegistrationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Traits) + flowID, sessionCookies, err := registration.SubmitRegistrationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Traits) if err != nil { log.ErrorLogger("Kratos post registration flow failed", err) @@ -72,9 +72,11 @@ func HandlePostRegistrationFlow(c *gin.Context) { return } - c.SetCookie("sdslabs_session", session, 3600, "/", config.NymeriaConfig.URL.Domain, true, true) + c.SetCookie("verification_flow", sessionCookies[0], 3600, "/", config.NymeriaConfig.URL.Domain, true, true) + c.SetCookie("sdslabs_session", sessionCookies[1], 3600, "/", config.NymeriaConfig.URL.Domain, true, true) c.JSON(http.StatusOK, gin.H{ "status": "created", + "flowID": flowID, }) } diff --git a/api/verification.go b/api/verification.go index ddc01a9..11325f4 100644 --- a/api/verification.go +++ b/api/verification.go @@ -35,6 +35,49 @@ func HandleGetVerificationFlow(c *gin.Context) { }) } +func HandleGetVerificationAfterRegistrationFlow(c *gin.Context) { + var t verification.SubmitVerificationBody + err := c.Bind(&t) + + if err != nil { + log.ErrorLogger("Unable to process json body", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process json body", + }) + return + } + + cookie, err := c.Cookie("verification_flow") + + if err != nil { + log.ErrorLogger("Cookie not found", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Cookie not found", + }) + return + } + + csrf_token, err := verification.InitializeVerificationAfterRegistrationFlowWrapper(cookie, t.FlowID) + + if err != nil { + log.ErrorLogger("Initialize Verification Failed", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Initialize Verification Failed", + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "csrf_token": csrf_token, + }) +} + func HandlePostVerificationFlow(c *gin.Context) { var t verification.SubmitVerificationBody err := c.Bind(&t) @@ -61,7 +104,53 @@ func HandlePostVerificationFlow(c *gin.Context) { return } - _, err = verification.SubmitVerificationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Email) + var csrf_token string + + csrf_token, err = verification.SubmitVerificationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Email) + + if err != nil { + log.ErrorLogger("Post Verification flow failed", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Post Settings flow failed", + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Account Verification Mail Sent", + "csrf_token": csrf_token, + }) +} + +func HandlePostVerificationCodeFlow(c *gin.Context) { + var t verification.SubmitVerificationBody + err := c.Bind(&t) + + if err != nil { + log.ErrorLogger("Unable to process json body", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to process json body", + }) + return + } + + cookie, err := c.Cookie("verification_flow") + + if err != nil { + log.ErrorLogger("Cookie not found", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Cookie not found", + }) + return + } + + _, err = verification.SubmitVerificationCodeFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.VerificationCode) if err != nil { log.ErrorLogger("Post Verification flow failed", err) @@ -74,7 +163,7 @@ func HandlePostVerificationFlow(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{ - "message": "Account Verification Mail Sent", + "message": "Account Verification Done", }) } diff --git a/pkg/wrapper/kratos/recovery/recovery.go b/pkg/wrapper/kratos/recovery/recovery.go index 0046d8b..e94d307 100644 --- a/pkg/wrapper/kratos/recovery/recovery.go +++ b/pkg/wrapper/kratos/recovery/recovery.go @@ -46,6 +46,12 @@ func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, e apiClient := client.NewAPIClient(config.KratosClientConfig) resp, r, err := apiClient.FrontendAPI.UpdateRecoveryFlow(context.Background()).Flow(flowID).UpdateRecoveryFlowBody(submitFlowBody).Cookie(cookie).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRecoveryFlow``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + return "", err + } + var csrf_token string for _, node := range resp.Ui.Nodes { @@ -56,12 +62,6 @@ func SubmitRecoveryFlowWrapper(cookie string, flowID string, csrfToken string, e } } - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRecoveryFlow``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - return "", err - } - return csrf_token, nil } diff --git a/pkg/wrapper/kratos/registration/registration.go b/pkg/wrapper/kratos/registration/registration.go index 67ba128..65b7c79 100644 --- a/pkg/wrapper/kratos/registration/registration.go +++ b/pkg/wrapper/kratos/registration/registration.go @@ -36,7 +36,7 @@ func InitializeRegistrationFlowWrapper() (string, string, string, error) { return setCookie, resp.Id, csrf_token, nil } -func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken string, password string, data Traits) (string, error) { +func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken string, password string, data Traits) (string, []string, error) { timeStamp := middleware.CurrentTimeStamp() trait := map[string]interface{}{ "email": data.Email, @@ -55,14 +55,15 @@ func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken strin apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.FrontendAPI.UpdateRegistrationFlow(context.Background()).Flow(flowID).UpdateRegistrationFlowBody(submitDataBody).Cookie(cookie).Execute() + resp, r, err := apiClient.FrontendAPI.UpdateRegistrationFlow(context.Background()).Flow(flowID).UpdateRegistrationFlowBody(submitDataBody).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRegistrationFlow``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - return "", err + return "", nil, err } responseCookies := r.Header["Set-Cookie"] - return responseCookies[1], nil + + return resp.GetContinueWith()[0].ContinueWithVerificationUi.GetFlow().Id, responseCookies, nil } diff --git a/pkg/wrapper/kratos/verification/types.go b/pkg/wrapper/kratos/verification/types.go index ee42de1..d37910e 100644 --- a/pkg/wrapper/kratos/verification/types.go +++ b/pkg/wrapper/kratos/verification/types.go @@ -1,7 +1,8 @@ package verification type SubmitVerificationBody struct { - CsrfToken string `json:"csrf_token"` - FlowID string `json:"flowID"` - Email string `json:"email"` + CsrfToken string `json:"csrf_token"` + FlowID string `json:"flowID"` + Email string `json:"email"` + VerificationCode string `json:"verification_code"` } diff --git a/pkg/wrapper/kratos/verification/verification.go b/pkg/wrapper/kratos/verification/verification.go index 8352303..1a5e6dd 100644 --- a/pkg/wrapper/kratos/verification/verification.go +++ b/pkg/wrapper/kratos/verification/verification.go @@ -33,17 +33,73 @@ func InitializeVerificationFlowWrapper() (string, string, string, error) { return setCookie, resp.Id, csrf_token, nil } +func InitializeVerificationAfterRegistrationFlowWrapper(cookie string, flowID string) (string, error) { + apiClient := client.NewAPIClient(config.KratosClientConfig) + + resp, r, err := apiClient.FrontendAPI.GetVerificationFlow(context.Background()).Cookie(cookie).Id(flowID).Execute() + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.InitializeSelfServiceVerificationFlowForBrowsers``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + var csrf_token string + + for _, node := range resp.Ui.Nodes { + if node.Attributes.UiNodeInputAttributes.Name == "csrf_token" { + csrf_token_interface := node.Attributes.UiNodeInputAttributes.Value + csrf_token, _ = csrf_token_interface.(string) + break + } + } + + return csrf_token, nil +} + func SubmitVerificationFlowWrapper(cookie string, flowID string, csrfToken string, email string) (string, error) { submitFlowBody := client.UpdateVerificationFlowBody{ - UpdateVerificationFlowWithLinkMethod: client.NewUpdateVerificationFlowWithLinkMethod(email, "link"), + UpdateVerificationFlowWithCodeMethod: client.NewUpdateVerificationFlowWithCodeMethod("code"), + } + + submitFlowBody.UpdateVerificationFlowWithCodeMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateVerificationFlowWithCodeMethod.SetEmail(email) + + apiClient := client.NewAPIClient(config.KratosClientConfig) + + resp, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + return "", err + } + + var csrf_token string + + for _, node := range resp.Ui.Nodes { + if node.Attributes.UiNodeInputAttributes.Name == "csrf_token" { + csrf_token_interface := node.Attributes.UiNodeInputAttributes.Value + csrf_token, _ = csrf_token_interface.(string) + break + } + } + + return csrf_token, nil +} + +func SubmitVerificationCodeFlowWrapper(cookie string, flowID string, csrfToken string, verificationCode string) (string, error) { + + submitFlowBody := client.UpdateVerificationFlowBody{ + UpdateVerificationFlowWithCodeMethod: client.NewUpdateVerificationFlowWithCodeMethod("code"), } - submitFlowBody.UpdateVerificationFlowWithLinkMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateVerificationFlowWithCodeMethod.SetCsrfToken(csrfToken) + submitFlowBody.UpdateVerificationFlowWithCodeMethod.SetCode(verificationCode) apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() + _, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).Token(verificationCode).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) From 98c2d6d9cc94d47d91378a21477aa92ed921b175 Mon Sep 17 00:00:00 2001 From: krishna2803 Date: Wed, 6 Nov 2024 03:19:08 +0530 Subject: [PATCH 07/20] Bump kratos version to 1.3.1 and change `docker-compose` to `docker compose` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b8354e..8a48a16 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Enter the Kratos directory and Change the Kratos Version to v0.10.0 ```sh cd kratos - git checkout v0.10.0 + git checkout v1.3.1 ``` Download the dependencies @@ -110,5 +110,5 @@ Copy the Kratos config file and identity schema from nymeria Run the following command to use Kratos in containerized form ```sh - docker-compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-postgres.yml up --build --force-recreate + docker compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-postgres.yml up --build --force-recreate ``` \ No newline at end of file From c481238d3d174cbd611a9c560bf8ee23523cfd9d Mon Sep 17 00:00:00 2001 From: Aryan Date: Sun, 22 Dec 2024 23:59:49 +0530 Subject: [PATCH 08/20] Fixes invite status not changing bug --- api/settings.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/settings.go b/api/settings.go index 79be25c..f7771b9 100644 --- a/api/settings.go +++ b/api/settings.go @@ -222,8 +222,6 @@ func HandleChangePassword(c *gin.Context) { return } - recovery_cookie, _ := c.Cookie("ory_kratos_session") - session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) @@ -238,10 +236,8 @@ func HandleChangePassword(c *gin.Context) { traits := identity.GetTraits() profile := traits.(map[string]interface{}) - if recovery_cookie != "" { - if profile["invite_status"] == "pending" { - profile["invite_status"] = "accepted" - } + if profile["invite_status"] == "pending" { + profile["invite_status"] = "accepted" } _, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, req_body.FlowID, req_body.CsrfToken, profile) From 0c8a5b7783f25b32d0849b6983ea617bc604cc24 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 00:34:06 +0530 Subject: [PATCH 09/20] Fixes bug where user can change his role --- api/settings.go | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/api/settings.go b/api/settings.go index f7771b9..bdb8b00 100644 --- a/api/settings.go +++ b/api/settings.go @@ -106,17 +106,6 @@ func HandleUpdateProfile(c *gin.Context) { var req_body settings.UpdateProfileAPIBody err := c.BindJSON(&req_body) - traitsinterface := map[string]interface{}{ - "email": req_body.Traits.Email, - "name": req_body.Traits.Name, - "img_url": req_body.Traits.ImgURL, - "phone_number": req_body.Traits.PhoneNumber, - "invite_status": req_body.Traits.InviteStatus, - "role": req_body.Traits.Role, - "created_at": req_body.Traits.Created_At, - "totp_enabled": req_body.Traits.TOTP_Enabled, - } - if err != nil { log.ErrorLogger("Unable to process json body", err) @@ -128,6 +117,31 @@ func HandleUpdateProfile(c *gin.Context) { return } + session, err := middleware.GetSession(c) + if err != nil { + log.ErrorLogger("Unable to get session", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to get session", + }) + return + } + identity := session.GetIdentity() + traits := identity.GetTraits() + profile := traits.(map[string]interface{}) + + traitsinterface := map[string]interface{}{ + "email": profile["email"], + "name": req_body.Traits.Name, + "img_url": req_body.Traits.ImgURL, + "phone_number": req_body.Traits.PhoneNumber, + "invite_status": profile["invite_status"], + "role": profile["role"], + "created_at": profile["created_at"], + "totp_enabled": profile["totp_enabled"], + } + flow_cookie, err := c.Cookie("settings_flow") if err != nil { log.ErrorLogger("Flow Cookie not found", err) From 962f958bf37d3c09e5e09e5a5ef6a9e96e36cf49 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 00:39:27 +0530 Subject: [PATCH 10/20] Changes endpoints case --- api/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/main.go b/api/main.go index c05dcf7..95f31bc 100644 --- a/api/main.go +++ b/api/main.go @@ -57,9 +57,9 @@ func Start() { r.POST("/recovery-code", HandlePostRecoveryCodeFlow) r.GET("/settings", HandleGetSettingsFlow) - r.POST("/updateprofile", HandleUpdateProfile) - r.POST("/changepassword", HandleChangePassword) - r.POST("/toggletotp", HandleToggleTOTP) + r.POST("/update-profile", HandleUpdateProfile) + r.POST("/change-password", HandleChangePassword) + r.POST("/toggle-totp", HandleToggleTOTP) r.GET("/verification", HandleGetVerificationFlow) r.POST("/verification-after-registration", HandleGetVerificationAfterRegistrationFlow) From df33da414392a1dce8d8651a0e530dfffe45e656 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 00:45:42 +0530 Subject: [PATCH 11/20] Fixes bug where admin can delete itself --- api/admin.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/admin.go b/api/admin.go index 2316192..e05687d 100644 --- a/api/admin.go +++ b/api/admin.go @@ -11,6 +11,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/log" + "github.com/sdslabs/nymeria/pkg/middleware" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" ) @@ -110,6 +111,27 @@ func HandleDeleteIdentityFlow(c *gin.Context) { return } + session, err := middleware.GetSession(c) + if err != nil { + log.ErrorLogger("Unable to get session", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to get session", + }) + return + } + identity := session.GetIdentity() + id := identity.GetId() + + if id == t.Identity { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Bad request", + "message": "Cannot delete own identity", + }) + return + } + r, err := admin.DeleteIdentityFlowWrapper(t.Identity) if err != nil { From 6d574900cb6b28423d11e98d872f43dc729bef9f Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 00:52:39 +0530 Subject: [PATCH 12/20] Fixes bug where admin can ban itself --- api/admin.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/api/admin.go b/api/admin.go index e05687d..9807879 100644 --- a/api/admin.go +++ b/api/admin.go @@ -178,6 +178,27 @@ func HandleBanIdentity(c *gin.Context) { return } + session, err := middleware.GetSession(c) + if err != nil { + log.ErrorLogger("Unable to get session", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to get session", + }) + return + } + identity := session.GetIdentity() + identityId := identity.GetId() + + if identityId == t.Identity { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Bad request", + "message": "Cannot ban own identity", + }) + return + } + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) if err != nil { @@ -260,6 +281,27 @@ func HandleRoleSwitch(c *gin.Context) { return } + session, err := middleware.GetSession(c) + if err != nil { + log.ErrorLogger("Unable to get session", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Unable to get session", + }) + return + } + identity := session.GetIdentity() + identityId := identity.GetId() + + if identityId == t.Identity { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Bad request", + "message": "Cannot switch own role", + }) + return + } + identityResult, r, err := admin.GetIdentityFlowWrapper(t.Identity) if err != nil { From 1f0b2927691282f6b6aad403190599c48128babb Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 01:25:14 +0530 Subject: [PATCH 13/20] Fixes empty verification flow id bug --- api/registration.go | 1 - pkg/wrapper/kratos/registration/registration.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/api/registration.go b/api/registration.go index 2e8b706..c117000 100644 --- a/api/registration.go +++ b/api/registration.go @@ -78,5 +78,4 @@ func HandlePostRegistrationFlow(c *gin.Context) { "status": "created", "flowID": flowID, }) - } diff --git a/pkg/wrapper/kratos/registration/registration.go b/pkg/wrapper/kratos/registration/registration.go index 65b7c79..ed82ab2 100644 --- a/pkg/wrapper/kratos/registration/registration.go +++ b/pkg/wrapper/kratos/registration/registration.go @@ -65,5 +65,5 @@ func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken strin responseCookies := r.Header["Set-Cookie"] - return resp.GetContinueWith()[0].ContinueWithVerificationUi.GetFlow().Id, responseCookies, nil + return resp.GetContinueWith()[1].ContinueWithVerificationUi.GetFlow().Id, responseCookies, nil } From 2e7ca604aef727634d2a18b93f89199365493f78 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 02:14:22 +0530 Subject: [PATCH 14/20] Fixes bug verification code never wrong --- api/verification.go | 7 ++++++- pkg/wrapper/kratos/verification/verification.go | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/api/verification.go b/api/verification.go index 11325f4..261126b 100644 --- a/api/verification.go +++ b/api/verification.go @@ -150,11 +150,16 @@ func HandlePostVerificationCodeFlow(c *gin.Context) { return } - _, err = verification.SubmitVerificationCodeFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.VerificationCode) + err = verification.SubmitVerificationCodeFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.VerificationCode) if err != nil { log.ErrorLogger("Post Verification flow failed", err) errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + + if errCode == 0 { + errCode = http.StatusBadRequest + } + c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Post Settings flow failed", diff --git a/pkg/wrapper/kratos/verification/verification.go b/pkg/wrapper/kratos/verification/verification.go index 1a5e6dd..29692bf 100644 --- a/pkg/wrapper/kratos/verification/verification.go +++ b/pkg/wrapper/kratos/verification/verification.go @@ -88,7 +88,7 @@ func SubmitVerificationFlowWrapper(cookie string, flowID string, csrfToken strin return csrf_token, nil } -func SubmitVerificationCodeFlowWrapper(cookie string, flowID string, csrfToken string, verificationCode string) (string, error) { +func SubmitVerificationCodeFlowWrapper(cookie string, flowID string, csrfToken string, verificationCode string) error { submitFlowBody := client.UpdateVerificationFlowBody{ UpdateVerificationFlowWithCodeMethod: client.NewUpdateVerificationFlowWithCodeMethod("code"), @@ -99,13 +99,20 @@ func SubmitVerificationCodeFlowWrapper(cookie string, flowID string, csrfToken s apiClient := client.NewAPIClient(config.KratosClientConfig) - _, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).Token(verificationCode).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() + resp, r, err := apiClient.FrontendAPI.UpdateVerificationFlow(context.Background()).Flow(flowID).Token(verificationCode).UpdateVerificationFlowBody(submitFlowBody).Cookie(cookie).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - return "", err + return err + } + + if resp.Ui.Messages[len(resp.Ui.Messages)-1].Text == "The verification code is invalid or has already been used. Please try again." { + fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceVerificationFlow``: %v\n", "The verification code is invalid or has already been used. Please try again.") + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + + return fmt.Errorf("the verification code is invalid or has already been used") } - return "", nil + return nil } From b7b1251a1d8b4466c4d2b4c3a74468f7b7855747 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 02:18:06 +0530 Subject: [PATCH 15/20] Fixes linting issues --- config/parser.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/parser.go b/config/parser.go index e24b6b8..1e25652 100644 --- a/config/parser.go +++ b/config/parser.go @@ -1,16 +1,16 @@ package config import ( - "io/ioutil" "log" + "os" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" ) func getConf() *NymeriaCfg { c := &NymeriaCfg{} - yamlFile, err := ioutil.ReadFile("config.yaml") + yamlFile, err := os.ReadFile("config.yaml") if err != nil { log.Printf("yamlFile.Get err #%v ", err) } From 02b808ef35732c804b279db5e368322ab79a7a4e Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 16:50:14 +0530 Subject: [PATCH 16/20] Merges redundant verification route --- api/main.go | 1 - api/registration.go | 18 ++++++++++++++++-- api/verification.go | 43 ------------------------------------------- 3 files changed, 16 insertions(+), 46 deletions(-) diff --git a/api/main.go b/api/main.go index 95f31bc..4d04ce7 100644 --- a/api/main.go +++ b/api/main.go @@ -62,7 +62,6 @@ func Start() { r.POST("/toggle-totp", HandleToggleTOTP) r.GET("/verification", HandleGetVerificationFlow) - r.POST("/verification-after-registration", HandleGetVerificationAfterRegistrationFlow) r.POST("/verification", HandlePostVerificationFlow) r.POST("/verification-code", HandlePostVerificationCodeFlow) diff --git a/api/registration.go b/api/registration.go index c117000..039c50a 100644 --- a/api/registration.go +++ b/api/registration.go @@ -10,6 +10,7 @@ import ( "github.com/sdslabs/nymeria/config" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/registration" + "github.com/sdslabs/nymeria/pkg/wrapper/kratos/verification" ) func HandleGetRegistrationFlow(c *gin.Context) { @@ -72,10 +73,23 @@ func HandlePostRegistrationFlow(c *gin.Context) { return } + csrf_token, err := verification.InitializeVerificationAfterRegistrationFlowWrapper(sessionCookies[0], flowID) + + if err != nil { + log.ErrorLogger("Initialize Verification Failed", err) + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), + "message": "Initialize Verification Failed", + }) + return + } + c.SetCookie("verification_flow", sessionCookies[0], 3600, "/", config.NymeriaConfig.URL.Domain, true, true) c.SetCookie("sdslabs_session", sessionCookies[1], 3600, "/", config.NymeriaConfig.URL.Domain, true, true) c.JSON(http.StatusOK, gin.H{ - "status": "created", - "flowID": flowID, + "status": "created", + "flowID": flowID, + "csrf_token": csrf_token, }) } diff --git a/api/verification.go b/api/verification.go index 261126b..c873b09 100644 --- a/api/verification.go +++ b/api/verification.go @@ -35,49 +35,6 @@ func HandleGetVerificationFlow(c *gin.Context) { }) } -func HandleGetVerificationAfterRegistrationFlow(c *gin.Context) { - var t verification.SubmitVerificationBody - err := c.Bind(&t) - - if err != nil { - log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to process json body", - }) - return - } - - cookie, err := c.Cookie("verification_flow") - - if err != nil { - log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Cookie not found", - }) - return - } - - csrf_token, err := verification.InitializeVerificationAfterRegistrationFlowWrapper(cookie, t.FlowID) - - if err != nil { - log.ErrorLogger("Initialize Verification Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Initialize Verification Failed", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "csrf_token": csrf_token, - }) -} - func HandlePostVerificationFlow(c *gin.Context) { var t verification.SubmitVerificationBody err := c.Bind(&t) From 87a7bff550ed5bcb1ed6e353ea2fa639886bef29 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 16:50:39 +0530 Subject: [PATCH 17/20] FIXES: TOTP --- api/login.go | 12 ++++++++++-- api/settings.go | 30 +++--------------------------- pkg/wrapper/kratos/login/login.go | 10 +++++++--- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/api/login.go b/api/login.go index a6d2ebc..457f0f7 100644 --- a/api/login.go +++ b/api/login.go @@ -65,7 +65,7 @@ func HandlePostLoginFlow(c *gin.Context) { identity, session, err := login.SubmitLoginFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Identifier) // _ is USERID - if err != nil { + if session == "" { log.ErrorLogger("Post login flow failed", err) errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0]) @@ -75,8 +75,16 @@ func HandlePostLoginFlow(c *gin.Context) { }) return } - c.SetCookie("sdslabs_session", session, 3600, "/", config.NymeriaConfig.URL.Domain, true, true) + + if err != nil { + c.JSON(http.StatusOK, gin.H{ + "status": "aal1 done", + "person": nil, + }) + return + } + c.JSON(http.StatusOK, gin.H{ "status": "user logged in", "person": identity, diff --git a/api/settings.go b/api/settings.go index bdb8b00..df317f5 100644 --- a/api/settings.go +++ b/api/settings.go @@ -31,8 +31,9 @@ func HandleGetSettingsFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Settings flow Failed", err) - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "internal server error", + errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + c.JSON(errCode, gin.H{ + "error": err.Error(), }) return } @@ -69,31 +70,6 @@ func HandleGetSettingsFlow(c *gin.Context) { } } - session, err := middleware.GetSession(c) - if err != nil { - log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Unable to get session", - }) - return - } - identity := session.GetIdentity() - traits := identity.GetTraits().(map[string]interface{}) - - _, err = settings.SubmitSettingsFlowProfileMethod(flow_cookie, session_cookie, flowID, csrf_token, traits) - if err != nil { - log.ErrorLogger("Kratos post settings update profile flow failed", err) - - errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0]) - c.JSON(errCode, gin.H{ - "error": err.Error(), - "message": "Kratos post settings update profile flow failed", - }) - return - } - c.JSON(http.StatusOK, gin.H{ "flowID": flowID, "csrf_token": csrf_token, diff --git a/pkg/wrapper/kratos/login/login.go b/pkg/wrapper/kratos/login/login.go index 62a1d14..ddbd3d6 100644 --- a/pkg/wrapper/kratos/login/login.go +++ b/pkg/wrapper/kratos/login/login.go @@ -42,12 +42,16 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass apiClient := client.NewAPIClient(config.KratosClientConfig) resp, r, err := apiClient.FrontendAPI.UpdateLoginFlow(context.Background()).Cookie(cookie).Flow(flowID).XSessionToken("").UpdateLoginFlowBody(submitDataBody).Execute() - if err != nil { - return *client.NewSessionWithDefaults(), "", err - } responseCookies := r.Header["Set-Cookie"] + if err != nil { + if responseCookies == nil { + return *client.NewSessionWithDefaults(), "", err + } + return *client.NewSessionWithDefaults(), responseCookies[1], err + } + return resp.Session, responseCookies[1], nil } From df29f287c8c184b043b06c3499517b1a76e2eb4d Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 20:04:47 +0530 Subject: [PATCH 18/20] Adds migrations to makefile --- Makefile | 17 ++++++++++++++++- db/migrations/000001_init_schema.up.sql | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b9d2370..6ba5fb6 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,15 @@ GOIMPORTS := $(GOPATH_BIN)/goimports GO_PACKAGES = $(shell go list ./... | grep -v vendor) PACKAGE_BASE := github.com/sdslabs/nymeria +DB_HOST = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'host:' | sed -n 's/.*host: *"\?\([^"]*\)"\?/\1/p') +DB_PORT = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'port:' | sed -n 's/.*port: *"\?\([^"]*\)"\?/\1/p') +DB_USER = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'user:' | sed -n 's/.*user: *"\?\([^"]*\)"\?/\1/p') +DB_PASS = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'password:' | sed -n 's/.*password: *"\?\([^"]*\)"\?/\1/p') +DB_NAME = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'db_name:' | sed -n 's/.*db_name: *"\?\([^"]*\)"\?/\1/p') + +UP_MIGRATION_FILE = db/migrations/000001_init_schema.up.sql +DOWN_MIGRATION_FILE = db/migrations/000001_init_schema.down.sql + .PHONY: help vendor build run dev lint format clean help: @@ -73,4 +82,10 @@ install-air: @curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(GOPATH_BIN) @echo "Air installed successfully" - \ No newline at end of file +apply-migration: + @echo "Applying migration..." + PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(UP_MIGRATION_FILE) + +rollback-migration: + @echo "Rolling back migration..." + PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(DOWN_MIGRATION_FILE) \ No newline at end of file diff --git a/db/migrations/000001_init_schema.up.sql b/db/migrations/000001_init_schema.up.sql index 26aed82..6c0a1b1 100644 --- a/db/migrations/000001_init_schema.up.sql +++ b/db/migrations/000001_init_schema.up.sql @@ -6,5 +6,5 @@ CREATE TABLE IF NOT EXISTS application ( ORGANIZATION VARCHAR(255), CREATED_AT TIMESTAMP, CLIENT_KEY VARCHAR(255), - CLIENT_SECRET TEXT, + CLIENT_SECRET TEXT ); \ No newline at end of file From b205949841d2120544c5c16ff0cdd9065579f3c3 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 23 Dec 2024 22:55:12 +0530 Subject: [PATCH 19/20] Fixes extra parameter in application --- pkg/db/application.go | 4 ++-- pkg/db/types.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/db/application.go b/pkg/db/application.go index 5b82661..5726c54 100644 --- a/pkg/db/application.go +++ b/pkg/db/application.go @@ -80,7 +80,7 @@ func GetAllApplication() ([]Application, error) { for rows.Next() { var t Application - err = rows.Scan(&t.ID, &t.Name, &t.RedirectURL, &t.AllowedDomains, &t.UpdatedAt, &t.Organization, &t.CreatedAt, &t.ClientKey, &t.ClientSecret) + err = rows.Scan(&t.ID, &t.Name, &t.RedirectURL, &t.AllowedDomains, &t.Organization, &t.CreatedAt, &t.ClientKey, &t.ClientSecret) if err != nil { return nil, err } @@ -122,7 +122,7 @@ func GetApplication(client_key string, client_secret string) (Application, error var t Application - err = db.QueryRow(sqlStatement, client_key, client_secret).Scan(&t.ID, &t.Name, &t.RedirectURL, &t.AllowedDomains, &t.UpdatedAt, &t.Organization, &t.CreatedAt, &t.ClientKey, &t.ClientSecret) + err = db.QueryRow(sqlStatement, client_key, client_secret).Scan(&t.ID, &t.Name, &t.RedirectURL, &t.AllowedDomains, &t.Organization, &t.CreatedAt, &t.ClientKey, &t.ClientSecret) if err != nil { return Application{}, err diff --git a/pkg/db/types.go b/pkg/db/types.go index b87ad0d..625084a 100644 --- a/pkg/db/types.go +++ b/pkg/db/types.go @@ -5,7 +5,6 @@ type Application struct { Name string `json:"name"` RedirectURL string `json:"redirect_url"` AllowedDomains string `json:"allowed_domains"` - UpdatedAt string `json:"updated_at"` Organization string `json:"organization"` CreatedAt string `json:"created_at"` ClientKey string `json:"client_key"` From e7316de6529b4dd069bfaf914963bce14a22f173 Mon Sep 17 00:00:00 2001 From: Aryan Date: Tue, 24 Dec 2024 02:50:56 +0530 Subject: [PATCH 20/20] Adds error message extractor --- api/admin.go | 23 +++++---- api/application.go | 10 ++-- api/login.go | 12 +++-- api/logout.go | 13 +++-- api/mfa.go | 6 +-- api/profile.go | 7 ++- api/recovery.go | 17 +++---- api/registration.go | 22 +++++---- api/settings.go | 29 +++++------ api/verification.go | 17 +++---- helper/extracter.go | 49 +++++++++++++++++++ helper/types.go | 9 ++++ pkg/db/application.go | 4 +- pkg/middleware/app_authorization.go | 12 ++--- pkg/wrapper/kratos/login/login.go | 10 ++-- .../kratos/registration/registration.go | 13 +++-- 16 files changed, 156 insertions(+), 97 deletions(-) create mode 100644 helper/extracter.go create mode 100644 helper/types.go diff --git a/api/admin.go b/api/admin.go index 9807879..20956f4 100644 --- a/api/admin.go +++ b/api/admin.go @@ -5,11 +5,10 @@ import ( "fmt" "net/http" "os" - "strconv" - "strings" "github.com/gin-gonic/gin" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/middleware" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/admin" @@ -24,7 +23,7 @@ func HandleCreateIdentityFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process JSON body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process JSON body", @@ -65,7 +64,7 @@ func HandleGetIdentityFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to convert map to json", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to convert map to json", @@ -80,7 +79,7 @@ func HandleGetIdentityFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to convert JSON to map", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to convert JSON to map", @@ -103,7 +102,7 @@ func HandleDeleteIdentityFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process JSON body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process JSON body", @@ -114,7 +113,7 @@ func HandleDeleteIdentityFlow(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", @@ -170,7 +169,7 @@ func HandleBanIdentity(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process JSON body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process JSON body", @@ -181,7 +180,7 @@ func HandleBanIdentity(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", @@ -232,7 +231,7 @@ func HandleRemoveBanIdentity(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process JSON body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process JSON body", @@ -273,7 +272,7 @@ func HandleRoleSwitch(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process JSON body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process JSON body", @@ -284,7 +283,7 @@ func HandleRoleSwitch(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", diff --git a/api/application.go b/api/application.go index b3ad702..8de3c53 100644 --- a/api/application.go +++ b/api/application.go @@ -18,7 +18,7 @@ func HandleGetApplication(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to get application data", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to get application data", @@ -39,7 +39,7 @@ func HandlePostApplication(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to process json body", @@ -73,7 +73,7 @@ func HandlePutApplication(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to process json body", @@ -107,7 +107,7 @@ func HandleDeleteApplication(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to process json body", @@ -141,7 +141,7 @@ func HandleUpdateClientSecret(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to process json body", diff --git a/api/login.go b/api/login.go index 457f0f7..c076044 100644 --- a/api/login.go +++ b/api/login.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/login" ) @@ -19,7 +20,8 @@ func HandleGetLoginFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Login Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) + c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Initialize Login Failed", @@ -42,7 +44,7 @@ func HandlePostLoginFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -55,7 +57,7 @@ func HandlePostLoginFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -63,7 +65,7 @@ func HandlePostLoginFlow(c *gin.Context) { return } - identity, session, err := login.SubmitLoginFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Identifier) // _ is USERID + identity, session, errMsg, err := login.SubmitLoginFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Identifier) // _ is USERID if session == "" { log.ErrorLogger("Post login flow failed", err) @@ -71,7 +73,7 @@ func HandlePostLoginFlow(c *gin.Context) { errCode, _ := strconv.Atoi((strings.Split(err.Error(), " "))[0]) c.JSON(errCode, gin.H{ "error": err.Error(), - "message": "Kratos post login flow failed", + "message": errMsg, }) return } diff --git a/api/logout.go b/api/logout.go index be24203..d0ea51f 100644 --- a/api/logout.go +++ b/api/logout.go @@ -2,12 +2,11 @@ package api import ( "net/http" - "strconv" - "strings" "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/logout" ) @@ -17,7 +16,7 @@ func HandleGetLogoutFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Session cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Session cookie not found", @@ -29,7 +28,7 @@ func HandleGetLogoutFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Kratos get logout flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Kratos get logout flow failed", @@ -49,7 +48,7 @@ func HandlePostLogoutFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -61,7 +60,7 @@ func HandlePostLogoutFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Session cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Session cookie not found", @@ -72,7 +71,7 @@ func HandlePostLogoutFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Kratos get logout flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Kratos get logout flow failed", diff --git a/api/mfa.go b/api/mfa.go index e70dd61..cdf7322 100644 --- a/api/mfa.go +++ b/api/mfa.go @@ -2,12 +2,12 @@ package api import ( "net/http" - "strconv" "strings" "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/login" ) @@ -19,7 +19,7 @@ func HandleGetMFAFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Session Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -72,7 +72,7 @@ func HandlePostMFAFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Session Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", diff --git a/api/profile.go b/api/profile.go index bfbde85..ebf2572 100644 --- a/api/profile.go +++ b/api/profile.go @@ -2,11 +2,10 @@ package api import ( "net/http" - "strconv" - "strings" "github.com/gin-gonic/gin" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/middleware" ) @@ -15,7 +14,7 @@ func HandlePostProfile(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", @@ -33,7 +32,7 @@ func HandleGetVerifiedStatus(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", diff --git a/api/recovery.go b/api/recovery.go index 3bd6b03..0474b46 100644 --- a/api/recovery.go +++ b/api/recovery.go @@ -2,12 +2,11 @@ package api import ( "net/http" - "strconv" - "strings" "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/recovery" ) @@ -19,7 +18,7 @@ func HandleGetRecoveryFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Recovery Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Initialize Recovery Failed", @@ -41,7 +40,7 @@ func HandlePostRecoveryFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -53,7 +52,7 @@ func HandlePostRecoveryFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -65,7 +64,7 @@ func HandlePostRecoveryFlow(c *gin.Context) { if err != nil { log.ErrorLogger("POST Recovery flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "POST Recovery flow failed", @@ -85,7 +84,7 @@ func HandlePostRecoveryCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -97,7 +96,7 @@ func HandlePostRecoveryCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Recovery Flow Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Recovery Flow Cookie not found", @@ -109,7 +108,7 @@ func HandlePostRecoveryCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("POST Recovery flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "POST Recovery Code flow failed", diff --git a/api/registration.go b/api/registration.go index 039c50a..6907ad0 100644 --- a/api/registration.go +++ b/api/registration.go @@ -2,12 +2,11 @@ package api import ( "net/http" - "strconv" - "strings" "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/registration" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/verification" @@ -18,7 +17,12 @@ func HandleGetRegistrationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Kratos get registration flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) + + if errCode == 0 { + errCode = http.StatusInternalServerError + } + c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Kratos get registration flow failed", @@ -41,7 +45,7 @@ func HandlePostRegistrationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -53,7 +57,7 @@ func HandlePostRegistrationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "cookie not found", @@ -61,14 +65,14 @@ func HandlePostRegistrationFlow(c *gin.Context) { return } - flowID, sessionCookies, err := registration.SubmitRegistrationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Traits) + flowID, sessionCookies, errMsg, err := registration.SubmitRegistrationFlowWrapper(cookie, t.FlowID, t.CsrfToken, t.Password, t.Traits) if err != nil { log.ErrorLogger("Kratos post registration flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), - "message": "Kratos post registration flow failed", + "message": errMsg, }) return } @@ -77,7 +81,7 @@ func HandlePostRegistrationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Verification Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Initialize Verification Failed", diff --git a/api/settings.go b/api/settings.go index df317f5..d2bd20d 100644 --- a/api/settings.go +++ b/api/settings.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/middleware" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/settings" @@ -19,7 +20,7 @@ func HandleGetSettingsFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Settings Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Initialize Settings Failed", @@ -31,7 +32,7 @@ func HandleGetSettingsFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Settings flow Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), }) @@ -85,7 +86,7 @@ func HandleUpdateProfile(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -96,7 +97,7 @@ func HandleUpdateProfile(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", @@ -122,7 +123,7 @@ func HandleUpdateProfile(c *gin.Context) { if err != nil { log.ErrorLogger("Flow Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -134,7 +135,7 @@ func HandleUpdateProfile(c *gin.Context) { if err != nil { log.ErrorLogger("Session Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -167,7 +168,7 @@ func HandleChangePassword(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -179,7 +180,7 @@ func HandleChangePassword(c *gin.Context) { if err != nil { log.ErrorLogger("Flow Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -191,7 +192,7 @@ func HandleChangePassword(c *gin.Context) { if err != nil { log.ErrorLogger("Session Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -215,7 +216,7 @@ func HandleChangePassword(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", @@ -253,7 +254,7 @@ func HandleToggleTOTP(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -265,7 +266,7 @@ func HandleToggleTOTP(c *gin.Context) { if err != nil { log.ErrorLogger("Flow Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -277,7 +278,7 @@ func HandleToggleTOTP(c *gin.Context) { if err != nil { log.ErrorLogger("Session Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -302,7 +303,7 @@ func HandleToggleTOTP(c *gin.Context) { session, err := middleware.GetSession(c) if err != nil { log.ErrorLogger("Unable to get session", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to get session", diff --git a/api/verification.go b/api/verification.go index c873b09..37845d4 100644 --- a/api/verification.go +++ b/api/verification.go @@ -2,12 +2,11 @@ package api import ( "net/http" - "strconv" - "strings" "github.com/gin-gonic/gin" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/wrapper/kratos/verification" ) @@ -19,7 +18,7 @@ func HandleGetVerificationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Initialize Verification Failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Initialize Verification Failed", @@ -41,7 +40,7 @@ func HandlePostVerificationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -53,7 +52,7 @@ func HandlePostVerificationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -67,7 +66,7 @@ func HandlePostVerificationFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Post Verification flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Post Settings flow failed", @@ -87,7 +86,7 @@ func HandlePostVerificationCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Unable to process json body", @@ -99,7 +98,7 @@ func HandlePostVerificationCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Cookie not found", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": err.Error(), "message": "Cookie not found", @@ -111,7 +110,7 @@ func HandlePostVerificationCodeFlow(c *gin.Context) { if err != nil { log.ErrorLogger("Post Verification flow failed", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) if errCode == 0 { errCode = http.StatusBadRequest diff --git a/helper/extracter.go b/helper/extracter.go new file mode 100644 index 0000000..a228b6a --- /dev/null +++ b/helper/extracter.go @@ -0,0 +1,49 @@ +package helper + +import ( + "encoding/json" + "io" + "net/http" + "strconv" + "strings" + + "github.com/sdslabs/nymeria/log" +) + +func ExtractErrorCode(Error error) int { + errCode, err := strconv.Atoi(strings.Split(Error.Error(), " ")[0]) + + if err != nil { + log.ErrorLogger("Error code extractor failed: ", err) + return http.StatusInternalServerError + } + + if errCode == 0 { + return http.StatusInternalServerError + } + return errCode +} + +func ExtractErrorMessage(r *http.Response) string { + + body, err := io.ReadAll(r.Body) + + if err != nil { + log.ErrorLogger("Error message extractor failed: ", err) + return "Error" + } + + var resp HttpResponseBody + err = json.Unmarshal(body, &resp) + + if err != nil { + log.ErrorLogger("Error message extractor failed: ", err) + return "Error" + } + + if len(resp.UI.Messages) == 0 { + return "Error" + } + + return resp.UI.Messages[0].Text +} diff --git a/helper/types.go b/helper/types.go new file mode 100644 index 0000000..185e2e8 --- /dev/null +++ b/helper/types.go @@ -0,0 +1,9 @@ +package helper + +type HttpResponseBody struct { + UI struct { + Messages []struct { + Text string `json:"text"` + } `json:"messages"` + } `json:"ui"` +} diff --git a/pkg/db/application.go b/pkg/db/application.go index 5726c54..7d96c9a 100644 --- a/pkg/db/application.go +++ b/pkg/db/application.go @@ -1,8 +1,6 @@ package db -import ( - "github.com/sdslabs/nymeria/helper" -) +import "github.com/sdslabs/nymeria/helper" func CreateApplication(name string, redirectURL string, allowedDomains string, organization string, clientKey string, clientSecret string) error { sqlStatement := `INSERT INTO application (name, redirect_url, allowed_domains, organization, created_at, client_key, client_secret) VALUES ($1, $2, $3, $4, now(), $5,$6);` diff --git a/pkg/middleware/app_authorization.go b/pkg/middleware/app_authorization.go index b94c58e..f73bc98 100644 --- a/pkg/middleware/app_authorization.go +++ b/pkg/middleware/app_authorization.go @@ -1,11 +1,11 @@ package middleware import ( - "strconv" "strings" "github.com/gin-gonic/gin" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/log" "github.com/sdslabs/nymeria/pkg/db" ) @@ -15,7 +15,7 @@ func HandleAppAuthorization(c *gin.Context) { err := c.BindJSON(&body) if err != nil { log.ErrorLogger("Unable to process json body", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unable to process json body", @@ -25,7 +25,7 @@ func HandleAppAuthorization(c *gin.Context) { app, err := db.GetApplication(body.ClientKey, body.ClientSecret) if err != nil { log.ErrorLogger("Unable to get application", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Internal Server Error", @@ -34,7 +34,7 @@ func HandleAppAuthorization(c *gin.Context) { } if app.RedirectURL != body.RedirectURL { log.ErrorLogger("Redirect URL does not match", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Redirect URL does not match", @@ -43,7 +43,7 @@ func HandleAppAuthorization(c *gin.Context) { } if app.ClientKey != body.ClientKey { log.ErrorLogger("Client Key does not match", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unauthorized", @@ -52,7 +52,7 @@ func HandleAppAuthorization(c *gin.Context) { } if app.ClientSecret != body.ClientSecret { log.ErrorLogger("Client Secret does not match", err) - errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) + errCode := helper.ExtractErrorCode(err) c.JSON(errCode, gin.H{ "error": strings.Split(err.Error(), " ")[1], "message": "Unauthorized", diff --git a/pkg/wrapper/kratos/login/login.go b/pkg/wrapper/kratos/login/login.go index ddbd3d6..6d443b6 100644 --- a/pkg/wrapper/kratos/login/login.go +++ b/pkg/wrapper/kratos/login/login.go @@ -6,6 +6,7 @@ import ( client "github.com/ory/client-go" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" ) func InitializeLoginFlowWrapper(aal string, cookie string) (string, string, string, error) { @@ -34,7 +35,7 @@ func InitializeLoginFlowWrapper(aal string, cookie string) (string, string, stri return setCookie, resp.Id, csrf_token, nil } -func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass string, identifier string) (client.Session, string, error) { +func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass string, identifier string) (client.Session, string, string, error) { submitDataBody := client.UpdateLoginFlowBody{UpdateLoginFlowWithPasswordMethod: client.NewUpdateLoginFlowWithPasswordMethod(identifier, "password", pass)} // SubmitSelfServiceLoginFlowBody | submitDataBody.UpdateLoginFlowWithPasswordMethod.SetCsrfToken(csrfToken) @@ -47,12 +48,13 @@ func SubmitLoginFlowWrapper(cookie string, flowID string, csrfToken string, pass if err != nil { if responseCookies == nil { - return *client.NewSessionWithDefaults(), "", err + msg := helper.ExtractErrorMessage(r) + return *client.NewSessionWithDefaults(), "", msg, err } - return *client.NewSessionWithDefaults(), responseCookies[1], err + return *client.NewSessionWithDefaults(), responseCookies[1], "", err } - return resp.Session, responseCookies[1], nil + return resp.Session, responseCookies[1], "", nil } func SubmitLoginWithMFAWrapper(cookie string, flowID string, csrfToken string, totp string) (client.Session, string, error) { diff --git a/pkg/wrapper/kratos/registration/registration.go b/pkg/wrapper/kratos/registration/registration.go index ed82ab2..5c476e1 100644 --- a/pkg/wrapper/kratos/registration/registration.go +++ b/pkg/wrapper/kratos/registration/registration.go @@ -2,12 +2,11 @@ package registration import ( "context" - "fmt" - "os" client "github.com/ory/client-go" "github.com/sdslabs/nymeria/config" + "github.com/sdslabs/nymeria/helper" "github.com/sdslabs/nymeria/pkg/middleware" ) @@ -36,7 +35,7 @@ func InitializeRegistrationFlowWrapper() (string, string, string, error) { return setCookie, resp.Id, csrf_token, nil } -func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken string, password string, data Traits) (string, []string, error) { +func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken string, password string, data Traits) (string, []string, string, error) { timeStamp := middleware.CurrentTimeStamp() trait := map[string]interface{}{ "email": data.Email, @@ -58,12 +57,12 @@ func SubmitRegistrationFlowWrapper(cookie string, flowID string, csrfToken strin resp, r, err := apiClient.FrontendAPI.UpdateRegistrationFlow(context.Background()).Flow(flowID).UpdateRegistrationFlowBody(submitDataBody).Cookie(cookie).Execute() if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `V0alpha2Api.SubmitSelfServiceRegistrationFlow``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - return "", nil, err + msg := helper.ExtractErrorMessage(r) + + return "", nil, msg, err } responseCookies := r.Header["Set-Cookie"] - return resp.GetContinueWith()[1].ContinueWithVerificationUi.GetFlow().Id, responseCookies, nil + return resp.GetContinueWith()[1].ContinueWithVerificationUi.GetFlow().Id, responseCookies, "", nil }