{"id":20733752,"url":"https://github.com/pageton/authify","last_synced_at":"2025-04-23T22:56:39.582Z","repository":{"id":258475869,"uuid":"873736654","full_name":"pageton/authify","owner":"pageton","description":"Authify is a simple and efficient authentication system built with Go and Fiber, designed to handle user authentication securely and flexibly for web applications.","archived":false,"fork":false,"pushed_at":"2024-10-21T12:33:53.000Z","size":191,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T22:56:29.134Z","etag":null,"topics":["auth","auth-services","auth0","authentication","authentication-backend","authify","backend","fiber","gol"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pageton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T16:23:10.000Z","updated_at":"2025-04-10T16:04:01.000Z","dependencies_parsed_at":"2024-10-19T07:09:06.685Z","dependency_job_id":"d39bcc95-c40f-4a5b-b92c-50de23670ba4","html_url":"https://github.com/pageton/authify","commit_stats":null,"previous_names":["pageton/authify"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageton%2Fauthify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageton%2Fauthify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageton%2Fauthify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageton%2Fauthify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pageton","download_url":"https://codeload.github.com/pageton/authify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528720,"owners_count":21445513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","auth-services","auth0","authentication","authentication-backend","authify","backend","fiber","gol"],"created_at":"2024-11-17T05:26:54.488Z","updated_at":"2025-04-23T22:56:39.565Z","avatar_url":"https://github.com/pageton.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Authify Service\n\nAuthify is an authentication service built using Go, Fiber, and SQLite. It provides functionalities for user registration, login, and JWT-based authentication.\n\n## Features\n\n- **Fast and efficient** authentication service\n- **Supports user registration** and **login** functionalities\n- **JWT-based** secure authentication\n- **SQLite database support** with both on-disk and in-memory options\n- **Synchronous API** ensuring better performance and concurrency handling\n- **Rate limiting** for request control\n- **CORS support** for secure API access from different origins\n- **Middleware handling** for error logging, request logging, and authentication checks\n\n## Project Structure\n\n```\n└── 📁authify\n    └── 📁cmd\n        └── main.go\n    └── 📁config\n        └── config.go\n    └── 📁db\n        └── 📁database\n            └── data.db\n        └── 📁migrations\n            └── 📁db_migrations\n                └── setup.go\n            └── queries.sql\n            └── schema.sql\n            └── sqlc.yaml\n        └── 📁model\n            └── db.go\n            └── models.go\n            └── queries.sql.go\n    └── 📁handler\n        └── login_handler.go\n        └── logout_handler.go\n        └── register_handler.go\n    └── 📁middleware\n        └── auth_middleware.go\n        └── cors_middleware.go\n        └── error_handling.go\n        └── rate_limiting.go\n        └── request_logging.go\n    └── 📁models\n        └── user.go\n    └── 📁services\n        └── jwt_service.go\n    └── .env\n    └── .env.example\n    └── .gitignore\n    └── docker-compose.yml\n    └── Dockerfile\n    └── go.mod\n    └── go.sum\n    └── LICENSE\n    └── Makefile\n    └── README.md\n```\n\n## Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/pageton/authify.git\n   cd authify\n   ```\n\n2. Install dependencies:\n\n   ```bash\n   go mod tidy\n   ```\n\n3. Copy the example environment file:\n\n   ```bash\n   cp .env.example .env\n   ```\n\n## Database Setup\n\nTo apply the schema for the SQLite database, run the following command:\n\n```bash\nsqlite3 ./db/database/data.db \u003c ./db/migrations/schema.sql\n```\n\nThis will create the necessary tables and indexes for your application.\n\n## Using sqlc\n\nTo generate the Go code from your SQL queries, use `sqlc`. Ensure that you have the correct `sqlc.yaml` configuration file.\n\n### Run the following command to generate Go code from SQL:\n\n```bash\nmake sqlc-generate\n```\n\n## .env Configuration\n\nThe `.env` file contains configuration variables that the project uses. Here are the key variables:\n\n- `SECRET_KEY`: The secret key used for JWT encryption. You can generate a 256-bit key using OpenSSL:\n\n  ```bash\n  openssl rand -base64 32\n  ```\n\n- `DATABASE_PATH`: The path to the SQLite database file.\n\n- `PORT`: The port on which the server runs. For Docker or public deployment, set it as `0.0.0.0:3000`.\n\n- `LIMIT`: The maximum number of requests allowed per second (rate limiting).\n\n### Example `.env` file:\n\n```env\nSECRET_KEY=your_generated_secret_key\nDATABASE_PATH=./db/database/data.db\nPORT=:3000\nLIMIT=5\n```\n\n## Running the Project\n\n### Development Mode\n\nTo run the project in development mode:\n\n```bash\ngo run ./cmd\n```\n\nThis will execute the `main.go` file located in the `cmd` folder.\n\n### Build and Run\n\nTo build and run the project in production mode:\n\n1. Build the project:\n\n   ```bash\n   go build -o auth ./cmd\n   ```\n\n2. Run the built binary:\n\n   ```bash\n   ./auth\n   ```\n\n## Docker Setup\n\n### Build the Docker Image\n\n```bash\nmake docker-build\n```\n\n### Run the Docker Container\n\n```bash\nmake docker-run\n```\n\nFor public deployment, ensure that the port is set to `0.0.0.0:3000` in the `.env` file.\n\n## API Endpoints\n\n### Registration Endpoint\n\n- **POST** `/register`\n  - Body:\n    ```json\n    {\n      \"username\": \"your_username\",\n      \"password\": \"your_password\"\n    }\n    ```\n\n### Login Endpoint\n\n- **POST** `/login`\n  - Body:\n    ```json\n    {\n      \"username\": \"your_username\",\n      \"password\": \"your_password\"\n    }\n    ```\n\n### Logout Endpoint\n\n- **POST** `/logout`\n  - Body:\n    ```json\n    {\n      \"user_id\": \"user_id_to_logout\"\n    }\n    ```\n\n### Protected Endpoint\n\n- **GET** `/protected`\n  - Headers: Must include a valid JWT token in the authorization header.\n\n  ```bash\n  Authorization: Bearer \u003cyour_jwt_token\u003e\n  ```\n\n## Makefile Commands\n\n1. **run**: \n   - Runs the Go project by executing the main file located in `cmd/main.go`.\n\n2. **migrate db-up**: \n   - Runs database migrations using the setup file in `db/migrations/db_migrations/setup.go`.\n\n3. **build**: \n   - Compiles the Go project into a binary named `authfiy`.\n\n4. **clean**: \n   - Cleans up the project by removing the compiled binary.\n\n5. **rebuild**: \n   - Cleans and rebuilds the project from scratch.\n\n6. **all**: \n   - Builds and then immediately runs the project.\n\n7. **docker-build**: \n   - Builds the Docker image for the project using the Dockerfile.\n\n8. **docker-run**: \n   - Runs the Docker container and logs the output. The container will run on the host network using the specified port from `.env`.\n\n9. **docker-clean**: \n   - Stops and removes the Docker container if it's running.\n\n10. **docker-restart**: \n    - Stops, removes, and then restarts the Docker container.\n\n11. **docker-compose-up**: \n    - Runs the project using `docker-compose`.\n\n12. **sqlc-generate**: \n    - Generates Go code from SQL queries based on the configuration file located at `db/migrations/sqlc.yaml`.\n\n13. **help**: \n    - Displays all available `Makefile` commands with a brief description.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpageton%2Fauthify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpageton%2Fauthify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpageton%2Fauthify/lists"}