Skip to content

Commit

Permalink
feat: implement auth (#3)
Browse files Browse the repository at this point in the history
* feat: implement auth

* chore: rename vars

---------

Co-authored-by: luzzifoss <[email protected]>
  • Loading branch information
luzzif and luzzifoss authored Jan 18, 2024
1 parent 01f7be6 commit 071d598
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
HOST="127.0.0.1"
PORT="1234"
JWT_SECRET="foo"
DB_CONNECTION_STRING="postgresql://user:[email protected]:5432/data-uploader"
W3UP_PRINCIPAL_KEY="foo"
W3UP_DELEGATION_PROOF="foo"
S3_ENDPOINT="http://foo.bar"
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ ENV HOST=$HOST
ARG PORT
ENV PORT=$PORT

ARG JWT_SECRET
ENV JWT_SECRET=$JWT_SECRET

ARG DB_CONNECTION_STRING
ENV DB_CONNECTION_STRING=$DB_CONNECTION_STRING

ARG W3UP_PRINCIPAL_KEY
ENV W3UP_PRINCIPAL_KEY=$W3UP_PRINCIPAL_KEY

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ The required env variables are:

- `HOST`: the server's host.
- `PORT`: the server's port.
- `DB_CONNECTION_STRING`: a connection string to a Postgres database.
- `JWT_SECRET`: the secret used to sign the issued JWTs. It's of utmost
importance to keep this value secret.
- `W3UP_PRINCIPAL_KEY`: a key identifying a principal that was previously
delegated by a w3up space owner to access the space itself.
- `W3UP_DELEGATION_PROOF`: a proof that proves the delegation of `store` and
Expand All @@ -60,6 +63,19 @@ In order to get the correct values for `W3UP_PRINCIPAL_KEY` and
`W3UP_DELEGATION_PROOF` follow
[this procedure](https://github.com/web3-storage/w3up/tree/main/packages/w3up-client#bringing-your-own-agent-and-delegation).

Once the `.env` file has been created, it's necessary to have all the correlated
infrastructure up and running in order to properly test the server. In
particular we need a `Postgres` database in which the server can store nonces to
avoid signature replay attacks.

For convenience all the needed infrastructure can easily be spun up using the
provided `docker-compose.yaml` file at the root of the package. Run the
following command to bootstrap everything:

```
docker compose up
```

Once the `.env` file has been created you can go ahead and start the server
using the following command launched from the package's root:

Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"
services:
postgres:
container_name: postgres
image: postgres:latest
ports:
- 127.0.0.1:5432:5432
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@
"devDependencies": {
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@hapi/inert": "^7.1.0",
"@hapi/vision": "^7.0.3",
"dotenv": "^16.3.1",
"esbuild": "^0.19.11",
"eslint": "^8.56.0",
"eslint-config-custom": "*",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"hapi-swagger": "^17.2.0",
"husky": "^8.0.3",
"pino": "^8.17.2",
"prettier": "^3.2.4"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.490.0",
"@hapi/boom": "^10.0.1",
"@hapi/hapi": "^21.3.2",
"@hapi/inert": "^7.1.0",
"@hapi/vision": "^7.0.3",
"@ipld/car": "^5.2.6",
"@ucanto/core": "^9.0.1",
"@ucanto/principal": "^9.0.0",
"@web3-storage/w3up-client": "^12.0.0",
"hapi-pino": "^12.1.0",
"joi": "^17.11.1"
"hapi-swagger": "^17.2.0",
"joi": "^17.11.1",
"jsonwebtoken": "^9.0.2",
"pg": "^8.11.3",
"viem": "^2.2.0"
}
}
Loading

0 comments on commit 071d598

Please sign in to comment.