simple-auth

module
v0.0.0-...-27850da Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Unlicense

README

Simple Auth

Go GoDoc Go Report Card codecov

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;

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 user
  • POST /v1/users/login: login with given credentials
  • GET /v1/users/current: get current user

with cURL:

  1. Create a new user
curl --location --request POST 'localhost:8080/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "dummy@email.com",
    "password": "hello123"
}'
  1. Login with given credentials
curl --location --request POST 'localhost:8080/v1/users/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "dummy@email.com",
    "password": "hello123"
}'
  1. 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

Directories

Path Synopsis
cmd
internal
pb/v1
Package pb is a reverse proxy.
Package pb is a reverse proxy.

Jump to

Keyboard shortcuts

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