一键导入
golang-gin-auth
JWT auth and RBAC for Go Gin APIs. Use when adding login, signup, JWT tokens, role checks, protected routes, or password hashing to a Gin app.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
JWT auth and RBAC for Go Gin APIs. Use when adding login, signup, JWT tokens, role checks, protected routes, or password hashing to a Gin app.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Build REST APIs with Go Gin. Use when creating Go web servers, adding Gin routes, writing handlers, or asking about middleware, binding, error handling, or project structure.
PostgreSQL integration for Go Gin with GORM/sqlx. Use when adding a database, writing queries, creating repositories, running migrations, or wiring DB layers in a Gin project.
Software architect for Go Gin APIs. Use when making architecture decisions, evaluating complexity, designing systems, choosing patterns, or coordinating across gin skills.
Deploy Go Gin APIs with Docker, docker-compose, Kubernetes. Use when Dockerizing a Go app, setting up docker-compose, deploying to K8s, or configuring CI/CD and health probes.
PostgreSQL DBA for Go Gin APIs. Use when designing schemas, analyzing migrations, choosing indexes, optimizing queries, or selecting extensions (pgvector, PostGIS, TimescaleDB).
Swagger/OpenAPI docs for Go Gin with swaggo/swag. Use when adding API docs, Swagger UI, endpoint annotations, or generating swagger.json for a Gin application.
| name | golang-gin-auth |
| description | JWT auth and RBAC for Go Gin APIs. Use when adding login, signup, JWT tokens, role checks, protected routes, or password hashing to a Gin app. |
| license | MIT |
| metadata | {"author":"henriqueatila","version":"1.0.5"} |
Add JWT-based authentication and role-based access control to a Gin API. This skill covers the patterns you need for secure APIs: JWT middleware, login handler, token lifecycle, and RBAC.
Dependencies: github.com/golang-jwt/jwt/v5, golang.org/x/crypto, github.com/google/uuid, golang.org/x/time/rate
Claims design:
Claims embeds jwt.RegisteredClaims + UserID, Email, RoleRefreshClaims embeds jwt.RegisteredClaims only (minimal payload)RegisteredClaims.ID carries the jti — required for token blacklistingTokenConfig fields: AccessSecret, RefreshSecret, AccessTTL (e.g. 15m), RefreshTTL (e.g. 7d), Issuer, Audience. Load from env — never hardcode secrets.
Token generation rules:
jti (uuid.NewString()), NotBefore, IssuedAt, ExpiresAtParseWithClaims — use t.Method != jwt.SigningMethodHS256 (not *jwt.SigningMethodHMAC which accepts HS256/384/512). An attacker could craft tokens with alg: none or a different HMAC variant if the check is too broaderrors.Is(err, jwt.ErrTokenExpired) for distinct handlingJWT middleware flow: Extract Authorization: Bearer <token> → ParseAccessToken → c.Set(ClaimsKey, claims) + c.Set(UserIDKey, claims.UserID) → c.Next()
Getting current user in handlers:
c.GetString(middleware.UserIDKey)c.Get(middleware.ClaimsKey) then type-assert to *auth.ClaimsPassword hashing: bcrypt.GenerateFromPassword([]byte(password), 12) — cost >= 12 for production.
Login security: Return generic "invalid credentials" for both wrong email and wrong password — never leak whether the email exists.
Rate limiting: Apply IPRateLimiter to auth routes (e.g. 5 req/min per IP). In-process map works for single instances; use Redis-backed limiter for multi-instance deployments.
Route wiring summary:
| Group | Middleware | Routes |
|---|---|---|
/auth | IPRateLimiter | POST /login, POST /register, POST /refresh |
| protected | Auth(cfg, logger) | all authenticated routes |
/admin | Auth + RequireRole("admin") | admin-only routes |
curl with expired tokens, invalid signatures, missing headers. Paste the 401/403 response. "I believe it rejects" is not "the output shows 401"This skill handles JWT authentication, token lifecycle, password hashing, RBAC middleware, and rate limiting for Go Gin APIs. Does NOT handle API routing/handlers (see golang-gin-api), database queries (see golang-gin-database), deployment (see golang-gin-deploy), or testing (see golang-gin-testing).
Load these when you need deeper detail:
Auth Implementation:
JWT Patterns:
RBAC:
OAuth2 / Social Login:
CAPTCHA:
UserRepository interface and GetByEmail implementation: see the golang-gin-database skillreferences/clean-architecture.md)If this skill doesn't cover your use case, consult the Gin documentation, golang-jwt GoDoc, or Gin GoDoc.