// SignOut signs the user out by trying to revoke the user's remote identity session along with
// the associated local session state. Handles both GET and POST.
SignOut signs the user out by trying to revoke the user's remote identity session along with
the associated local session state. Handles both GET and POST.
// SignOut signs the user out by trying to revoke the user ' s remote identity session along with // the associated local session state . Handles both GET and POST .
func (a *Authenticate) SignOut(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		httputil.ErrorResponse(w, r, err.Error(), http.StatusInternalServerError)
		return
	}
	redirectURI := r.Form.Get("redirect_uri")
	session, err := a.sessionStore.LoadSession(r)
	if err != nil {
		log.Error().Err(err).Msg("authenticate: signout failed to load session")
		httputil.ErrorResponse(w, r, "No session found to log out", http.StatusBadRequest)
		return
	}
	if r.Method == http.MethodGet {
		signature := r.Form.Get("sig")
		timestamp := r.Form.Get("ts")
		destinationURL, err := url.Parse(redirectURI)
		if err != nil {
			log.Error().Err(err).Msg("authenticate: malformed destination url")
			httputil.ErrorResponse(w, r, "Malformed destination URL", http.StatusBadRequest)
			return
		}
		t := struct {
			Redirect    string
			Signature   string
			Timestamp   string
			Destination string
			Email       string
			Version     string
		}{
			Redirect:    redirectURI,
			Signature:   signature,
			Timestamp:   timestamp,
			Destination: destinationURL.Host,
			Email:       session.Email,
			Version:     version.FullVersion(),
		}
		a.templates.ExecuteTemplate(w, "sign_out.html", t)
		w.WriteHeader(http.StatusOK)
		return
	}
	a.sessionStore.ClearSession(w, r)
	err = a.provider.Revoke(session.AccessToken)
	if err != nil {
		log.Error().Err(err).Msg("authenticate: failed to revoke user session")
		httputil.ErrorResponse(w, r, fmt.Sprintf("could not revoke session: %s ", err.Error()), http.StatusBadRequest)
		return
	}
	http.Redirect(w, r, redirectURI, http.StatusFound)
}
func ( a * Authenticate ) SignOut ( w http . ResponseWriter , r * http . Request ) { err := r . ParseForm ( ) if err != nil { httputil . ErrorResponse ( w , r , err . Error ( ) , http . StatusInternalServerError ) return } redirectURI := r . Form . Get ( " " ) session , err := a . sessionStore . LoadSession ( r ) if err != nil { log . Error ( ) . Err ( err ) . Msg ( " " ) httputil . ErrorResponse ( w , r , " " , http . StatusBadRequest ) return } if r . Method == http . MethodGet { signature := r . Form . Get ( " " ) timestamp := r . Form . Get ( " " ) destinationURL , err := url . Parse ( redirectURI ) if err != nil { log . Error ( ) . Err ( err ) . Msg ( " " ) httputil . ErrorResponse ( w , r , " " , http . StatusBadRequest ) return } t := struct { Redirect string Signature string Timestamp string Destination string Email string Version string } { Redirect : redirectURI , Signature : signature , Timestamp : timestamp , Destination : destinationURL . Host , Email : session . Email , Version : version . FullVersion ( ) , } a . templates . ExecuteTemplate ( w , " " , t ) w . WriteHeader ( http . StatusOK ) return } a . sessionStore . ClearSession ( w , r ) err = a . provider . Revoke ( session . AccessToken ) if err != nil { log . Error ( ) . Err ( err ) . Msg ( " " ) httputil . ErrorResponse ( w , r , fmt . Sprintf ( " " , err . Error ( ) ) , http . StatusBadRequest ) return } http . Redirect ( w , r , redirectURI , http . StatusFound ) }
SignOut signs the user out by trying to revoke the user's remote identity session along with
the associated local session state.
SignOut signs the user out by trying to revoke the user ' s remote identity session along with the associated local session state .
// pretty safe to say that no matter what heppanes here, we want to revoke the local session