package queryapi import ( "net/http" "net/url" "github.com/labstack/echo/v4" ) // All of the auth related handlers that are called from the // generated swagger code. func (s *Controllers) Login(ctx echo.Context) error { // Redirect to Cognito login page // This is a placeholder implementation - you'll need to implement the actual Cognito redirect logic loginURL := "https://doczy.auth.us-east-1.amazoncognito.com/oauth2/authorize" return ctx.Redirect(http.StatusFound, loginURL) } func (s *Controllers) LoginCallback(ctx echo.Context, params LoginCallbackParams) error { return ctx.JSON(http.StatusOK, map[string]string{"message": "Login callback is a no op since its handled by the middleware."}) } // Logout is called by the swagger generated code for the logout endpoint. // It redirects to the Cognito logout endpoint to properly terminate the session, // which then redirects back to the home page. func (s *Controllers) Logout(ctx echo.Context) error { // the middleware will have already removed the auth cookie // Construct the Cognito logout URL with proper parameters logoutURL := s.authConfig.GetAuthLogoutURL() clientID := s.authConfig.GetAuthClientID() // The logout_uri should redirect back to our home page // Use the same base URL that was used for redirect URI setup baseURL := ctx.Scheme() + "://" + ctx.Request().Host logoutRedirectURI := baseURL + s.authConfig.GetAuthHomePath() // Build the full Cognito logout URL with query parameters parsedURL, err := url.Parse(logoutURL) if err != nil { s.authConfig.GetAuthLogger().Error("Failed to parse logout URL", "error", err) // Fallback to simple redirect to home return ctx.Redirect(http.StatusFound, s.authConfig.GetAuthHomePath()) } query := parsedURL.Query() query.Set("client_id", clientID) query.Set("logout_uri", logoutRedirectURI) parsedURL.RawQuery = query.Encode() cognitoLogoutURL := parsedURL.String() s.authConfig.GetAuthLogger().Debug("Redirecting to Cognito logout", "logout_url", cognitoLogoutURL, "client_id", clientID, "logout_uri", logoutRedirectURI) // Redirect to Cognito logout endpoint return ctx.Redirect(http.StatusFound, cognitoLogoutURL) } func (s *Controllers) GetHomePage(ctx echo.Context) error { return HomeHandler(ctx) }