[3.3] Hasura Auth API + Postman

Links to 3.1 & 3.2

The 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 ether app.

1. Register a user

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

POST auth.<project-name>.hasura-app.io/signup HTTP/1.1
Content-Type: application/json

{
"username" : "hasura-test",
"password" : "hasura-test-123"
}

The response will be as follows:

HTTP/1.1 200 OK
Content-Type: application/json
{
"auth_token": "pand3yofqfqrz7kab8i7n4w9n2wgc6bg",
"hasura_id": 2,
"hasura_roles": [
"user"
]
}
Performing signup API in Postman

2. 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.

POST auth.<project-name>.hasura-app.io/login HTTP/1.1
Content-Type: application/json
{
"username" : "hasura-test",
"password" : "hasura-test-123"
}

The response will be as follows:

HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: dinoisses=pand3yofqfqrz7kab8i7n4w9n2wgc6bg; Domain=.<project-name>.hasura-app.io:01:34 GMT; httponly; Max-Age=1814400; Path=/
{
"auth_token": "pand3yofqfqrz7kab8i7n4w9n2wgc6bg",
"hasura_id": 2,
"hasura_roles": [
"user"
]
}
Performing logout API in Postman

3. Logout

When the user logs out, the session token is deleted from the session store and the cookie is set to expire.

GET auth.<project-name>.hasura-app.io/user/logout HTTP/1.1
Authorization: Bearer pand3yofqfqrz7kab8i7n4w9n2wgc6bg
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: dinoisses=; Domain=.<project-name>.hasura-app.io; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
{
"message": "Logged out"
}
Performing logout API in Postman

4. User info

We have to add session token in Authorization header.

GET auth.<project-name>.hasura-app.io/user/account/info HTTP/1.1
Authorization: Bearer pand3yofqfqrz7kab8i7n4w9n2wgc6bg

The response will be as follows:

HTTP/1.1 200 OK
Content-Type: application/json
{
"auth_token": "pand3yofqfqrz7kab8i7n4w9n2wgc6bg",
"hasura_roles": [
"user"
],
"mobile": null,
"hasura_id": 2,
"username": "hasura-test",
"email": null
}
Performing info API in Postman

For more details about Hasura Auth API, please follow Hasura documentation.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.