Code Monkey home page Code Monkey logo

beretta350 / golang-authentication-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 123 KB

A simple lightweight authentication API built in Golang designed to be a fast and easy start for other projects.

License: MIT License

Dockerfile 0.79% Go 97.77% JavaScript 1.43%
bcrypt csrf csrf-protection docker docker-compose gin gin-framework gin-gonic go golang jwt jwt-auth jwt-authentication jwt-token mongo mongodb xss integration-testing test-automation testcontainers

golang-authentication-api's Introduction

Golang Authentication API

Golang JWT Docker MongoDB

A simple lightweight authentication API built in Golang designed to be a fast and easy start for other projects. It includes JWT token generation for secure authentication, bcrypt cryptography for password hashing, and MongoDB for storing user credentials. This API also tries to avoid CSRF and XSS attacks to ensure basic levels of security.

Layout

The project focuses on enabling a fast and easy start. Thinking on that, nothing better than the golang standards project layout. A well known layout among Go users that encourages best practices like modularization and separation of concerns, which can improve code quality and scalability.

So, if you have questions about the layout check the link above!

Key Technologies

  • GIN (Web Framework): The application leverages the Gin web framework to handle HTTP requests, routing, and middleware, ensuring fast and scalable API development.

  • JWT (JSON Web Token): JWT token creation, validation, and parsing to provide a secure and efficient way to manage authentication and authorization in the application.

  • Bcrypt (Cryptography package): Securely hash and compare passwords providing a reliable method for storing and verifying passwords, ensuring that user credentials are protected against unauthorized access.

  • Testcontainers: Testcontainers is a library for creating lightweight, disposable Docker containers for automated tests. It enables reliable and reproducible test environments, ensuring consistent integration testing by mimicking production-like setups.

  • Docker: Docker is used to containerize the application, making it easy to manage dependencies and ensure consistency across different environments.

  • MongoDB: NoSQL database with a robust and efficient way to perform CRUD operations, query data, and manage transactions in the application.

Get Started

To get started with the authentication api, follow these steps:

  1. Clone the repository to your local machine.

  2. Ensure you have Golang and Docker installed.

  3. Build and run the application using Docker Compose.

    • docker compose up -d --build
  4. Access the application's API endpoints from localhost:8080 to interact with the authetication api.

Usage

Use the API endpoints to manage your users effectively.

Example API Endpoints

  • GET /user?id=<userId>: Get user infos.
  • GET /refreshToken: Refresh access token using refresh token.
  • POST /login: Login with user credentials (returns JWT with user ID claim).
  • POST /save: Create a new user.
  • PUT /update?id=<userId>: Update user data.
  • DELETE /delete?id=<userId>: Delete user.

OBS: Passwords must be at least 8 characters long

Testing

The application is covered by integration tests focused on verifying that the application works correctly as a whole.

Run integration tests:

  • go test github.com/Beretta350/authentication/tests/integration

OBS: Becareful with timeout setted, the integration tests running time is arround 100s

Contributions

We welcome contributions to this authentication api. If you're interested in enhancing or extending its functionality, feel free to create pull requests or open issues on the repository.

Enjoy using this simple lightweight authentication API built with Golang and Gin!

golang-authentication-api's People

Contributors

beretta350 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.