Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saeedmaldosary/go-authentication-jwt
Go-Authentication-JWT is a robust authentication system built using Go (Golang). It leverages the power of JWT (JSON Web Tokens) to provide secure token-based authentication for applications. The project is designed with modularity in mind, making it easy to integrate with existing Go applications or to use as a foundation for new projects.
https://github.com/saeedmaldosary/go-authentication-jwt
authentication gin go jwt
Last synced: 12 days ago
JSON representation
Go-Authentication-JWT is a robust authentication system built using Go (Golang). It leverages the power of JWT (JSON Web Tokens) to provide secure token-based authentication for applications. The project is designed with modularity in mind, making it easy to integrate with existing Go applications or to use as a foundation for new projects.
- Host: GitHub
- URL: https://github.com/saeedmaldosary/go-authentication-jwt
- Owner: saeedmaldosary
- Created: 2023-08-21T12:17:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-24T07:59:55.000Z (over 1 year ago)
- Last Synced: 2024-11-13T10:48:17.451Z (2 months ago)
- Topics: authentication, gin, go, jwt
- Language: Go
- Homepage:
- Size: 80.6 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go-Authentication-JWT
A simple Go application that demonstrates user authentication using JWT (JSON Web Tokens).
## Features
- **User Signup**: Allows new users to register.
- **User Login**: Authenticates users and provides a JWT token.
- **Token Validation**: Validates the provided JWT token.## Setup and Initialization
1. **Environment Variables**: Ensure you have a `.env` file with the necessary environment variables. The application uses `godotenv` to load these variables.
2. **Database Connection**: The application connects to a PostgreSQL database. The connection string is fetched from the environment variable `DB`.3. **Database Synchronization**: The application uses GORM for ORM and automatically migrates the user model to the database.
## Endpoints
- **Signup**: `POST /signup`
- Payload:
```json
{
"Email": "[email protected]",
"Password": "your_password"
}
```
- **Login**: `POST /login`
- Payload:
```json
{
"Email": "[email protected]",
"Password": "your_password"
}
```
- Response: Returns a JWT token.- **Validate**: `GET /validate`
- Requires JWT token in the `Authorization` cookie. Validates the token and returns the associated user.## Middleware
- **RequireAuth**: This middleware checks for the `Authorization` cookie in the request, decodes the JWT token, validates it, and attaches the associated user to the request.
## Models
- **User Model**: Represents a user with fields `Email` and `Password`. The email is unique for each user.