Auth Service for Payment
Welcome to the Auth Service for Payment! π This microservice provides a robust and secure authentication system tailored specifically for payment processing applications.
π Features
- User Registration: Effortlessly register new users with secure password hashing.
- Token Generation: Generate access and refresh tokens to maintain user sessions seamlessly.
- User Management: Easily manage user information with functionalities for checking existing usernames and emails.
- Secure: Employs industry-standard security practices to keep user data safe.
- gRPC Communication: Efficient and high-performance communication using gRPC.
π οΈ Technologies Used
- Golang: A powerful programming language for building efficient and reliable applications.
- gRPC: A modern open-source high-performance RPC framework.
- Bcrypt: For secure password hashing.
- MySQL: A robust relational database for data storage.
π¦ Installation
- Clone the repository:
git clone https://github.com/yourusername/auth-service-payment.git
cd auth-service-payment
- Install dependencies:
go mod tidy
- Set up your environment variables in a .env file based on the provided template.
- Run the application:
go run main.go
Folder Structure
auth-service/
βββ cmd/
β βββ auth/
β βββ main.go # Entry point for the auth service
βββ internal/
β βββ config/ # Configuration files (e.g., for environment variables)
β β βββ config_test.go
β β βββ mysql.go
β β βββ config.go
β βββ handler/ # HTTP/gRPC handlers
β β βββ auth_handler.go # Handlers for authentication-related endpoints
β βββ middleware/ # Middleware functions (e.g., authentication, logging)
β β βββ auth_middleware.go
β βββ model/ # Data models (e.g., User struct)
β β βββ user.go
β βββ repository/ # Repository pattern for database interactions
β β βββ auth_repository_impl.go
β β βββ auth_repository.go
β β βββ auth_repository_test.go
β βββ service/ # Business logic and service layer
β β βββ auth_service_impl.go
β β βββ auth_service_test.go
β β βββ auth_service.go # Logic for handling authentication
β βββ utils/ # Utility functions (e.g., token generation, validation)
β βββ global.go
β βββ password_utils.go
β βββ utils_test.go
β βββ token.go
βββ mocks/ # Integration tests (optional)
β βββ mock_config.go
β βββ mock_database.go
β βββ mock_hashpassword.go
β βββ mock_repository.go
β βββ mock_token.go
βββ .env # Environment variables (optional)
βββ .gitignore
βββ coverage.html
βββ coverage.out
βββ LICENSE
βββ readme.md
βββ go.mod # Go module file
βββ go.sum
π Usage
This service exposes several gRPC endpoints for managing user authentication. Here's a brief overview:
- RegisterUser: Register a new user and receive access and refresh tokens.
- LoginUser: Authenticate an existing user and retrieve tokens.
- RefreshToken: Refresh user access tokens seamlessly.
π§ͺ Testing
To ensure code quality and functionality, unit tests are implemented using github.com/stretchr/testify. Run the tests with:
go test -coverprofile=coverage.out ./... && go tool cover -html=coverage.out -o coverage.html
π€ Contributing
We welcome contributions! Please fork the repository and submit a pull request with your changes.
- Fork it!
- Create your feature branch (git checkout -b feature/MyFeature)
- Commit your changes (git commit -m 'Add some feature')
- Push to the branch (git push origin feature/MyFeature)
- Open a pull request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries or feedback, please reach out to fajaramaulanadev@gmail.com.