Skip to content

Commit 567437b

Browse files
committed
feat: Enhance OAuth2 handlers and user authentication endpoints
- Added Swagger documentation for Google, Facebook, and GitHub OAuth2 login and callback handlers. - Improved error handling in user registration and login by using structured error responses. - Introduced new endpoints for refreshing tokens, requesting password resets, and verifying emails with appropriate documentation. - Updated user profile retrieval to return structured user response. - Added DTOs for error and message responses to standardize API responses.
1 parent a61de3c commit 567437b

File tree

11 files changed

+2492
-15
lines changed

11 files changed

+2492
-15
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A modern, production-ready Go REST API for authentication and authorization, fea
1212
- Redis for token/session management
1313
- Dockerized for local development & deployment
1414
- Unit & integration tests
15+
- **Interactive Swagger API documentation**
1516

1617
## 🗂️ Project Structure
1718
```
@@ -22,6 +23,23 @@ pkg/ # Models, DTOs, errors, JWT helpers
2223
Dockerfile, docker-compose.yml, dev.sh, dev.bat
2324
```
2425

26+
## 📖 API Documentation (Swagger)
27+
After starting the server, access the interactive API docs at:
28+
29+
- [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/index.html)
30+
31+
You can try out all endpoints, including social logins, directly from the browser.
32+
33+
## 🔄 Regenerating Swagger Documentation
34+
If you make changes to your API routes or annotations, regenerate the Swagger docs with:
35+
36+
```
37+
swag init -g cmd/api/main.go -o docs
38+
```
39+
40+
- Requires the [swag CLI](https://github.com/swaggo/swag) (`go install github.com/swaggo/swag/cmd/swag@latest`)
41+
- This will update the `docs/` folder with the latest API documentation
42+
2543
## ⚡ Quick Start (Docker)
2644
1. Clone the repository
2745
2. Copy `.env` and update with your credentials

cmd/api/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,37 @@ import (
88
"github.com/joho/godotenv"
99
"github.com/spf13/viper"
1010

11+
_ "github.com/gjovanovicst/auth_api/docs" // docs is generated by Swag CLI
1112
"github.com/gjovanovicst/auth_api/internal/database"
1213
"github.com/gjovanovicst/auth_api/internal/email"
1314
"github.com/gjovanovicst/auth_api/internal/middleware"
1415
"github.com/gjovanovicst/auth_api/internal/redis"
1516
"github.com/gjovanovicst/auth_api/internal/social"
1617
"github.com/gjovanovicst/auth_api/internal/user"
18+
swaggerFiles "github.com/swaggo/files"
19+
ginSwagger "github.com/swaggo/gin-swagger"
1720
)
1821

22+
// @title Authentication and Authorization API
23+
// @version 1.0
24+
// @description This is a sample authentication and authorization API built with Go and Gin.
25+
// @termsOfService http://swagger.io/terms/
26+
27+
// @contact.name API Support
28+
// @contact.url http://www.swagger.io/support
29+
// @contact.email support@swagger.io
30+
31+
// @license.name Apache 2.0
32+
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
33+
34+
// @host localhost:8080
35+
// @BasePath /
36+
37+
// @securityDefinitions.apikey ApiKeyAuth
38+
// @in header
39+
// @name Authorization
40+
// @description Type "Bearer" + your JWT token
41+
1942
func main() {
2043
// Load environment variables from .env file
2144
if err := godotenv.Load(); err != nil {
@@ -84,6 +107,9 @@ func main() {
84107
// Add other protected routes here
85108
}
86109

110+
// Add Swagger UI endpoint
111+
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
112+
87113
// Start the server
88114
port := viper.GetString("PORT")
89115
log.Printf("Server starting on port %s", port)

0 commit comments

Comments
 (0)