Using Authorizer with Hasura

Hasura gives you instant GraphQL / Rest API on top of SQL databases like Postgres and MySQL.

It takes away the pain of writing basic CRUD (Create, Read, Update, Delete) APIS. It also gives column and row level authorization layer using JWT tokens. Thi…


This content originally appeared on DEV Community and was authored by Lakhan Samani

Hasura gives you instant GraphQL / Rest API on top of SQL databases like Postgres and MySQL.

It takes away the pain of writing basic CRUD (Create, Read, Update, Delete) APIS. It also gives column and row level authorization layer using JWT tokens. This helps in having secured APIs without writing any backend code.

On the other hand Authorizer is database independent open source authentication and authorization solution built using GraphQL. You can bring in your database and have authentication layer ready for your users in seconds. Motive of Authorizer is to save your user data in your database without having the pain of developing highly secure auth system.

In technical terms you get an JWT token with authorizer.dev which you can use with Hasura to verify the permission for a given user.

You can check a video tutorial for same

Now you get following things:

  • GraphQL API out of the box with Hasura for your database
  • Authentication with Authorizer
  • Authorization (Role based access) with Hasura auth system
  • Secure session management with Authorizer
  • Multiple login recipes with Authorizer
  • And your data stays within in your database

Here is how the broader picture looks like

hasur-authorizer-architecture

Also authorizer-react / authorizer-js takes away the pain of

  • Securely managing JWT token
  • Creating login / signup page
  • Creating forgot password page

Isn’t that great! all in one place and under your control 🎉

No more need to pay 3rd party applications which can own your data and you might have to write some logic to stitch the data with your database.

gif

Here are 5 simple steps to achieve this

Step 1: Deploy Authorizer instance

Deploy production ready Authorizer instance using one click deployment options available below

Infra provider One-click link Additional information
Railway.app Deploy on Railway docs
Heroku Deploy to Heroku docs
Render render button docs

For more information check docs

Step 2: Setup Instance

  • Open authorizer instance endpoint in browser
  • Signup with a secure password
  • Configure social logins / smtp server and other environment variables based on your needs

For more information please check docs

Step 3: Setup Hasura Instance

Step 4: Configure Database with Hasura

  • Open the hasura endpoint for your instance and configure the database that you have used for authorizer.

Check the hasura docs for more information.

Note if you have used single click deployment option for authorizer you can get database URL from respective platform's env sections.

Step 5: Configure JWT token Authorization Script

In order for Hasura to authorize a user, JWT token needs to have specific keys, you can add those keys by modifying JWT token script in your Authorizer Dashboard.

Example:

function(user,tokenPayload) {
  var data = tokenPayload;
  data['https://hasura.io/jwt/claims'] = {
    'x-hasura-user-id': user.id,
    'x-hasura-default-role': tokenPayload.allowed_roles[0],
    'x-hasura-allowed-roles': user.roles
  }

  return data;
}

sample

Thats all,

You can configure access control for various roles that your application needs. You can also configure same roles in your authorizer dashboard.

For more information on access control check hasura docs

You can also stitch Authorizer Graphql Endpoint with Hasura Remote Schema, that way you can have single endpoint for all your GraphQL queries / mutations.

For more information check:

Site: https://authorizer.dev
Docs: https://docs.authorizer.dev
Youtube: https://youtube.com/playlist?list=PLSQGbUjHc6bpaAgCiQPzNxiUPr7SkDAFR
Github: https://github.com/authorizerdev/authorizer
React-SDK: https://github.com/authorizerdev/authorizer-react
JS-SDK: https://github.com/authorizerdev/authorizer-js
Join Discord: https://discord.gg/Zv2D5h6kkK


This content originally appeared on DEV Community and was authored by Lakhan Samani


Print Share Comment Cite Upload Translate Updates
APA

Lakhan Samani | Sciencx (2022-04-19T03:42:01+00:00) Using Authorizer with Hasura. Retrieved from https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/

MLA
" » Using Authorizer with Hasura." Lakhan Samani | Sciencx - Tuesday April 19, 2022, https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/
HARVARD
Lakhan Samani | Sciencx Tuesday April 19, 2022 » Using Authorizer with Hasura., viewed ,<https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/>
VANCOUVER
Lakhan Samani | Sciencx - » Using Authorizer with Hasura. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/
CHICAGO
" » Using Authorizer with Hasura." Lakhan Samani | Sciencx - Accessed . https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/
IEEE
" » Using Authorizer with Hasura." Lakhan Samani | Sciencx [Online]. Available: https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/. [Accessed: ]
rf:citation
» Using Authorizer with Hasura | Lakhan Samani | Sciencx | https://www.scien.cx/2022/04/19/using-authorizer-with-hasura/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.