authentication

command module
v0.0.0-...-2dc4e31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

README ΒΆ

Authentication

Repository Informations Open Tasks
GitHub Repo size GitHub Stars Forks Build Status Open Issues Open Pull Requests
Last Updates
Last Tag Last Release Last Release Stats
Copyright
License Contributors

πŸš€ Project created to train authentication issues, password recovery, login with third parties, permissions, etc.

🏁 Table of Contents


===================

πŸ±β€πŸ Features

πŸ’» Dependencies and Environment

πŸš€ Installing

🧹 Formatting the Code

πŸ§ͺ Testing

β˜• Using

πŸ”’ License

πŸ‘· Author

===================

πŸ±β€πŸ Features

🧾 Documentation

  • Migrations
  • BDD (Behavior Driven Development) to use cases
  • Gin Swagger to routes
  • Concept of semantic versioning with tags and releases

βš™ General

  • CI/CD process with github actions to perform code formatting check (golangci-lint), build and run automated tests

  • Test setup with TestContainers:

    1- For each test switch/file that uses the database, a Postgres container is created just for testing

    2- Then all migrations are run in this container

    3- Before each test, a script is run to clean all records from the tables

    4- After executing the switch, the container is terminated

  • Common middlewares to routes: block inactives users, rate limiter, timeout, only https, jwt signature checker for some routes, admin only for some routes, check 2fa when user has the 2fa activated

πŸ— Use Cases

  • login_2fa: With the normal JWT and the code generated by google authenticator it is possible to return the valid JWT for users who have 2FA activated
  • active_2fa (need to be logged in): returns qrcode to synchronize with google authenticator
  • desactive_2fa (need to be logged in)
  • notify the user by email: when your password is changed and when your email is verified
  • verify_change_email_code (need to be logged in): Verifies that the code is correct and not expired
  • send_change_email_code (need to be logged in): Saves a code and an expiration time (5 minutes) in the database and sends an email with the code
  • change_email (need to be logged in): It is necessary to use a unique code that is sent to the current email
  • change_password_in_recovery: Verifies that the code is correct and not expired and change the password to the new password
  • verify_password_recovery_code: Verifies that the code is correct and not expired
  • send_password_recovery_code: Saves a code and an expiration time (5 minutes) in the database and sends an email with the code
  • verify_email: Verifies that the code is correct and not expired and updates the email as verified
  • send_email_verification_code: Saves a code and an expiration time (5 minutes) in the database and sends an email with the code
  • admin elevation: you can promote anothers users to admin, delete users, inative user, find user information, list all users, list all logs, list all logs of a user
  • log: all operations have log persistence with information such as: user id, operation code, method, route, success (true/false), ip and timestamp
  • delete_user (need to be logged in): delete by id or e-mail
  • find_user (need to be logged in): find by id or e-mail
  • change_password (need to be logged in)
  • login: With JWT
  • create_user: Do not allow repeated emails and weak passwords

πŸ’‘ Technical Decisions

  • Clean Code
  • Scream Architecture
  • Commit Lint
  • SOLID
  • Clean Architecture

πŸ’» Dependencies and Environment

My dependencies and versions

Go: go version go1.22.0 windows/amd64

Docker: Docker version 25.0.3, build 4debf41

docker-compose: Docker Compose version v2.24.5-desktop.1

πŸš€ Installing

1- To install the dependencies you can run the following command in the root folder:

$ go mod tidy
$ go mod download

OBS: We have the development .env file committed to the project, but you can change it as you see fit

2- (If you already have a PostgresSQL instance, you can skip this part) You will need a postgresSQL instance, we have a docker-compose ready to create a container, you can run the following command in the root folder

$ docker-compose up -d

3- Up the migrations: Naturally, when running the server it will execute the migrations, but they can be executed by code with (change pg url to yours):

$ migrate -database postgres://myuser:mypassword@localhost:5432/mydatabase?sslmode=disable -path src/db/migrations up

🧹 Formatting the Code

To check the code format you will need instal golangci-lint and run the following command in the root folder:

$ golangci-lint run

πŸ§ͺ Testing

To exec all the tests run the following command in the root folder:

$ go test -p 1 ./src/...

You can add the "-v" flag to see detailed output

$ go test -v -p 1 ./src/...

β˜• Using

First, check the dependencies and the installation process:

Going to root folder and exec:

$ go run .\main.go

Now you can open http://localhost:8080 with your browser to see the result.

You can see the routes in Local Swagger Documentation or you can see the routes documentation in 'rest' folder, this files using de REST Client extension of VSCode, but you can export it any way you want

You can create new migrations using the command

migrate create -ext sql -dir src/db/migrations -seq MIGRATION_NAME

πŸ”’ License

Projeto contΓͺm GNU GENERAL PUBLIC LICENSE.

πŸ‘· Author

Made by Glener Pizzolato! πŸ™‹

Linkedin Badge Gmail Badge

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL