https://github.com/hvalfangst/gin-api
API programmed in Golang with the Gin framework providing CRUD endpoints for the domain of wine. Authentication and authorization is being handled by middleware.
https://github.com/hvalfangst/gin-api
authentication authorization gin-gonic go-pg golang jwt jwt-tokens middlware
Last synced: 3 months ago
JSON representation
API programmed in Golang with the Gin framework providing CRUD endpoints for the domain of wine. Authentication and authorization is being handled by middleware.
- Host: GitHub
- URL: https://github.com/hvalfangst/gin-api
- Owner: hvalfangst
- Created: 2023-08-06T20:20:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-13T22:51:21.000Z (over 1 year ago)
- Last Synced: 2025-01-25T06:25:09.478Z (5 months ago)
- Topics: authentication, authorization, gin-gonic, go-pg, golang, jwt, jwt-tokens, middlware
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gin API with auth middleware
## Abstract
This repository contains a Go-based API developed using the Gin web framework.
The API features robust authentication and authorization mechanisms, allowing secure access to various endpoints.
Users can create accounts, log in, and interact with wine-related data while adhering to specific access rights.## Middleware
The API utilizes the following middleware functions:
* Authenticate: Validate users by querying DB with basic auth headers contained in request. Used before 'login' handler in user context.
* Authorize: Manages user access control based on JWT token claims. Used before handlers in wine context.
* LogTokenActivity: Logs user activity by creating token activity records for auditing purposes. Used after handlers in wine context.## User deletion goroutine
A goroutine will be launched on startup which periodically (every 10 seconds) checks for users in the database who have been designated for removal.
That is, users which has the 'for_deletion' flag set to 'true.'
If any such users are found, they are deleted from the database.## Requirements
* x86-64
* Linux/Unix
* [Golang](https://go.dev/)
* [Docker](https://www.docker.com/products/docker-desktop/)## Startup
The script "up" provisions resources and starts our application by executing the following:
```
1. docker-compose -f docker/db/docker-compose.yml up -d
2. go build -o gin_api_with_auth src/main.go
3. ./gin_api_with_auth
```## Shutdown
The script "down" deletes our dev and test databases by executing the following:
```
1. docker-compose -f db/docker-compose.yml down
```## Postman Collection
The repository includes a Postman collection in the 'postman' directory.