Merged in feature/permit-integration-1 (pull request #172)
Permit integration - part 1 * WIP permit integration * slim down build * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-integration-1 * omit swagger from auth * clean build * comment * part 1 completed this is the initial permitio parts and tests without integration. Also testing.md since we have a new test target `task test:permitio` * feature flag for no jwt validation * permit integration * fix ci unit tests * ci fix * build fix * fix home handler * fix redirect * test fix * update docs for auth
This commit is contained in:
@@ -2,6 +2,7 @@ package queryapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@@ -21,11 +22,42 @@ func (s *Controllers) LoginCallback(ctx echo.Context, params LoginCallbackParams
|
||||
}
|
||||
|
||||
// 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
|
||||
// so we can just redirect to the home page after logging out.
|
||||
return ctx.Redirect(http.StatusFound, "/home")
|
||||
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user