Giter VIP home page Giter VIP logo

nhost / hasura-backend-plus Goto Github PK

View Code? Open in Web Editor NEW
1.2K 1.2K 187.0 5.98 MB

🔑Auth and 📦Storage for Hasura. The quickest way to get Auth and Storage working for your next app based on Hasura.

Home Page: https://nhost.github.io/hasura-backend-plus/

License: MIT License

JavaScript 0.72% Dockerfile 0.50% PLpgSQL 3.40% TypeScript 93.82% EJS 1.56%
authentication docker graphql hasura jwt s3 storage typescript

hasura-backend-plus's Introduction

Nhost

Nhost

Quickstart   •   Website   •   Docs   •   Blog   •   Twitter   •   Discord


Nhost is an open source Firebase alternative with GraphQL, built with the following things in mind:

  • Open Source
  • GraphQL
  • SQL
  • Great Developer Experience

Nhost consists of open source software:

Architecture of Nhost




Visit https://docs.nhost.io for the complete documentation.

Get Started

Option 1: Nhost Hosted Platform

  1. Sign in to Nhost.
  2. Create Nhost app.
  3. Done.

Option 2: Self-hosting

Since Nhost is 100% open source, you can self-host the whole Nhost stack. Check out the example docker-compose file to self-host Nhost.

Sign In and Make a Graphql Request

Install the @nhost/nhost-js package and start build your app:

import { NhostClient } from '@nhost/nhost-js'

const nhost = new NhostClient({
  subdomain: '<your-subdomain>',
  region: '<your-region>'
})

await nhost.auth.signIn({ email: '[email protected]', password: 'spaceX' })

await nhost.graphql.request(`{
  users {
    id
    displayName
    email
  }
}`)

Frontend Agnostic

Nhost is frontend agnostic, which means Nhost works with all frontend frameworks.

Resources

  • Start developing locally with the Nhost CLI

Nhost Clients

Integrations

Applications

Community ❤️

First and foremost: Star and watch this repository to stay up-to-date.

Also, follow Nhost on GitHub Discussions, our Blog, and on Twitter. You can chat with the team and other members on Discord and follow our tutorials and other video material at YouTube.

Nhost is Open Source

This repository, and most of our other open source projects, are licensed under the MIT license.

ROSS Index - Fastest Growing Open-Source Startups | Runa Capital

How to contribute

Here are some ways of contributing to making Nhost better:

Contributors

A table of avatars from the project's contributors

hasura-backend-plus's People

Contributors

aaronhayes avatar alanpachuau avatar babakscript avatar cgsdev0 avatar dependabot[bot] avatar diogoeichert avatar elitan avatar franzyke avatar frissonlabs avatar hampuskraft avatar jlvdh avatar joaovpmamede avatar joshmedeski avatar kekbait avatar komninoschatzipapas avatar marcellothearcane avatar mnlbox avatar nunopato avatar plmercereau avatar pomarec avatar ppseafield avatar rodolfosilva avatar rubenvaneldik avatar skinymonkey avatar svarto avatar tcbyrd avatar tobiastornros avatar weyert avatar yagger avatar zbeyens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hasura-backend-plus's Issues

How to access other table schemas?

This is probably a question for Hasura, but I can't seem to find anything on the docs about it.

Is there a way of querying the other tables here? I'd like to set up a duplicate of the public database for a testing environment.

image

I assume it would be either a custom header or a different URL.

Execute db-user-uuid-init.sql fails

Attempt to Hasura > Data > Run SQL with db-user-uuid-init.sql fails with the following error:

SQL Execution Failed postgres-error : function public.set_current_timestamp_updated_at() does not exist

Looks like this trigger function is simply missing from the dump.

[v2] JWKS endpoint?

Hi Johan,
First of all many thanks for this very nice repo! I am actually considering using it instead of the scrappy attempt I did a few months ago (and another ongoing attempt in this monorepo).
Did you ever considered setting a JWKS endpoint, so Hasura could get its JWK public key from HBP? It would help centralise the keys into one service (HBP), and we could then even consider an automatic keys rotation. What do you think about that?
Best,
Pilou

