Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fsobh/auth
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/fsobh/auth
- Owner: fsobh
- Created: 2024-12-11T04:52:28.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-16T06:42:43.000Z (about 1 month ago)
- Last Synced: 2024-12-16T07:37:44.423Z (about 1 month ago)
- Language: Go
- Size: 2.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
Authentication service
- Supports **HTTP/2** and **gRPC** protocols.
- PostgreSQL database with **sqlc** for type-safe queries.
- Redis queue for background tasks.
## ๐ Table of Contents
- [๐ Overview](#-overview)
- [๐พ Features](#-features)
- [๐ Project Structure](#-project-structure)
- [๐ Project Index](#-project-index)
- [๐ Getting Started](#-getting-started)
- [โ๏ธ Prerequisites](#-prerequisites)
- [โ๏ธ Installation](#-installation)
- [๐ค Usage](#๐ค-usage)
- [๐งช Testing](#๐งช-testing)
- [๐ Project Roadmap](#-project-roadmap)
- [๐ฐ Contributing](#-contributing)
- [๐ License](#-license)
- [๐ Acknowledgments](#-acknowledgments)---
## ๐ Overview
A Golang authentication service API, supporting both HTTP/2 and gRPC protocols.
The service is designed to provide user authentication and authorization features,
including user registration, login, and email verification.
The service is built
using a PostgreSQL database with sqlc for type-safe queries and a Redis queue for background tasks.---
## ๐พ Features
- **User Registration**: Register a new user with a unique email, username, and password.
- **Email Verification**: Sends a verification email to a user's email address. **User creation will rollback if verification email fails to send (using transactional queries with callbacks)**
- **User Login**: Authenticate a user with a valid email and password.
- **User Update**: Update a user's profile information, including their email, username, and password.---
## ๐ Project Structure
```sh
โโโ auth/
โโโ db
โ โโโ migration
โ โโโ query
โ โโโ sqlc
โโโ doc
โ โโโ db.dbml
โ โโโ statik
โ โโโ swagger
โโโ gapi
โ โโโ authorization.go
โ โโโ converter.go
โ โโโ error.go
โ โโโ logger.go
โ โโโ metadata.go
โ โโโ rpc_create_user.go
โ โโโ rpc_login_user.go
โ โโโ rpc_update_user.go
โ โโโ rpc_verify_email.go
โ โโโ server.go
โโโ go.mod
โโโ go.sum
โโโ main.go
โโโ makefile
โโโ pb
โ โโโ rpc_create_user.pb.go
โ โโโ rpc_login_user.pb.go
โ โโโ rpc_update_user.pb.go
โ โโโ rpc_verify_email.pb.go
โ โโโ service_auth.pb.go
โ โโโ service_auth.pb.gw.go
โ โโโ service_auth_grpc.pb.go
โ โโโ user.pb.go
โโโ proto
โ โโโ google
โ โโโ protoc-gen-openapiv2
โ โโโ rpc_create_user.proto
โ โโโ rpc_login_user.proto
โ โโโ rpc_update_user.proto
โ โโโ rpc_verify_email.proto
โ โโโ service_auth.proto
โ โโโ user.proto
โโโ sqlc.yaml
โโโ util
โ โโโ config.go
โ โโโ password.go
โ โโโ random.go
โโโ val
โ โโโ validator.go
โโโ worker
โโโ distributor.go
โโโ logger.go
โโโ processor.go
โโโ task_send_verify_email.go
```### ๐ Project Index
AUTH/
__root__
makefile
โฏ makefile with commands for local development
main.go
โฏ Main entry point for API service
go.mod
โฏ Go mod file
go.sum
โฏ Go sum file
sqlc.yaml
โฏ Sqlc V2 configuration file
worker
processor.go
โฏ Task processor for Redis queue - picks up tasks from the queue to process and run them
task_send_verify_email.go
โฏ Redis queue task for sending out the verification email to new users
logger.go
โฏ Logger for the Redis queue
distributor.go
โฏ Redis task distributor interface - distributes the tasks into appropriate queues
proto
user.proto
โฏ proto buff specification for `User` object serialization
rpc_update_user.proto
โฏ proto buff specification for `Update user` request / response serialization
rpc_create_user.proto
โฏ proto buff specification for `Create user` request / response serialization
service_auth.proto
โฏ proto buff specification for API service
rpc_verify_email.proto
โฏ proto buff specification for `Verify email` request / response serialization
rpc_login_user.proto
โฏ proto buff specification for `Login user` request / response serialization
protoc-gen-openapiv2
options
openapiv2.proto
โฏ REPLACE-ME
annotations.proto
โฏ REPLACE-ME
api
httpbody.proto
โฏ REPLACE-ME
field_behavior.proto
โฏ REPLACE-ME
http.proto
โฏ REPLACE-ME
annotations.proto
โฏ REPLACE-ME
doc
db.dbml
โฏ Database markup version of the database schema
statik
statik.go
โฏ Serves static swagger specification page
swagger
swagger-initializer.js
โฏ cloned from swagger-ui
swagger-ui-standalone-preset.js
โฏ cloned from swagger-ui
auth.swagger.json
โฏ cloned from swagger-ui
swagger-ui-es-bundle.js
โฏ cloned from swagger-ui
swagger-ui-bundle.js
โฏ cloned from swagger-ui
index.css
โฏ cloned from swagger-ui
swagger-ui-es-bundle-core.js
โฏ cloned from swagger-ui
swagger-ui.js
โฏ cloned from swagger-ui
swagger-ui.css
โฏ cloned from swagger-ui
index.html
โฏ cloned from swagger-ui
oauth2-redirect.html
โฏ cloned from swagger-ui
gapi
metadata.go
โฏ Helper to capture metadata of gRPC gateway requests
logger.go
โฏ Logger file for gRPC & HTTP requests
authorization.go
โฏ Validates token format for incoming authorized calls
rpc_update_user.go
โฏ Function that is called to update a user record when the api endpoint is invoked
rpc_verify_email.go
โฏ Function that is called to verify a new users email when the api endpoint is invoked
error.go
โฏ Helper to handle generic errors (invalid request params, unauthorized calls)
rpc_login_user.go
โฏ Function that is called to log a user into their account when the api endpoint is invoked
converter.go
โฏ Helper to sanitize User database objects from sensitive data (like password)
rpc_create_user.go
โฏ Function that is called to create a new user account when the api endpoint is invoked
server.go
โฏ Initializes a new Server to run
val
validator.go
โฏ Helper to validate string format for email, names, passwords, etc...
pb
user.pb.go
โฏ Code generated by protoc-gen-go
service_auth_grpc.pb.go
โฏ Code generated by protoc-gen-go
rpc_login_user.pb.go
โฏ Code generated by protoc-gen-go
rpc_update_user.pb.go
โฏ Code generated by protoc-gen-go
rpc_create_user.pb.go
โฏ Code generated by protoc-gen-go
service_auth.pb.go
โฏ Code generated by protoc-gen-go
service_auth.pb.gw.go
โฏ Code generated by protoc-gen-go
rpc_verify_email.pb.go
โฏ Code generated by protoc-gen-go
util
password.go
โฏ Helper to hash & compare passwords
config.go
โฏ Server configs read from app.env
random.go
โฏ Random generator utility
db
sqlc
models.go
โฏ Code generated by sqlc
db.go
โฏ Code generated by sqlc
verify_email.sql.go
โฏ Code generated by sqlc
user.sql.go
โฏ Code generated by sqlc
querier.go
โฏ Code generated by sqlc
tx_verify_email.go
โฏ Transactional write to the database to update user records across tables when email is verified
store.go
โฏ SQLStore provides all functions to execute db queries and transactions. Also used to Mock DB for tests
tx_create_user.go
โฏ Transactional write that creates a user in the database. This transaction has a callback that executes only when the database write is successful. We use this call back to send out the verification email upon sign up
sessions.sql.go
โฏ Code generated by sqlc
query
user.sql
โฏ Queries & annotations pertaining to users for sqlc to generate application database code
sessions.sql
โฏ Queries & annotations pertaining to sessions for sqlc to generate application database code
verify_email.sql
โฏ Queries & annotations pertaining to verifying emails for sqlc to generate application database code
migration
000001_init_schema.up.sql
โฏ Initial database schema for migrate up to use
000001_init_schema.down.sql
โฏ Initial drop database schema for migrate down to use
---
## ๐ Getting Started### โ๏ธ Prerequisites
Before getting started with auth, ensure your runtime environment meets the following requirements:
- **Programming Language:** Go
- **Package Manager:** Go modules
- **Containerization:** Docker### โ๏ธ Installation
Install auth using the following methods:
1. Clone the auth repository:
```sh
โฏ git clone https://github.com/fsobh/auth
```2. Navigate to the project directory:
```sh
โฏ cd auth
```3. Install the project dependencies:
**Using `go modules`** ย [](https://golang.org/)
```sh
โฏ go mod tidy
```### ๐ค Usage
**Steps 1 and 2 are essential for the service to run**1. **Update `app.env` with your environment variables**
| Name | Description
|:------------------:| :---:
| PASETO_PRIVATE_KEY | Hexadecimal private key (Paseto V2)
| PASETO_PUBLIC_KEY | Hexadecimal public key (Paseto V2)
| SES_FROM_EMAIL | Verified AWS SES email address
2. **Update the `.env` file with your AWS account credentials**| Name | Description
|:------------------:| :---:
| AWS_ACCESS_KEY_ID | AWS IAM access key
| AWS_SECRET_ACCESS_KEY | AWS IAM secret key
| AWS_DEFAULT_REGION | AWS region3. Run the following command to start the service:
```sh
โฏ docker compose up
```[//]: # (### ๐งช Testing)
[//]: # (Run the test suite using the following command:)
[//]: # (**Using `go modules`** ย [](https://golang.org/))
[//]: # ()
[//]: # (```sh)[//]: # (โฏ go test ./...)
[//]: # (```)
---
## ๐ Project Roadmap- [X] **`Task 1`**: Authentication + sessions.
- [ ] **`Task 2`**: Add RBAC.
- [ ] **`Task 3`**: Add OAuth2 support.
- [ ] **`Task 4`**: Add unit tests.
- [ ] **`Task 5`**: Add Github actions to auto deploy.---
## ๐ฐ Contributing
- **๐ฌ [Join the Discussions](https://github.com/fsobh/auth/discussions)**: Share your insights, provide feedback, or ask questions.
- **๐ [Report Issues](https://github.com/fsobh/auth/issues)**: Submit bugs found or log feature requests for the `auth` project.
- **๐ก [Submit Pull Requests](https://github.com/fsobh/auth/blob/main/CONTRIBUTING.md)**: Review open PRs, and submit your own PRs.Contributing Guidelines
1. **Fork the Repository**: Start by forking the project repository to your github account.
2. **Clone Locally**: Clone the forked repository to your local machine using a git client.
```sh
git clone https://github.com/fsobh/auth
```
3. **Create a New Branch**: Always work on a new branch, giving it a descriptive name.
```sh
git checkout -b new-feature-x
```
4. **Make Your Changes**: Develop and test your changes locally.
5. **Commit Your Changes**: Commit with a clear message describing your updates.
```sh
git commit -m 'Implemented new feature x.'
```
6. **Push to github**: Push the changes to your forked repository.
```sh
git push origin new-feature-x
```
7. **Submit a Pull Request**: Create a PR against the original project repository. Clearly describe the changes and their motivations.
8. **Review**: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!Contributor Graph
---
## ๐ License
- This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.---
## ๐ Acknowledgments
- [Zero log](https://github.com/rs/zerolog)
- [sqlc](https://github.com/sqlc-dev/sqlc-gen-go)
- [proto buf](https://github.com/golang/protobuf)
- [mockdb](https://pkg.go.dev/github.com/tmaiaroto/discfg/storage/mockdb)
- [statik](https://github.com/rakyll/statik)
- [asynq](https://github.com/hibiken/asynq)---