golang-gin-auth

Implement JWT authentication and RBAC authorization for Go Gin APIs.

3|Updated Mar 1, 2026
One-click install
npx skills add https://github.com/henriqueatila/golang-gin-best-practices --skill golang-gin-auth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-gin-auth
Source: https://github.com/henriqueatila/golang-gin-best-practices/tree/main/skills/golang-gin-auth
Command: npx skills add https://github.com/henriqueatila/golang-gin-best-practices --skill golang-gin-auth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/golang-jwt/jwt/v5, golang.org/x/crypto, github.com/google/uuid, golang.org/x/time/rate, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides a robust framework for implementing secure authentication and authorization in Go applications using the Gin web framework, protecting your APIs from unauthorized access and ensuring data integrity.

Core Features & Use Cases

  • JWT Authentication: Securely manage user sessions with short-lived access tokens and long-lived refresh tokens, including mechanisms for token blacklisting and rotation.
  • Role-Based Access Control (RBAC): Implement granular permissions to restrict access to specific API endpoints based on user roles.
  • Password Security: Safely handle user passwords using bcrypt hashing.
  • Use Case: When building a new microservice, integrate this Skill to handle user logins, protect sensitive endpoints like user profiles or admin dashboards, and manage user permissions effectively.

Quick Start

Use the golang-gin-auth skill to add JWT authentication middleware to your Gin API routes.

Frequently Asked Questions about golang-gin-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add JWT authentication and RBAC to a Go Gin API?

JWT authentication and RBAC in a Go Gin API are implemented using middleware that validates access tokens and enforces role-based permissions on specific routes. This includes login and register handlers to securely bootstrap user sessions using bcrypt hashing.

What is the best way to handle JWT token blacklisting and refresh rotation in Gin?

JWT token blacklisting and refresh rotation in Gin are handled by tracking unique token IDs (jti) to invalidate compromised access tokens and issuing new refresh tokens upon each valid use. This prevents stolen short-lived tokens from being reused indefinitely.

Does this Gin JWT authentication approach include rate limiting and CSRF protection?

Yes, this Gin JWT authentication approach includes rate limiting on authentication endpoints and CSRF protection. Rate limiting mitigates brute-force attacks on login routes, while CSRF protection secures state-changing operations against cross-site request forgery.

How do I secure user passwords with bcrypt in a Golang web application?

To secure user passwords with bcrypt in a Golang web application, you hash the plaintext password during user registration and verify the hash against the stored digest during login. This prevents storing raw passwords and protects against database breach exposure.

When do I need RBAC middleware in a Go Gin application?

You need RBAC middleware in a Go Gin application when you must restrict access to sensitive API endpoints based on user roles. It enforces granular permissions, ensuring only authorized users can access admin dashboards or private user profiles.