# README
Simple Auth
An example user registration and authentication service featuring;
- gRPC Server
- HTTP Server with RESTful endpoints
- JWT-based authentication
- Swagger REST API documentation
- Containerized integration tests
- Data validation
Service uses following Go packages;
- Database ORM: gorm
- JWT: golang-jwt
- RESTful Endpoints: grpc-gateway
- Validation: protoc-gen-validate
Quick Run
docker-compose build
docker-compose up
will build and start these containers;
grpc_server
http_server
db
(postgres:13.1-alpine)integration-tests
RESTful API
After Quick Run
, you have a RESTful API server running at http://localhost:8080. It provides the following endpoints:
POST /v1/users
: create a new userPOST /v1/users/login
: login with given credentialsGET /v1/users/current
: get current user
with cURL:
- Create a new user
curl --location --request POST 'localhost:8080/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
"password": "hello123"
}'
- Login with given credentials
curl --location --request POST 'localhost:8080/v1/users/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
"password": "hello123"
}'
- Get current user
curl --location --request GET 'localhost:8080/v1/users/current' \
--header 'Authorization: <TOKEN_FROM_STEP2>'
API Documentation
Swagger UI is available (see Quick Run
) at http://localhost:8080/swagger-ui/
Development
Install required tools:
make install-tools
Generate gRPC and REST bindings:
make generate
Environment variables required when running services locally:
DB_HOST=localhost;
DB_NAME=simple_auth;
DB_USERNAME=local;
DB_PASSWORD=local;
DB_PORT=5432;
DB_SSL_MODE=disable
GRPC_SERVER_ADDR=localhost:8070
HTTP_SERVER_ADDR=localhost:8080
Tests
Unit Tests
make test
Integration Tests
There's the users/service_integration_test.go
test covering the basic functionality. After running gRPC server and
database server (see Quick Run) just run test with tags
flag.
make test-integration
or easier way is just running integration-test
with docker-compose:
docker-compose build
docker-compose up
# Packages
No description provided by the author