Hasura Auth API + Postman collection

Task 3.3) Learn Authentication APIs

Hello! Welcome back readers!! In this blog, our task is to know about the Authentication APIs. You can have a look at our Schema Modelling to get a better understanding of this task.In the last blog we talked about the Data API’s.If you missed on that head on to this link(Here:-link).

User management is much important for any application as it manages the user information. It includes the signup, login, user information and logout options for the user. You can refer about it in more detail at 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.

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.

Steps for using Hasura Auth API

  1. Log in to hasuractl console and get the External Endpoint from the Data and Schema option on the left side.
External Endpoint

2. Now, open the Postman App and do the following settings as shown :

Setting for Auth API

For signup : http://auth.c100.hasura.me/signup
For login : http://auth.c100.hasura.me/login
For viewing user info : http://auth.c100.hasura.me/user/account/info
For logout : http://auth.c100.hasura.me/user/logout

And specify that you want to provide raw data and select Content-Type as JSON(application/json).

Lets now start useing Auth APIs:

  1. Registering the user

The signup is used for registration of a new user. Thus, the JSON query is as follows:

Signup for user

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

Result for signup in the database

2. Login

The login option is used for registered user for logging in the system/application. For the same the JSON query is as:

Login for user

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

By using the following JSON query, we can get the user information:

User Info query

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 :

Llogout query

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

That’s it for tasks of Week 3 of the Hasura Internship. Stay tuned for the further blogs. Till then Ciao :-) !!

References:

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