Auth microservice
This micro-service mainly focusses on the authorization and authentication of the Users that are sending request for signup and signin in the following service.
Additional Features:
- deleting an User account
- finding whether an User is admin or not
-
Databases required
- User
- Role
- UserRoles
- AirplaneAuthorities
-
Design of the Databases
-
Users Table (or User Model)
- id (created by sequelize automatically)
- password
- createdAt (created by sequelize automatically)
- updatedAt (created by sequelize automatically)
-
Roles Table (or Role Model)
- id (created by sequelize automatically)
- name
- createdAt (created by sequelize automatically)
- updatedAt (created by sequelize automatically)
-
UserRoles Table : used as a
through- table to create MANY-TO-MANY associations between tablesUsersandRoles. -
AirplaneAuthorities Table (or AirplaneAuthority Model)
- id (created by sequelize automatically)
- name
- domainName
- createdAt (created by sequelize automatically)
- updatedAt (created by sequelize automatically)
-
For signup
Request Format (to be sent in body) (json):
{
"email": <YOUR_EMAILID>,
"password": <YOUR_PASSWORD>
}- Creates a User with the given email-id and password. The password is encrypted using the npm package bcrypt.
- As soon as the user is created it allots a role to the user based upon the Domain-name in email-id. For example,
- if the email is of the form
xxxxxx@admin.xxxthen it allots an admin role. - if the email is of the form
xxxxxx@<AIRPLANE_AUTHORITY>.xxxthen it allots a role of Airplane Authority. - for all other cases, it allots a role of customer to the user.
- if the email is of the form
For signin
Request format (to be sent in body) (json):
{
"email": <YOUR_EMAILID>,
"password": <YOUR_PASSWORD>
}- On successfull signin, a token (valid for 96 hrs or 4 days) is given which the user should save for further use during flight booking or any other activities which may require it.
For deleting an user
Request format (to be sent in body) (json):
{
"email": <YOUR_EMAILID>,
"password": <YOUR_PASSWORD>,
"token": <YOUR_TOKEN>
}- Successfull deletion resuslts in removal of allotted user role.
For checking Admin rights
Request format (to be sent in body) (json):
{
"userId": <INTEGER_USERID>
}- Returns whether the corresponding user is an admin or not.
