diff --git a/config-example.yaml b/config-example.yaml index cd19c45..afc71c8 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -16,3 +16,6 @@ running_periods: db: url: postgres://link:link@localhost:15432/link-db?sslmode=disable + +auth: + addr: auth-svc:8000 \ No newline at end of file diff --git a/docs/spec/components/schemas/ProofCreate.yaml b/docs/spec/components/schemas/ProofCreate.yaml index f2f7218..96bd0e3 100644 --- a/docs/spec/components/schemas/ProofCreate.yaml +++ b/docs/spec/components/schemas/ProofCreate.yaml @@ -3,8 +3,12 @@ required: - proof - proof_type - org_id + - user_did - schema_url properties: + user_did: + type: string + description: The user DID proof: type: string description: The proof object in JSON string format diff --git a/docs/spec/paths/v1@links.yaml b/docs/spec/paths/v1@links.yaml index e63b674..0bf2460 100644 --- a/docs/spec/paths/v1@links.yaml +++ b/docs/spec/paths/v1@links.yaml @@ -17,6 +17,9 @@ post: data: type: object properties: + user_did: + type: string + description: User DID that owns all selected proofs proofs_ids: type: array items: diff --git a/docs/spec/paths/v1@links@{link_id}.yaml b/docs/spec/paths/v1@links@{link_id}.yaml index 6ba0bd5..ff485f9 100644 --- a/docs/spec/paths/v1@links@{link_id}.yaml +++ b/docs/spec/paths/v1@links@{link_id}.yaml @@ -3,8 +3,6 @@ get: description: > Returns information about the all proofs of the link. operationId: proofsByLinkID - security: - - Bearer: [ ] tags: - Proofs parameters: diff --git a/docs/spec/paths/v1@proofs@{id}.yaml b/docs/spec/paths/v1@proofs@{id}.yaml index 6fae47e..0b96eff 100644 --- a/docs/spec/paths/v1@proofs@{id}.yaml +++ b/docs/spec/paths/v1@proofs@{id}.yaml @@ -3,6 +3,8 @@ get: description: > Returns information about the particular proof. operationId: proofByID + security: + - Bearer: [ ] tags: - Proofs parameters: diff --git a/go.mod b/go.mod index e267d5e..005b0e4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rarimo/rarime-link-svc -go 1.20 +go 1.21.0 require ( github.com/Masterminds/squirrel v1.4.0 @@ -8,6 +8,7 @@ require ( github.com/go-chi/chi v4.1.2+incompatible github.com/go-ozzo/ozzo-validation/v4 v4.2.1 github.com/google/uuid v1.3.0 + github.com/rarimo/rarime-auth-svc v0.0.0-20240112133056-5c14a530b15f github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a github.com/rubenv/sql-migrate v1.5.2 gitlab.com/distributed_lab/ape v1.7.1 @@ -23,14 +24,16 @@ require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect + github.com/ethereum/go-ethereum v1.13.8 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/getsentry/raven-go v0.2.0 // indirect github.com/getsentry/sentry-go v0.7.0 // indirect github.com/go-errors/errors v1.5.1 // indirect github.com/go-gorp/gorp/v3 v3.1.0 // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/holiman/uint256 v1.2.4 // indirect github.com/jmoiron/sqlx v1.2.0 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect @@ -46,11 +49,9 @@ require ( github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.3.2 // indirect - github.com/stretchr/testify v1.8.4 // indirect gitlab.com/distributed_lab/lorem v0.2.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 8614e3f..a142b6f 100644 --- a/go.sum +++ b/go.sum @@ -35,10 +35,13 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= +github.com/ethereum/go-ethereum v1.13.8 h1:1od+thJel3tM52ZUNQwvpYOeRHlbkVFZ5S8fhi0Lgsg= +github.com/ethereum/go-ethereum v1.13.8/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= @@ -62,12 +65,18 @@ github.com/go-ozzo/ozzo-validation/v4 v4.2.1 h1:XALUNshPYumA7UShB7iM3ZVlqIBn0jfw github.com/go-ozzo/ozzo-validation/v4 v4.2.1/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34HU= +github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs= github.com/gobuffalo/packd v1.0.1 h1:U2wXfRr4E9DH8IdsDLlRFwTZTK7hLfq9qT/QHXGVe/0= +github.com/gobuffalo/packd v1.0.1/go.mod h1:PP2POP3p3RXGz7Jh6eYEf93S7vA2za6xM7QT85L4+VY= github.com/gobuffalo/packr/v2 v2.8.3 h1:xE1yzvnO56cUC0sTpKR3DIbxZgB54AftTFMhB2XEWlY= +github.com/gobuffalo/packr/v2 v2.8.3/go.mod h1:0SahksCVcx4IMnigTjiFuyldmTrdTctXsOdiU5KwbKc= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= +github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw= +github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= 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/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= @@ -84,6 +93,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= +github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -100,6 +111,7 @@ github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVE github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= +github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk= github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U= github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw= @@ -110,9 +122,11 @@ github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 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/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= @@ -126,14 +140,18 @@ github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= +github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= +github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= +github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg= github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ= @@ -163,9 +181,13 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE 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/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= +github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= +github.com/rarimo/rarime-auth-svc v0.0.0-20240112133056-5c14a530b15f h1:lnf2esmQAAN52nbG1c2v5+SCWIq6xheF9HfgBZjhR2Q= +github.com/rarimo/rarime-auth-svc v0.0.0-20240112133056-5c14a530b15f/go.mod h1:xtjHOQwPlTBnTa6hveACLtxjpxCcznjQB84+FmjFRBM= github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a h1:aqz/1mU+rK/xLqf2/NHu+0fUGbVNf+9DYFI70fQo0M0= github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a/go.mod h1:EYFR6RRqIlnpjcl/SgPgYn8Bmw4+5itRRbPCiSylCds= 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/rubenv/sql-migrate v1.5.2 h1:bMDqOnrJVV/6JQgQ/MxOpU+AdO8uzYYA/TxFUBzFtS0= github.com/rubenv/sql-migrate v1.5.2/go.mod h1:H38GW8Vqf8F0Su5XignRyaRcbXbJunSWxs+kmzlg0Is= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -235,8 +257,8 @@ gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312/go.mod h1:vdlhN5/oQ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -247,8 +269,8 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -262,14 +284,15 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/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.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -278,6 +301,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/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/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= @@ -290,3 +314,6 @@ 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/internal/config/main.go b/internal/config/main.go index 41854e2..bdbf0f6 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -1,6 +1,7 @@ package config import ( + "github.com/rarimo/rarime-auth-svc/pkg/auth" "github.com/rarimo/rarime-link-svc/internal/data" "github.com/rarimo/rarime-link-svc/internal/data/pg" "gitlab.com/distributed_lab/kit/comfig" @@ -13,6 +14,7 @@ type Config interface { comfig.Logger comfig.Listenerer pgdb.Databaser + auth.Auther LinkConfiger RunningPeriods SubServices @@ -24,6 +26,7 @@ type config struct { pgdb.Databaser types.Copuser comfig.Listenerer + auth.Auther LinkConfiger RunningPeriods SubServices @@ -40,6 +43,7 @@ func New(getter kv.Getter) Config { RunningPeriods: NewRunningPeriods(getter), SubServices: NewSubServices(), Databaser: pgdb.NewDatabaser(getter), + Auther: auth.NewAuther(getter), } } diff --git a/internal/services/api/handlers/create_proof.go b/internal/services/api/handlers/create_proof.go index d2060c7..15c669e 100644 --- a/internal/services/api/handlers/create_proof.go +++ b/internal/services/api/handlers/create_proof.go @@ -7,6 +7,7 @@ import ( validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/google/uuid" + "github.com/rarimo/rarime-auth-svc/pkg/auth" "github.com/rarimo/rarime-link-svc/internal/data" "github.com/rarimo/rarime-link-svc/resources" "gitlab.com/distributed_lab/ape" @@ -47,6 +48,11 @@ func CreateProof(w http.ResponseWriter, r *http.Request) { return } + if !auth.Authenticates(UserClaim(r), auth.UserGrant(req.Data.UserDid)) { + ape.RenderErr(w, problems.Unauthorized()) + return + } + orgID, err := uuid.Parse(req.Data.OrgId) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) @@ -55,7 +61,7 @@ func CreateProof(w http.ResponseWriter, r *http.Request) { proof := data.Proof{ ID: uuid.New(), - Creator: UserID(r), + Creator: req.Data.UserDid, CreatedAt: time.Now().UTC(), Proof: []byte(req.Data.Proof), Type: req.Data.ProofType, diff --git a/internal/services/api/handlers/create_proof_link.go b/internal/services/api/handlers/create_proof_link.go index d80a4bf..b79d56d 100644 --- a/internal/services/api/handlers/create_proof_link.go +++ b/internal/services/api/handlers/create_proof_link.go @@ -2,17 +2,20 @@ package handlers import ( "encoding/json" + "net/http" + "time" + "github.com/google/uuid" + "github.com/rarimo/rarime-auth-svc/pkg/auth" "github.com/rarimo/rarime-link-svc/internal/data" "github.com/rarimo/rarime-link-svc/resources" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" "gitlab.com/distributed_lab/logan/v3/errors" - "net/http" - "time" ) type ProofLink struct { + UserDID string `json:"user_did"` ProofsIds []uuid.UUID `json:"proofs_ids"` } @@ -37,17 +40,26 @@ func CreateProofLink(w http.ResponseWriter, r *http.Request) { return } - timestamp := time.Now().UTC() - linkID := uuid.New() + if !auth.Authenticates(UserClaim(r), auth.UserGrant(req.Data.UserDID)) { + ape.RenderErr(w, problems.Unauthorized()) + return + } - var proofs []data.Proof - err = Storage(r).LinkQ().Transaction(func(q data.LinkQ) error { + var ( + timestamp = time.Now().UTC() + linkID = uuid.New() + proofs []data.Proof + proofNotFound = errors.New("proof not found") + invalidCreator = errors.New("invalid proof creator") + ) + err = Storage(r).LinkQ().Transaction(func(q data.LinkQ) error { err = q.Insert(&data.Link{ ID: linkID, - UserID: UserID(r), + UserID: req.Data.UserDID, CreatedAt: timestamp, }) + if err != nil { ape.RenderErr(w, problems.InternalError()) return err @@ -60,28 +72,35 @@ func CreateProofLink(w http.ResponseWriter, r *http.Request) { return err } + if p == nil { + ape.RenderErr(w, problems.NotFound()) + return proofNotFound + } + + if p.Creator != req.Data.UserDID { + ape.RenderErr(w, problems.Unauthorized()) + return invalidCreator + } + proofs = append(proofs, *p) err = q.InsertCtxLinkToProof(r.Context(), data.LinksToProof{ LinkID: linkID, ProofID: proofID, }) + if err != nil { ape.RenderErr(w, problems.InternalError()) return err } } - if len(proofs) != len(req.Data.ProofsIds) { - ape.RenderErr(w, problems.BadRequest(errors.New("proofs not found"))...) - return errors.New("proofs not found") - } - return nil }) if err != nil { - ape.RenderErr(w, problems.InternalError()) + Log(r).WithError(err).Error("failed to create proof link entry") + // Response error rendered before return } diff --git a/internal/services/api/handlers/ctx.go b/internal/services/api/handlers/ctx.go index c7db131..3017688 100644 --- a/internal/services/api/handlers/ctx.go +++ b/internal/services/api/handlers/ctx.go @@ -2,9 +2,11 @@ package handlers import ( "context" + "net/http" + + "github.com/rarimo/rarime-auth-svc/resources" "github.com/rarimo/rarime-link-svc/internal/data" "gitlab.com/distributed_lab/logan/v3" - "net/http" ) type ctxKey int @@ -12,7 +14,7 @@ type ctxKey int const ( logCtxKey ctxKey = iota storageCtxKey - userIDCtxKey + userClaimCtxKey ) func CtxLog(entry *logan.Entry) func(context.Context) context.Context { @@ -35,12 +37,12 @@ func Storage(r *http.Request) data.Storage { return r.Context().Value(storageCtxKey).(data.Storage) } -func CtxUserID(userID string) func(context.Context) context.Context { +func CtxUserClaim(claim []resources.Claim) func(context.Context) context.Context { return func(ctx context.Context) context.Context { - return context.WithValue(ctx, userIDCtxKey, userID) + return context.WithValue(ctx, userClaimCtxKey, claim) } } -func UserID(r *http.Request) string { - return r.Context().Value(userIDCtxKey).(string) +func UserClaim(r *http.Request) []resources.Claim { + return r.Context().Value(userClaimCtxKey).([]resources.Claim) } diff --git a/internal/services/api/handlers/get_links_by_user.go b/internal/services/api/handlers/get_links_by_user.go index 3fda9ce..df472f3 100644 --- a/internal/services/api/handlers/get_links_by_user.go +++ b/internal/services/api/handlers/get_links_by_user.go @@ -2,6 +2,7 @@ package handlers import ( "context" + validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/rarimo/rarime-link-svc/resources" "gitlab.com/distributed_lab/ape" diff --git a/internal/services/api/handlers/get_proof.go b/internal/services/api/handlers/get_proof.go index b1e5b5b..9db2113 100644 --- a/internal/services/api/handlers/get_proof.go +++ b/internal/services/api/handlers/get_proof.go @@ -1,14 +1,16 @@ package handlers import ( + "net/http" + "github.com/go-chi/chi" validation "github.com/go-ozzo/ozzo-validation/v4" "github.com/google/uuid" + "github.com/rarimo/rarime-auth-svc/pkg/auth" "github.com/rarimo/rarime-link-svc/resources" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" "gitlab.com/distributed_lab/logan/v3/errors" - "net/http" ) type proofByIDRequest struct { @@ -46,6 +48,11 @@ func ProofByID(w http.ResponseWriter, r *http.Request) { return } + if !auth.Authenticates(UserClaim(r), auth.UserGrant(proof.Creator)) { + ape.RenderErr(w, problems.Unauthorized()) + return + } + ape.Render(w, resources.ProofResponse{ Data: resources.Proof{ Key: resources.Key{ diff --git a/internal/services/api/handlers/get_proofs_by_user.go b/internal/services/api/handlers/get_proofs_by_user.go index 6cd05a5..ff9a763 100644 --- a/internal/services/api/handlers/get_proofs_by_user.go +++ b/internal/services/api/handlers/get_proofs_by_user.go @@ -2,6 +2,7 @@ package handlers import ( validation "github.com/go-ozzo/ozzo-validation/v4" + "github.com/rarimo/rarime-auth-svc/pkg/auth" "github.com/rarimo/rarime-link-svc/resources" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" @@ -32,6 +33,11 @@ func GetProofs(w http.ResponseWriter, r *http.Request) { return } + if !auth.Authenticates(UserClaim(r), auth.UserGrant(req.UserDid)) { + ape.RenderErr(w, problems.Unauthorized()) + return + } + proofs, err := Storage(r).ProofQ().ProofsByCreatorCtx(r.Context(), req.UserDid) if err != nil { Log(r).WithError(err).Error("failed to get proofs") diff --git a/internal/services/api/handlers/middleware.go b/internal/services/api/handlers/middleware.go index 736ca6f..cc741f6 100644 --- a/internal/services/api/handlers/middleware.go +++ b/internal/services/api/handlers/middleware.go @@ -1,25 +1,31 @@ package handlers import ( - "context" + "net/http" + + "github.com/rarimo/rarime-auth-svc/pkg/auth" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" - "net/http" + "gitlab.com/distributed_lab/logan/v3" ) -func AuthMiddleware() func(http.Handler) http.Handler { +func AuthMiddleware(auth *auth.Client, log *logan.Entry) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // TODO: implement auth and user id extraction - userID := r.Header.Get("Authorization") - if userID == "" { - ape.Render(w, problems.Unauthorized()) + claims, status, err := auth.ValidateJWT(r.Header) + if err != nil { + if status == http.StatusUnauthorized { + ape.Render(w, problems.Unauthorized()) + return + } + + log.WithError(err).Error("failed to execute auth validate request") + ape.Render(w, problems.InternalError()) return } - r = r.WithContext(context.WithValue(r.Context(), userIDCtxKey, userID)) - - next.ServeHTTP(w, r) + ctx := CtxUserClaim(claims)(r.Context()) + next.ServeHTTP(w, r.WithContext(ctx)) }) } } diff --git a/internal/services/api/main.go b/internal/services/api/main.go index eeaf4d3..2dcf331 100644 --- a/internal/services/api/main.go +++ b/internal/services/api/main.go @@ -2,9 +2,10 @@ package api import ( "context" + "time" + "github.com/rarimo/rarime-link-svc/internal/services/proofs_cleaner" "gitlab.com/distributed_lab/logan/v3" - "time" "github.com/go-chi/chi" "github.com/rarimo/rarime-link-svc/internal/config" @@ -36,20 +37,24 @@ func Run(ctx context.Context, cfg config.Config) { r.Route("/v1", func(r chi.Router) { r.Route("/proofs", func(r chi.Router) { r.Group(func(r chi.Router) { - // TODO r.Use(handlers.AuthMiddleware()) + r.Use(handlers.AuthMiddleware(cfg.Auth(), cfg.Log())) r.Get("/", handlers.GetProofs) r.Post("/", handlers.CreateProof) }) + r.Route("/{id}", func(r chi.Router) { + r.Use(handlers.AuthMiddleware(cfg.Auth(), cfg.Log())) r.Get("/", handlers.ProofByID) }) }) + r.Route("/links", func(r chi.Router) { r.Group(func(r chi.Router) { - // TODO r.Use(handlers.AuthMiddleware()) + r.Use(handlers.AuthMiddleware(cfg.Auth(), cfg.Log())) r.Get("/", handlers.GetLinks) r.Post("/", handlers.CreateProofLink) }) + r.Route("/{link_id}", func(r chi.Router) { r.Get("/", handlers.GetLinkByID) }) diff --git a/resources/model_proof_create.go b/resources/model_proof_create.go index cce7254..b639c8a 100644 --- a/resources/model_proof_create.go +++ b/resources/model_proof_create.go @@ -11,6 +11,8 @@ type ProofCreate struct { Proof string `json:"proof"` // The type of the proof ProofType string `json:"proof_type"` + // The user DID + UserDid string `json:"user_did"` // The schema URL of the claim the proof was created based on SchemaUrl string `json:"schema_url"` }