This is
- Auth
- Files (S3-compatible Object Storage)
for Hasura
Add to docker-compose.yaml
:
hasura-backend-plus:
image: elitan/hasura-backend-plus
environment:
USER_FIELDS: '<user_fields>' // separate with comma. Ex: 'company_id,sub_org_id'
HASURA_GRAPHQL_ENDPOINT: https://<hasura-graphql-endpoint>
HASURA_GRAPHQL_ACCESS_KEY: <hasura-access-key>
HASURA_GRAPHQL_JWT_SECRET: '{"type": "HS256", "key": "secret_key"}'
S3_ACCESS_KEY_ID: <access>
S3_SECRET_ACCESS_KEY: <secret>
S3_ENDPOINT: <endpoint>
S3_BUCKET: <bucket>
DOMAIN: <domain-running-this-service>
REFETCH_TOKEN_EXPIRES: 54000
caddy:
....
depends_on:
- graphql-engine
- hasura-backend-plus
Add this to your caddy file
<domain-running-this-service> {
proxy / hasura-backend-plus:3000
}
Restart your docker containers
docker-compose up -d
USER_FIELDS: '<user_fields>' // separate with comma. Ex: 'company_id,sub_org_id'
HASURA_GRAPHQL_ENDPOINT: https://<hasura-graphql-endpoint>
HASURA_GRAPHQL_ACCESS_KEY: <hasura-access-key>
HASURA_GRAPHQL_JWT_SECRET: '{"type": "HS256", "key": "secret_key"}'
S3_ACCESS_KEY_ID: <access>
S3_SECRET_ACCESS_KEY: <secret>
S3_ENDPOINT: <endpoint>
S3_BUCKET: <bucket>
DOMAIN: <domain-running-this-service>
REFETCH_TOKEN_EXPIRES: 54000
If you have some specific fields on your users that you also want to have as a JWT claim you can specify those user fields in the USER_FIELDS
env var.
So lets say you have a user table like:
- id
- password
- role
- company_id
and you want to include the company_id
as a JWT claim. You can specify USER_FIELDS=company_id
.
Then you will have a JWT a little something like this:
{
"https://hasura.io/jwt/claims": {
"x-hasura-allowed-roles": [
"company_admin"
],
"x-hasura-default-role": "company_admin",
"x-hasura-user-id": "3",
"x-hasura-company-id": "1" <------ THERE WE GO :)
},
"iat": 1549526843,
"exp": 1549527743
}
This enables you to make permissions using x-hasura-company-id
for insert/select/update/delete in on tables in your Hasura console. Like this: {"seller_company_id":{"_eq":"X-HASURA-COMPANY-ID"}}
It also enables you to write permission rules for the storage endpoint in this repo. Here is an example: https://github.com/elitan/hasura-backend-plus/blob/master/src/storage/storage-tools.js#L16
more explanations coming soon
/register
/activate-account
/sign-in
/refetch-token
/new-password
Will act as a proxy between your client and a S3 compatible block storage service (Ex AWS S3 or Digital Ocean Spaces). Can handle read, write and security permission. Digital Ocean offer S3-compatible object storage for $5/month with 250 GB of storage with 1TB outbound transfer. https://www.digitalocean.com/products/spaces/.
Uploads to /storage/upload
. Will return key
, originalname
and mimetype
. You are able to upload multiple (50) files at the same time.
Get files at /storage/file/{key}
.
Security rules are placed in storage-tools.js
in the function validateInteraction
.
key
= Interacted file. Ex: /companies/2/customer/3/report.pdf
.
type
= Operation type. Can be one of: read
, write
.
claims
= JWT claims coming https://hasura.io/jwt/claims
custom claims in the Hasura JWT token. Ex: claims['x-hasura-user-id']
.