- Renamed existing hello world endpoints to public and added a new protected endpoint with OAuth guard. - Updated test cases to reflect the new endpoint structure and added tests for protected endpoint access with and without valid tokens. - Enhanced response handling for public and protected endpoints to ensure consistent output and proper status codes.
22 lines
381 B
Go
22 lines
381 B
Go
package oauth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Guard is the OAuth guard middleware
|
|
func (s *Service) Guard(c *gin.Context) {
|
|
// Get the token from the request
|
|
token := c.GetHeader("Authorization")
|
|
|
|
// Validate the token
|
|
if token == "" {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
// Validate the token
|
|
}
|