Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boilerplate auth server to create JWT tokens #848

Conversation

peterjgrainger
Copy link

@peterjgrainger peterjgrainger commented Oct 24, 2018

Add a boilerplate for creating a jwt authentication server to provide tokens to be used with the graphQL engine. See the docker-compose configuration and the README to see how to test.

close #451

Description

Creates the auth server described here: https://docs.hasura.io/1.0/graphql/manual/auth/jwt.html to create tokens to be decoded by the GraphQL server.

What component does this PR affect?

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System

Requires changes from other components? If yes, please mark the components:

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System

Related Issue

n/a

Solution and Design

Based very closely on boilerplate with passportjs but without the webhook. Uses an environment variable to set the JWT signing key.

Allows a user to signup (saves user in postgres) then login using that user.

JWT contains userID from the database their username and the required hasura claims including the role user and signs with JWT signing key

{
        sub: '' + user.id,
        name: user.username,
        iat: Date.now() / 1000,
        "https://hasura.io/jwt/claims": {
          "x-hasura-allowed-roles": ["editor","user", "mod"],
          "x-hasura-user-id": '' + user.id,
          "x-hasura-default-role": "user",
          "x-hasura-role": "user"
        }
      }

Type

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Docs update
  • Community content

Checklist:

  • I have read the contributing guide and my code conforms to the guidelines.
  • This change requires a change in the documentation.
  • I have updated the documentation accordingly.
  • I have added required tests.

@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @peterjgrainger, thanks for your PR!

One of my human friends will review this PR and get back to you as soon as possible. 🕐

Stay awesome! 😎

@CLAassistant
Copy link

CLAassistant commented Oct 24, 2018

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ peterjgrainger
✅ shahidhk
❌ petergrainger


petergrainger seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hasura-bot
Copy link
Contributor

Review app available at: https://hge-ci-pull-848.herokuapp.com

@revskill10
Copy link

Please don't use knex. Use a graphql client instead.

@peterjgrainger
Copy link
Author

@revskill10 I was trying to be consistent with the other boilerplates such as https://github.com/hasura/graphql-engine/tree/master/community/boilerplates/auth-webhooks/passport-js

Do you mean to set up the users table using the GraphQL client? I was trying to make the process as easy to use as possible, it's only saving the user against a password? Maybe I could use redux or other simple data store instead?

@hasura-bot
Copy link
Contributor

Review app available at: https://hge-ci-pull-848.herokuapp.com

@revskill10
Copy link

Yes, it's simpler than using a third party library like knex, because graphql is universal. Not all node users use knex, they all know what graphql is.

@hasura-bot
Copy link
Contributor

Review app available at: https://hge-ci-pull-848.herokuapp.com

@peterjgrainger
Copy link
Author

peterjgrainger commented Oct 25, 2018

@revskill10 maybe i could add migrations and use the hasura cli? https://docs.hasura.io/1.0/graphql/manual/migrations/index.html

@revskill10
Copy link

I think you can just deploy a staging server for hasura, the code only uses graphql instead. You can put static schema file in repo optionally.

@hasura-bot
Copy link
Contributor

Review app available at: https://hge-ci-pull-848.herokuapp.com

@peterjgrainger
Copy link
Author

@revskill10 updated as suggested. Let me know if there is anything else that should be changed

@hasura-bot
Copy link
Contributor

Review app available at: https://hge-ci-pull-848.herokuapp.com

@shahidhk shahidhk self-assigned this Oct 27, 2018
@coco98
Copy link
Contributor

coco98 commented Oct 29, 2018

@peterjgrainger Thank you so much for your work! This will be very helpful to folks looking at getting started with a simple JWT auth server. 🎉

I'll be reviewing this along with @ecthiender and @arvi3411301.

Also, please do sign the CLA so that we can merge your PR into the repo!

@shahidhk shahidhk added the c/community Related to community content label Oct 29, 2018
@peterjgrainger
Copy link
Author

peterjgrainger commented Oct 29, 2018 via email

@peterjgrainger
Copy link
Author

peterjgrainger commented Nov 6, 2018

@coco98 I signed the CLA multiple times but the check is still failing it says the email used in the commit is not on my account but it is registered in github

Also I'm not sure why the circleCI build failed? It passed when I did the initial change

@ecthiender ecthiender changed the title feat: add auth server to create JWT tokens used in engine add boilerplate auth server to create JWT tokens Nov 26, 2018
@emahuni
Copy link

emahuni commented Jul 11, 2019

@peterjgrainger, can you please try again, wanted to see this in the community.

@ctwhome
Copy link

ctwhome commented Nov 2, 2020

is this finally finished? thanks a lot

@praveenweb praveenweb removed their request for review October 22, 2021 06:31
@Stefmore02
Copy link
Contributor

Closing this PR in response to [4442].

@Stefmore02 Stefmore02 closed this Apr 18, 2023
@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @peterjgrainger!

Sorry that your PR wasn’t merged.

Do take a look at any of the other open issues to see if you’d like to take something up! We’re around on Discord if you have any questions 😄

@Stefmore02 Stefmore02 added the c/docs Related to docs label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/community Related to community content c/docs Related to docs community-contrib 🙏🏽
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: create a boilerplate for using hasura with passportjs and jwt
10 participants