A runnable HTTP server that wires AuthCore into Gin. Same routes as the Fiber example, different framework.
This example is its own Go module (separate
go.mod) so the root library has no runtime dependency on Gin. Run it from this directory.
cd examples/gin
go run .Server listens on :3000.
| Method | Path | Auth | Purpose |
|---|---|---|---|
POST |
/register |
none | Hash + store the new user's password |
POST |
/login |
none | Verify password, issue an access + refresh pair |
GET |
/me |
Authorization: Bearer <access> |
Verify the access token, return claims |
POST |
/refresh |
refresh token in body | Rotate the pair, replace the stored hash |
# 1. Register
curl -X POST localhost:3000/register \
-H 'content-type: application/json' \
-d '{"email":"ana@example.com","password":"Str0ng-P@ssword!"}'
# 2. Login: capture the tokens
curl -X POST localhost:3000/login \
-H 'content-type: application/json' \
-d '{"email":"ana@example.com","password":"Str0ng-P@ssword!"}'
# 3. Protected route
curl localhost:3000/me -H 'authorization: Bearer <access-token>'
# 4. Rotate
curl -X POST localhost:3000/refresh \
-H 'content-type: application/json' \
-d '{"refresh_token":"<refresh-token>"}'Providerpassed to multiple modules once at startup.pwdMod.Hash/pwdMod.Verifyfor registration + login.jwtMod.CreateTokenswith typedUserClaims.jwtMod.VerifyAccessTokenin a Gin middleware for/me.jwtMod.HashRefreshToken→ DB lookup →jwtMod.VerifyRefreshTokenHash→jwtMod.RotateTokens: the full anti-reuse rotation pattern.
User storage is an in-memory map for brevity. Swap it for your real database.