Hasura Auth API + Postman collection




In my previous post, I had mentioned that Hasura platform provides Data API as well as Auth API. I used Data API to insert and retrieve data into tables of my database schema. Check out my previous post about Hasura Data API


Auth service

Hasura Auth provides services for user authentication & authorization, user management, session management and table permissions. In a typical app, we require to
  1. Register a new user.
  2. Login an existing user and maintain his/her session.
  3. Logout the user and terminate his/her session.
  4. Reset password for a user.
Table for user information is already there in Auth service.

Roles

There are three roles in the auth service
  • admin
  • user
  • anonymous
A user of user table can have more then one role, and each role have its permission and access restrictions. The admin role can do CRUD queries to all the tables. Permissions for other roles is need to be defined in each table.
When we register a new user, it assigned least user role. If no one is logged in, that is given to role anonymous.
A logged in user is identified using the session tokens assigned to them.

API Request using Postman

As I told in my previous post about Hasura Data API where I was using Postman to query data from data service. Same in here I am using to contact Auth API on different endpoints for different purposes.
Auth API URL : http://auth.c100.hasura.me/
All request made to the Auth service must be POST, and data need to be send in application/json format.

User signup

For signup request, append signup in auth url. Body of request must be in raw and JSON format. Data need to be with the request is a username and a password (must be 8 characters). Put these information in the request body and send the request to Data API.

Signup request

If the Data service is running appropriately and the data sent with request then we get the response from Auth API, which is the information of newly signed up user.


A new user is added in Auth user table and it is assigned an id also a role user. This newly registered user is logged in and assigned a session token, which is in the response named as auth_token .

User Login

Login request made on the endpoint auth_url/login. Data need to be send on login is same as of signup, but a little change in the response recieved which is the string hasura_roles is not present in that.

User Logout

For logging out a user we need to request on the endpoint auth_url/user/logout. In this request we do not need to send any data. Response for logout is as


And the user is logged out of Auth service.

What's Next?

Next post is about integrating my app’s first screen’s UI with backend.

Comments

Popular posts from this blog

User Feedback & Testing of White Board

Idea for an app | First step to internship

Playing with the Octo-Cat