Discover Packages
github.com/nazarslota/unotes/auth
module
Version:
v0.0.0-...-f767cfc
Opens a new window with list of versions in this module.
Published: Aug 20, 2023
License: MIT
Opens a new window with license information.
README
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
You must have Docker installed.
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=
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
You must have Docker
and Docker Compose installed.
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=
Now you need to run the following command.
docker-compose up --detach --build --remove-orphans
Development
Prerequisites
Dependencies
make dependencies
Other
Code generation.
make protobuf
Plugins install.
make protoplugins
Plugins.
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=
Expand ▾
Collapse ▴
Directories
¶
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.
Click to show internal directories.
Click to hide internal directories.