Add more docs about Auth

I see this in Readme file:

Auth

/register
/activate-account
/sign-in
/refetch-token
/new-password

Can you explain how we can use these?

some cleanup on package.json

Hi man,
I think it's better to add nodemon from dependency to dev-dependency and add some start and dev script.

user secret_token

what is the flow for reseting password?
Every time I call new-password endpoint I have to send the user's secret_token that I first get from the user when logging/registering?
If that's the case, what is the purpose of it?

Boom is deprecated, use @hapi/boom

There's a deprecation notice on https://www.npmjs.com/package/boom -

This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.

It looks like a case of changing all instances of boom to @hapi/boom, or has the API changed?

Req: Basic Example

I'm looking for a basic example of a file upload from react to hasura backend (minio).

/storage/fn/get-download-url/* returns empty object

I assume the /fn/get-download-url/* endpoint here is intended to provide an image url that can be used in an html <img> tag.

I have managed to download the image blob with the /file/* endpoint and convert it to a data url, but it would be nicer to get a simple URL!

Any ideas why I am not getting the token specified here?

clear refresh tokens

when do you clear the refresh tokens in the db? Shouldn't it be done when the user logouts?

Add 'get user' endpoint

Great project! I'm getting started with integrating this (via nhost) to Nuxt.js and have come across an issue.

I'm using the default @nuxtjs/auth module, which requires an endpoint to fetch user data:

auth: {
  strategies: {
    local: {
      endpoints: {
        login: { url: '<url>/auth/login', method: 'post', propertyName: 'token' },
        logout: false,
        user: { url: '<url>/auth/user', method: 'get', propertyName: 'user' }
      },
    }
  }
}

the user endpoint requires a response similar to this:

{
  "user": {
    <user_data>
  }
}

Would it be possible to add an endpoint that runs a query like this?

query user($username: String!) {
  users(where: {username: {_eq: $username}}) {
    username
    id
    created_at
  }
}

Two step (factor) authentication

Hi @elitan ,
I think two step (factor) authentication can be very useful for many applications. I recently implement this in LoopBack based on below article:
https://jordankasper.com/two-factor-authentication-with-loopback/
and use this library:
https://github.com/speakeasyjs/speakeasy

Later I see this library: https://passwordless.net/

For testing purpose I think we need print 2FA code on console and a setting option for example called send 2FA code by: to select gateway for send 2FA code (for example we can suggest some option here: send 2FA code through mail plugin, web hook call, sms, ...)

I think this library is more better than other thinking
https://github.com/yeojz/otplib

Lets talk about this here 😉

Login with facebook & linkedin

hi everyone,

really like the repo Jonah.
i am implementing it for an existing project. i have a fork because i need login with email and password :)

i am looking into implementing login with social media accounts too. i dont think auth0 is a solution as for high no of users costs can explode. i will feedback here if i get anywhere.

did you try this? was it on your radar?
do you have any suggestions?
thanks,
C

Login try limit

Hi @elitan ,
We need some login try limitation solution. Something like #22 but for login.

Some approach:

  1. Block user for X minute after Y unsuccessful login try.
  2. Show captcha image after X unsuccessful login try.

We also need some new environment variable for this X, Y, ...
We also need implement this for both traditional and 2FA login mechanism after merge #29

Include documentation for migration when schema changes

Any chance documentation for migration can be included when schema changes? I'm not sure what is the best way to do so with the additional of the oauth providers and I can see in db-init.sql that the schema has significant changes

add USER_FIELDS example

Hi @elitan,
Thanks for this awesome repo, Can you explain how we can use USER_FIELDS for add custom user fields?
I can't find any example or note in ReadMe.md file.

/auth/logout throw an error

Hi, just noticed there is a reference to undefined user variable in the /auth/logout route, the logout-all is ok

router.post('/logout', async (req, res, next) => {
  // get refresh token
  const schema = Joi.object().keys({
    refresh_token: Joi.string().uuid().required(),
  });

  const { error, value } = schema.validate(req.body);

  const { refresh_token } = value;

  // delete refresh token passed in data
  let mutation = `
  mutation (
    $refresh_token: uuid!,
  ) {
    delete_refresh_token: delete_${schema_name}refresh_tokens (
      where: {
        refresh_token: { _eq: $refresh_token }
      }
    ) {
      affected_rows
    }
  }
  `;

  let hasura_data;
  try {
    hasura_data = await graphql_client.request(mutation, {
      user_id: user.id,
    });
  } catch (e) {
    console.error(e);
    // console.error('Error connection to GraphQL');
    return next(Boom.unauthorized('Unable to delete refresh token'));
  }

  res.send('OK');
});
hasura-backend-plus_1  | POST /auth/logout 401 84 - 5.430 ms
hasura-backend-plus_1  | ReferenceError: user is not defined
hasura-backend-plus_1  |     at router.post (/app/src/auth/auth.js:166:16)
hasura-backend-plus_1  |     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
hasura-backend-plus_1  |     at next (/app/node_modules/express/lib/router/route.js:137:13)
hasura-backend-plus_1  |     at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
hasura-backend-plus_1  |     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
hasura-backend-plus_1  |     at /app/node_modules/express/lib/router/index.js:281:22
hasura-backend-plus_1  |     at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
hasura-backend-plus_1  |     at next (/app/node_modules/express/lib/router/index.js:275:10)
hasura-backend-plus_1  |     at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)
hasura-backend-plus_1  |     at router (/app/node_modules/express/lib/router/index.js:47:12)
hasura-backend-plus_1  | Unable to delete refresh token
hasura-backend-plus_1  | Error: Unable to delete refresh token
hasura-backend-plus_1  |     at router.post (/app/src/auth/auth.js:171:22)
hasura-backend-plus_1  |     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
hasura-backend-plus_1  |     at next (/app/node_modules/express/lib/router/route.js:137:13)
hasura-backend-plus_1  |     at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
hasura-backend-plus_1  |     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
hasura-backend-plus_1  |     at /app/node_modules/express/lib/router/index.js:281:22
hasura-backend-plus_1  |     at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
hasura-backend-plus_1  |     at next (/app/node_modules/express/lib/router/index.js:275:10)
hasura-backend-plus_1  |     at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)
hasura-backend-plus_1  |     at router (/app/node_modules/express/lib/router/index.js:47:12)```

GraphQL endpoint for files

I've had a quick look around, but I don't think there is such a thing as a GraphQL wrapper for Amazon AWS. Would it be preferable to develop this externally and import to HBP at a later date?


It would be really useful to have a GraphQL endpoint for the file API in HBP. Ideally, it should be possible to create, read, update and delete files.

Creating files

Here is a specification for uploading files. The implementation will need a bit of work to smoothly work with AWS, particularly large files. This could be implemented at a later date, as there is already a workable upload solution.

It will either need a custom GraphQL type, or else require the file to be encoded as a base64 blob (very large files might prohibit this).

Reading files

The listObjects provides a method for listing objects. It looks like you can get metadata for all objects like this, though I'm not sure how is best to implement the folder structure through GraphQL (i.e. folders and files in the same directory).

There's an issue of pagination that some users may face (1000 items maximum), but there are ways round that.

You might need to work out whether it would be more efficient to use headObject or listObjects depending on the GraphQL query.

Updating files

I can't seem to find the appropriate endpoint for updating files, possibly you should delete and re-add the file.

Deleting files

You can delete multiple objects with the deleteObjects property, but I think you need to reference the unique ID assigned by the bucket. In order to delete in a GraphQL-compliant way (i.e. deleting by an arbitrary reference), you may need to get the bucket data before.

An idea for implementing into Nhost would be as a remote schema. Is it possible to create a new Hasura instance with preconfigured remote schemas? If so, you could add an authentication key as an environment variable.

Change name of hasura-backend-plus?

Right now the name hasura-backend-plus is a long name, not really unique and it does not feel it has its own 'soul'.

My idea is to change the repo name to something easier, smaller and catchier with just a single name? Like:

  • yeasura
  • blace
  • moritter

or something similar.

My idea is to also add a js sdk. Much like firebase-js-sdk that will handle auth and storage more easiely. Like:

    const upload_res = await <reponame>.upload('product-images/', [this.image_upload], (progressEvent) => {
      console.log('new progress event');
      console.log(progressEvent);
    });
  1. Thoughts on the idea to change the repo name?
  2. Any name suggestions? (optional)

Login gives error

Trying to login with a registered user i get the following output from the logs:

hasura-backend-plus_1  | user: {
hasura-backend-plus_1  |   "id": 1,
hasura-backend-plus_1  |   "password": "$2a$10$WiMG2bz7Vnkv0cMLdn4i1.9LCNEPtixGOYv.DBYDmxt3aDoQ0KiEm",
hasura-backend-plus_1  |   "active": true,
hasura-backend-plus_1  |   "default_role": "user",
hasura-backend-plus_1  |   "roles": []
hasura-backend-plus_1  | }
hasura-backend-plus_1  | Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
hasura-backend-plus_1  |     at Sign.sign (internal/crypto/sig.js:80:26)
hasura-backend-plus_1  |     at Object.sign (/app/node_modules/jwa/index.js:76:45)
hasura-backend-plus_1  |     at Object.jwsSign [as sign] (/app/node_modules/jws/lib/sign-stream.js:32:24)
hasura-backend-plus_1  |     at Object.module.exports [as sign] (/app/node_modules/jsonwebtoken/sign.js:198:16)
hasura-backend-plus_1  |     at Object.generateJwtToken (/app/src/auth/auth-tools.js:25:16)
hasura-backend-plus_1  |     at router.post (/app/src/auth/auth.js:306:32)

I know it has something to do with the keys. I generated the keys from the terminal using:

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

tried to verify the signature at jwt.io and it was a valid signature. Seeing the hasura-backend minio example it shows that both need to be the public keys. What am I doing wrong?

Split this project

@elitan nice job with this library.
I think we can split this project in two small projects.
One for authentication only and one for storage only. What do you think of this approach?

And we can use the docker-compose to merge both with hasrua/graphql-engine.

Right now I started making hasura-auth. And @toastedtoast has started hasura-storage, both forked from HB+.

But I think we can unify all this projects in a organization with HB+ splited.

What do you think?

cc\ @mnlbox

Switch authentication to a general and customizable passport.js approach

Hi,
@elitan As we talk later it's a good improvement if we can change current authentication approach to passport.js based approach.
My other suggestion is to separate authentication strategy implementation from Auth layer. For example Auth layer can be a simple GraphQL mutation or REST layer and we can edit this with file outside docker image based on http://www.passportjs.org/ or any other authentication implementation. Something like you done for storage-rule in:

volumes:
  ./storage-rules.js:/app/src/storage/storage-rules.js

passportjs has a lot of authentication strategy (LDAP, 2FA, ...)

Companies or apps have a vary type of authentication logic and if we can separate it as authentication.js form HB+ core as a volume binded file outside docker we can support many strategies.
Passport.js contains 502 authentication strategy now. It's most powerful authentication solution I think. You can find many authentication here: http://www.passportjs.org/packages/

For example this 2FA can useful for mobile apps and social networks: http://www.passportjs.org/packages/passport-2fa-totp/

Or we can use http://www.passportjs.org/packages/passport-ldapauth/ because we have Active Directory in my company.

I guess if we can get passport.js working with HB+ with a good way to configure it, it should work with any passport provider. 😉

JWT token in http only cookie

I have a question regarding /login route. When server authenticates the user, http only cookie is created and sent to the client. I want to know why ? .. because Hasura in JWT mode cannot read JWT from cookie to create authorization header as explained here
Does this cookie have any other purpose?

How to add my custom business logic?

Hi @elitan,
I want to add some business logic to my Hasura and see that this repo is good as a start point.
Can you guide me about how we can do this?
Are you any suggestion for me?
Are you any plan to simplify this use-case? (customized business logic)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.