An organization-user JWT authentication system. Made using golang, gin, gorm and go-jwt.
Swagger documentation can be viewed here.
Untitled.mp4
- Clone this repo
- Change directory to the cloned repo
- Ensure you have
go
installed on your machine. - Run
go mod download
- Ensure you have
postgresql
installed on your machine OR you can create a cloudpostgres
database - Run
cp .env.sample .env
- Set the environment variables as mentioned in the
.env.sample
. - Run
go run main.go
postgresql
has been used for this task because I have been building web-apps using postgresql from a long time. I have build many backend API services using Django
all using postgresql
. Unlike mongoDB, it is a RDBMS, hence defining relations between 2-3 tables becomes pretty easy.
gin
- It is most popular go framework that is designed for building APIs. Hence, I have used gin to complete the task.go-jwt
- It is the most popular package for implementing JWTs in Go. It has many pre-defined functions for signing and validating JWTs. Hence, used I have used it here, to sign and validate access_token and refresh_token.gorm
- It is the most popular ORM package in the Go ecosystem. Makes it really easy to create models and querying through database.bcrypt
- It implements Provos and Mazières's bcrypt adaptive hashing algorithm. Used to hash passwords to store in database.
- /removeMember POST - Remove the member from an organization provided the current user is an admin of the organization.
- /createUser POST - Creates a new user for an organization provided that the current user is an admin of the organization.
- /getUsersFromOrganization/{organizationID} GET - Get members of an organization provided the current user is also a member.
- /login POST - The current user is logged in, provided the correct username and password is passed.
- /logout GET - The current user is logged out.
- /createOrganization POST - Creates an organization and makes the creator of the organization an admin of the organization.
- /makeUserAdmin POST - Makes an existing user an admin of an organization. [No validations here. Just for modifying data.]