diff --git a/api/Authenticator.api b/api/Authenticator.api index d106cf9..1b2d2b7 100644 --- a/api/Authenticator.api +++ b/api/Authenticator.api @@ -33,11 +33,7 @@ type ( OpenidSigned string `form:"openid.signed"` OpenidSig string `form:"openid.sig"` } - SteamLoginCallbackResp { - Success bool `json:"success"` - SteamId string `json:"steamId,omitempty"` - Message string `json:"message,omitempty"` - } +// No response needed - endpoint will redirect to frontend ) @server ( @@ -60,9 +56,9 @@ service Authenticator { @doc ( summary: "Steam login callback" - description: "Handles the callback from Steam after user authentication" + description: "Validates Steam authentication and redirects to frontend with status" ) @handler steamLoginCallbackHandler - get /steam/callback (SteamLoginCallbackReq) returns (SteamLoginCallbackResp) + get /steam/callback (SteamLoginCallbackReq) } diff --git a/src/etc/authenticator.yaml b/src/etc/authenticator.yaml index ce56ceb..d89e841 100644 --- a/src/etc/authenticator.yaml +++ b/src/etc/authenticator.yaml @@ -4,6 +4,7 @@ Port: 8888 Steam: CallbackURL: https://www.cialloo.com/api/authenticator/steam/callback + FrontendCallbackURL: https://www.cialloo.com/auth/callback Redis: Host: redis.production.svc.cluster.local:6379 diff --git a/src/internal/config/config.go b/src/internal/config/config.go index d4b165f..2a4b535 100644 --- a/src/internal/config/config.go +++ b/src/internal/config/config.go @@ -12,5 +12,6 @@ type Config struct { } type SteamConfig struct { - CallbackURL string + CallbackURL string + FrontendCallbackURL string } diff --git a/src/internal/handler/steamlogincallbackhandler.go b/src/internal/handler/steamlogincallbackhandler.go index 8f4cd98..ccb296c 100644 --- a/src/internal/handler/steamlogincallbackhandler.go +++ b/src/internal/handler/steamlogincallbackhandler.go @@ -3,10 +3,11 @@ package handler import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "src/internal/logic" "src/internal/svc" "src/internal/types" + + "github.com/zeromicro/go-zero/rest/httpx" ) // Steam login callback @@ -19,11 +20,10 @@ func steamLoginCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } l := logic.NewSteamLoginCallbackLogic(r.Context(), svcCtx) - resp, err := l.SteamLoginCallback(&req) + err := l.SteamLoginCallback(&req, w, r) if err != nil { httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) } + // No response needed - redirect is handled in logic } } diff --git a/src/internal/logic/steamlogincallbacklogic.go b/src/internal/logic/steamlogincallbacklogic.go index 976c4f0..2952eda 100644 --- a/src/internal/logic/steamlogincallbacklogic.go +++ b/src/internal/logic/steamlogincallbacklogic.go @@ -3,6 +3,8 @@ package logic import ( "context" "fmt" + "net/http" + "net/url" "src/internal/svc" "src/internal/types" @@ -26,9 +28,12 @@ func NewSteamLoginCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) } } -func (l *SteamLoginCallbackLogic) SteamLoginCallback(req *types.SteamLoginCallbackReq) (resp *types.SteamLoginCallbackResp, err error) { - // Convert request to map for Steam validation - paramsMap := map[string]string{ +func (l *SteamLoginCallbackLogic) SteamLoginCallback(req *types.SteamLoginCallbackReq, w http.ResponseWriter, r *http.Request) error { + // Get the frontend callback URL from config + frontendCallbackURL := l.svcCtx.Config.Steam.FrontendCallbackURL + + // Convert the request to a map for validation + openidParams := map[string]string{ "openid.mode": req.OpenidMode, "openid.ns": req.OpenidNs, "openid.op_endpoint": req.OpenidOpEndpoint, @@ -41,29 +46,30 @@ func (l *SteamLoginCallbackLogic) SteamLoginCallback(req *types.SteamLoginCallba "openid.sig": req.OpenidSig, } - // Validate the response with Steam - steamID, isValid, err := steamauth.ValidateResponse(paramsMap) + // Validate the Steam OpenID response + steamID, isValid, err := steamauth.ValidateResponse(openidParams) if err != nil { - l.Logger.Errorf("Steam validation error: %v", err) - return &types.SteamLoginCallbackResp{ - Success: false, - Message: fmt.Sprintf("Validation error: %v", err), - }, nil + l.Logger.Errorf("Failed to validate Steam OpenID response: %v", err) + // Redirect to frontend with error status + redirectURL := fmt.Sprintf("%s?status=error&message=%s", frontendCallbackURL, url.QueryEscape("Failed to validate Steam response")) + http.Redirect(w, r, redirectURL, http.StatusFound) + return nil } if !isValid { - l.Logger.Info("Steam validation failed: invalid credentials") - return &types.SteamLoginCallbackResp{ - Success: false, - Message: "Invalid Steam credentials", - }, nil + l.Logger.Infof("Invalid Steam OpenID response") + // Redirect to frontend with failure status + redirectURL := fmt.Sprintf("%s?status=failed&message=%s", frontendCallbackURL, url.QueryEscape("Steam authentication failed")) + http.Redirect(w, r, redirectURL, http.StatusFound) + return nil } + // Successful validation l.Logger.Infof("Steam login successful for Steam ID: %s", steamID) - return &types.SteamLoginCallbackResp{ - Success: true, - SteamId: steamID, - Message: "Login successful", - }, nil + // Redirect to frontend with success status and Steam ID + redirectURL := fmt.Sprintf("%s?status=success&steamId=%s", frontendCallbackURL, steamID) + http.Redirect(w, r, redirectURL, http.StatusFound) + + return nil } diff --git a/src/internal/types/types.go b/src/internal/types/types.go index 3ad1530..59e6139 100644 --- a/src/internal/types/types.go +++ b/src/internal/types/types.go @@ -23,11 +23,5 @@ type SteamLoginCallbackReq struct { OpenidSig string `form:"openid.sig"` } -type SteamLoginCallbackResp struct { - Success bool `json:"success"` - SteamId string `json:"steamId,omitempty"` - Message string `json:"message,omitempty"` -} - type SteamLoginInitReq struct { }