3.3) Hasura Auth API + Postman collection for Expense Tracker

Hasura Expense Tracker
4 min readJun 27, 2017

--

In this blog post we will be going through Hasura Auth API and Postman collection which is the task 3 of week 3 for the Hasura Internship. You can have a look at our Schema Modelling to get a better understanding of this task.

User management is an important part of an application. It lets you manage users that use your app. It includes registration, login, logout, reset password etc. For user management Hasura offers the Auth service. You can refer to the original documentation here — Auth Service by Hasura.

What is Auth Service?

The auth service is a part of every Hasura project. It has extensive APIs to manage users, roles and integrates with various social login providers. These are the endpoints that we are interested in to build our ExTra Expense Tracker app.

How it works

Hasura Auth provides an HTTP API for authentication and authorization of identities on the Hasura platform. This API can be consumed directly by frontend interfaces like mobile apps, browser-based apps, device apps as well as any server-side program.

Basic actions

Basic actions includes registering, logging in a user, viewing user info and logout. We will see below how to perform these basic actions.

Steps for using Hasura Auth API

  1. Login to your console and on the home page under running services in Auth click on status. Now note down you External Endpoint. In our case, it is http://auth.c100.hasura.me/.
Auth External Endpoint

2. Next, open Postman app and set it up as following:

Now you are ready to use Hasura Auth APIs.

  1. Register a user

Suppose a new user wishes to register, we can use the following JSON query :

Signup request for a new user
Response for signup request with auth_token

The new user gets an id and is allotted the “user” role. The “auth_token” for the user is also specified in the response.

Every user created with the /signup endpoint is assigned the role user.

2) Login

For the newly registered user to login to the application, we can use the following JSON query :

Login request for already registered user
Successful login

When a user logs in, a new session token is created for the user. It is set as cookie and also returned in auth_token of the response. The token and the associated user’s information is stored in the session store.

3) User info

There may be scenarios in which we may want to retrieve details about the current user. In such cases, we make the User info query.

For viewing user info, make sure to change the request type to “GET”.

To make the request, in the Headers tab, add a new key “Authorization” and specify it’s value as “Bearer auth_token”.

Making request to view user info
Response showing all details about current user

Using this endpoint, information about current logged in user can be retrieved.

4) Logout

In order to logout from an application, the user must be able to make logout requests. This can be achieved by the following :

Making POST request to specified endpoint and adding a new key in Headers tab. The key must be specified as “Authorization” and it’s value should be specified as “Bearer auth_token”.

Successful logout

After making the request, we get the response that confirms that we have been logged out successfully.

The API collection used for authentication are : https://www.getpostman.com/collections/b33b8041032c9111324f

References:

  1. Documentation for Hasura Auth API
  2. Examples of Hasura Auth API

-Akash Dabhi and Vinit Neogi

--

--

Hasura Expense Tracker

Two tech geeks embarking on a journey to create their first android app for their Hasura Internship program. IT dept, St. Francis Institute of Technology.