auth

module
v0.0.0-...-f767cfc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT

README

Auth

This is an authentication and authorization microservice written in Go and built using REST and gRPC. It uses PostgreSQL and Redis for storage and implements the OAuth2.0 authentication method for secure authentication.

Run

Docker
  1. You must have Docker installed.
  2. Now in the main folder of the project you need to create an .env file in which you need to configure to add the following environment variables.
    AUTH_ACCESS_TOKEN_SECRET=
    AUTH_REFRESH_TOKEN_SECRET=
    
    AUTH_POSTGRESQL_HOST=
    AUTH_POSTGRESQL_PORT=
    AUTH_POSTGRESQL_USERNAME=
    AUTH_POSTGRESQL_PASSWORD=
    AUTH_POSTGRESQL_DBNAME=
    AUTH_POSTGRESQL_SSLMODE=
    
    AUTH_REDIS_ADDR=
    AUTH_REDIS_PASSWORD=
    AUTH_REDIS_DB=
    
  3. Now run the following commands to build and run the Docker container.
    docker build --tag auth .
    docker run --publish 8082:8082 --publish 8092:8092 --name auth --detach --restart always --env-file ./.env auth
    
Docker Compose
  1. You must have Docker and Docker Compose installed.
  2. Now in the main folder of the project you need to create an .env file in which you need to configure to add the following environment variables.
    AUTH_ACCESS_TOKEN_SECRET=
    AUTH_REFRESH_TOKEN_SECRET=
    
    AUTH_POSTGRESQL_HOST=
    AUTH_POSTGRESQL_PORT=
    AUTH_POSTGRESQL_USERNAME=
    AUTH_POSTGRESQL_PASSWORD=
    AUTH_POSTGRESQL_DBNAME=
    AUTH_POSTGRESQL_SSLMODE=
    
    AUTH_REDIS_ADDR=
    AUTH_REDIS_PASSWORD=
    AUTH_REDIS_DB=
    
  3. Now you need to run the following command.
    docker-compose up --detach --build --remove-orphans
    

Development

Prerequisites
Dependencies
make dependencies
Other
Protocol Buffer
  • Code generation.

    make protobuf
    
  • Plugins install.

    make protoplugins
    
  • Plugins.

Swagger
Migrations
  • Using migrate tool.

    • New migration.

      migrate create -ext sql -dir schema/ -seq <name>
      
    • Up.

      migrate -path ./schema -database 'postgres://<username>:<password>@<host>:<port>/<database>' up
      migrate -path ./schema -database 'postgres://<username>:<password>@<host>:<port>/<database>?sslmode=disable' up
      
    • Down.

      migrate -path ./schema -database 'postgres://<username>:<password>@<host>:<port>/<database>' down
      migrate -path ./schema -database 'postgres://<username>:<password>@<host>:<port>/<database>?sslmode=disable' down`
      
  • Tools install.

    make tools
    
  • Tools.

Environment variables
AUTH_ACCESS_TOKEN_SECRET=
AUTH_REFRESH_TOKEN_SECRET=

AUTH_POSTGRESQL_HOST=
AUTH_POSTGRESQL_PORT=
AUTH_POSTGRESQL_USERNAME=
AUTH_POSTGRESQL_PASSWORD=
AUTH_POSTGRESQL_DBNAME=
AUTH_POSTGRESQL_SSLMODE=
   
AUTH_REDIS_ADDR=
AUTH_REDIS_PASSWORD=
AUTH_REDIS_DB=

Directories

Path Synopsis
api
cmd
internal
storage
Package storage provides storage implementations.
Package storage provides storage implementations.
storage/postgres
Package postgres provides a PostgreSQL repository implementation for storing and managing users.
Package postgres provides a PostgreSQL repository implementation for storing and managing users.
storage/redis
Package redis provides a Redis repository implementation for storing and managing refresh tokens.
Package redis provides a Redis repository implementation for storing and managing refresh tokens.
pkg
errors
Package errors implements a custom error type HTTPError.
Package errors implements a custom error type HTTPError.
jwt
Package jwt provides functionality for creating and parsing JSON Web Tokens (JWTs) using HMAC-SHA256 for signature validation.
Package jwt provides functionality for creating and parsing JSON Web Tokens (JWTs) using HMAC-SHA256 for signature validation.
logger
Package logger provides Logger, which is a wrapper around zerolog.Logger.
Package logger provides Logger, which is a wrapper around zerolog.Logger.

Jump to

Keyboard shortcuts

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