(w http.ResponseWriter, r *http.Request)
| 396 | } |
| 397 | |
| 398 | func (rt *router) loginPOST(w http.ResponseWriter, r *http.Request) { |
| 399 | if err := r.ParseForm(); err != nil { |
| 400 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 401 | return |
| 402 | } |
| 403 | if r.FormValue("revoke-consents") == "on" { |
| 404 | res, err := rt.cl.OAuth2API.RevokeOAuth2ConsentSessions(r.Context()). |
| 405 | Subject(r.FormValue("username")). |
| 406 | All(true). |
| 407 | Execute() |
| 408 | if err != nil { |
| 409 | _, _ = fmt.Fprintln(rt.cmd.ErrOrStderr(), "Error revoking previous consents:", err) |
| 410 | } else { |
| 411 | _, _ = fmt.Fprintln(rt.cmd.ErrOrStderr(), "Revoked all previous consents") |
| 412 | } |
| 413 | defer res.Body.Close() //nolint:errcheck |
| 414 | } |
| 415 | switch r.FormValue("action") { |
| 416 | case "accept": |
| 417 | |
| 418 | req, res, err := rt.cl.OAuth2API.AcceptOAuth2LoginRequest(r.Context()). |
| 419 | LoginChallenge(r.FormValue("ls")). |
| 420 | AcceptOAuth2LoginRequest(openapi.AcceptOAuth2LoginRequest{ |
| 421 | Subject: r.FormValue("username"), |
| 422 | Remember: new(r.FormValue("remember") == "on"), |
| 423 | RememberFor: new(int64(3600)), |
| 424 | Context: map[string]string{ |
| 425 | "context from": "login step", |
| 426 | }, |
| 427 | }).Execute() |
| 428 | if err != nil { |
| 429 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 430 | return |
| 431 | } |
| 432 | defer res.Body.Close() //nolint:errcheck |
| 433 | http.Redirect(w, r, req.RedirectTo, http.StatusFound) |
| 434 | |
| 435 | case "deny": |
| 436 | req, res, err := rt.cl.OAuth2API.RejectOAuth2LoginRequest(r.Context()).LoginChallenge(r.FormValue("ls")).Execute() |
| 437 | if err != nil { |
| 438 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 439 | return |
| 440 | } |
| 441 | defer res.Body.Close() //nolint:errcheck |
| 442 | http.Redirect(w, r, req.RedirectTo, http.StatusFound) |
| 443 | |
| 444 | default: |
| 445 | http.Error(w, "Invalid action", http.StatusBadRequest) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | func (rt *router) consentGET(w http.ResponseWriter, r *http.Request) { |
| 450 | req, raw, err := rt.cl.OAuth2API.GetOAuth2ConsentRequest(r.Context()). |
nothing calls this directly
no test coverage detected