(management handlers moved to internal/api/handlers/management) AuthMiddleware returns a Gin middleware handler that authenticates requests using the configured authentication providers. When no providers are available, it allows all requests (legacy behaviour).
(manager *sdkaccess.Manager)
| 1773 | // using the configured authentication providers. When no providers are available, |
| 1774 | // it allows all requests (legacy behaviour). |
| 1775 | func AuthMiddleware(manager *sdkaccess.Manager) gin.HandlerFunc { |
| 1776 | return func(c *gin.Context) { |
| 1777 | if manager == nil { |
| 1778 | c.Next() |
| 1779 | return |
| 1780 | } |
| 1781 | |
| 1782 | result, err := manager.Authenticate(c.Request.Context(), c.Request) |
| 1783 | if err == nil { |
| 1784 | if result != nil { |
| 1785 | c.Set("userApiKey", result.Principal) |
| 1786 | c.Set("accessProvider", result.Provider) |
| 1787 | if len(result.Metadata) > 0 { |
| 1788 | c.Set("accessMetadata", result.Metadata) |
| 1789 | } |
| 1790 | } |
| 1791 | c.Next() |
| 1792 | return |
| 1793 | } |
| 1794 | |
| 1795 | statusCode := err.HTTPStatusCode() |
| 1796 | if statusCode >= http.StatusInternalServerError { |
| 1797 | log.Errorf("authentication middleware error: %v", err) |
| 1798 | } |
| 1799 | c.AbortWithStatusJSON(statusCode, gin.H{"error": err.Message}) |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | func configuredSignatureCacheEnabled(cfg *config.Config) bool { |
| 1804 | if cfg != nil && cfg.AntigravitySignatureCacheEnabled != nil { |
no test coverage detected