initial cognito

actual
This commit is contained in:
jay brown
2025-03-20 15:25:13 -07:00
parent 229f2b324d
commit dda6d7ee8c
301 changed files with 74255 additions and 3 deletions
+4 -3
View File
@@ -136,9 +136,10 @@ func (ckp *CognitoKeyProvider) GetPublicKey(kid string) (*rsa.PublicKey, error)
return key, nil
}
// Fetch JWKS from Cognito
//baseURL := "https://cognito-idp.amazonaws.com"
//jwksPath := fmt.Sprintf("/%s/%s/.well-known/jwks.json", ckp.Region, ckp.UserPoolID)
// Fetch JWKS from Cognito (old way)
// baseURL := "https://cognito-idp.amazonaws.com"
// jwksPath := fmt.Sprintf("/%s/%s/.well-known/jwks.json", ckp.Region, ckp.UserPoolID)
// https://cognito-idp.us-east-2.amazonaws.com/us-east-2_1y6po8rR8/.well-known/jwks.json
jwksURL := fmt.Sprintf("https://cognito-idp.%s.amazonaws.com/%s/.well-known/jwks.json", ckp.Region, ckp.UserPoolID)
if err := IsValidJWKSURL(jwksURL); err != nil {
+63
View File
@@ -5,6 +5,7 @@ import (
"errors"
"log/slog"
"net"
"os"
"strconv"
"time"
@@ -62,6 +63,65 @@ type Server struct {
cleanup func() error
}
// Return a middleware that logs all of the cookies and headers for a request
// if DEBUG=true is set in the environment.
func getDebugMiddleware(logger *slog.Logger) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// Only log if DEBUG=true
if os.Getenv("DEBUG") != "true" {
return next(c)
}
req := c.Request()
// Create structured debug info
debugInfo := map[string]interface{}{
"method": req.Method,
"url": map[string]interface{}{
"full": req.URL.String(),
"path": req.URL.Path,
"query": req.URL.RawQuery,
},
"headers": map[string][]string{},
"cookies": []map[string]string{},
}
// Collect headers - Fix type assertion error checking
headers, ok := debugInfo["headers"].(map[string][]string)
if !ok {
logger.Error("Failed to assert headers type")
} else {
for k, v := range req.Header {
headers[k] = v
}
}
// Collect cookies - Fix type assertion error checking
cookies, ok := debugInfo["cookies"].([]map[string]string)
if !ok {
logger.Error("Failed to assert cookies type")
} else {
for _, cookie := range req.Cookies() {
cookies = append(cookies, map[string]string{
"name": cookie.Name,
"value": cookie.Value,
})
}
// Update the slice in the map after appending
debugInfo["cookies"] = cookies
}
// Log with pretty formatting
logger.Info("DEBUG REQUEST",
"details", debugInfo,
)
return next(c)
}
}
}
func getSlogCustomEchoMiddleware(logger *slog.Logger) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
@@ -118,6 +178,9 @@ func New(ctx context.Context, cfg Config) (*Server, error) {
e.Use(middleware.Recover())
e.Use(middleware.CORS())
// Add debug middleware early to catch all requests
e.Use(getDebugMiddleware(cfg.GetLogger()))
cfg.SetRouter(e)
opnapi, err := cfg.RegisterHandlers()
if err != nil {