Documentation
¶
Overview ¶
Package main demonstrates a minimal HTTP integration with goAuth.
It starts a local HTTP server on :8080 backed by miniredis (no external Redis required) and an in-memory user provider stub.
Endpoints:
POST /login — JSON {"username":"...", "password":"...", "remember":true|false}
POST /refresh — rotates tokens via the refresh-token cookie
POST /logout — destroys the current session (by access token)
GET /protected — middleware-guarded route (requires valid access token)
Run:
go run ./examples/http-minimal
Then:
# login (stores refresh cookie in cookie jar)
curl -i -c jar.txt -X POST localhost:8080/login \
-H 'Content-Type: application/json' \
-d '{"username":"alice@example.com","password":"correct-horse"}'
# call protected (uses access token from login response)
curl -i localhost:8080/protected -H "Authorization: Bearer <ACCESS_TOKEN>"
# refresh (uses cookie jar)
curl -i -b jar.txt -c jar.txt -X POST localhost:8080/refresh
# logout (invalidates session by access token, clears refresh cookie)
curl -i -b jar.txt -c jar.txt -X POST localhost:8080/logout \
-H "Authorization: Bearer <ACCESS_TOKEN>"
Click to show internal directories.
Click to hide internal directories.