henriqueatila/golang-gin-best-practices / skills/golang-gin-auth
golang-gin-auth
VerifiedJWT 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.4 KB |
| metadata.json | config | 499 B |
| references/auth-implementation-core.md | markdown | 3.5 KB |
| references/auth-implementation-handlers.md | markdown | 3.9 KB |
| references/auth-ip-rate-limiter.md | markdown | 1.5 KB |
| references/auth-middleware.md | markdown | 2.2 KB |
| references/captcha-middleware.md | markdown | 3.8 KB |
| references/jwt-patterns-blacklist.md | markdown | 3.4 KB |
| references/jwt-patterns-rs256.md | markdown | 2.7 KB |
| references/jwt-patterns-storage-and-csrf.md | markdown | 3.8 KB |
| references/jwt-patterns-tokens.md | markdown | 4.8 KB |
| references/oauth2-flows.md | markdown | 3.8 KB |
| references/oauth2-github-profile.md | markdown | 1.3 KB |
| references/oauth2-google-and-security.md | markdown | 2.0 KB |
| references/rbac-hierarchy-and-tenant.md | markdown | 3.2 KB |
| references/rbac-middleware.md | markdown | 4.2 KB |
| references/rbac-resource-and-impersonation.md | markdown | 3.8 KB |
| references/rbac-route-wiring.md | markdown | 1.6 KB |
references/oauth2-google-and-security.md
View on GitHub# OAuth2 / Social Login — Google Flow, Route Registration & Security Checklist
See also: `oauth2-flows.md`
## Google OAuth2 Flow
Config differences only — callback pattern is identical to GitHub. Use the Google userinfo endpoint instead of the GitHub API:
```go
// internal/auth/google_userinfo.go
// GET https://www.googleapis.com/oauth2/v3/userinfo
// Authorization: Bearer <access_token>
// Response fields: sub (ID), email, name, picture
```
Implement `GoogleLogin` and `GoogleCallback` handlers following the same pattern as `GitHubLogin` / `GitHubCallback` in `oauth2-flows.md`, substituting `h.googleCfg` and the Google userinfo endpoint.
## Route Registration
Wire into the Gin router alongside existing auth routes:
```go
// internal/router/router.go
authGroup := r.Group("/auth")
authGroup.Use(middleware.IPRateLimiter(5, time.Minute))
{
authGroup.POST("/login", authHandler.Login)
authGroup.POST("/register", authHandler.Register)
authGroup.POST("/refresh", authHandler.Refresh)
// OAuth2 routes — no rate limiter needed (redirects, not form submissions)
authGroup.GET("/github", oauth2Handler.GitHubLogin)
authGroup.GET("/github/callback", oauth2Handler.GitHubCallback)
authGroup.GET("/google", oauth2Handler.GoogleLogin)
authGroup.GET("/google/callback", oauth2Handler.GoogleCallback)
}
```
## Security Checklist
| Risk | Mitigation |
|------|-----------|
| CSRF on callback | Always verify and delete state in a single atomic Redis DEL operation |
| Insecure redirect URL | Set `RedirectURL` to `https://` only; validate `REDIRECT_URL` env var at startup |
| Token leakage | Store OAuth2 access tokens server-side only; never send to client |
| Open redirect | Register exact redirect URLs in the OAuth2 provider dashboard; reject any deviation |
| Excessive scope | Request only the scopes you actually need (`user:email` not full `user`) |
| Provider error leakage | Return generic errors — never expose provider error details to clients |
| Long CSRF window | Keep state TTL short (10 minutes max) |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |