github.com/crewjam/saml@v0.4.14/samlsp/error.go (about)

     1  package samlsp
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  
     7  	"github.com/crewjam/saml"
     8  )
     9  
    10  // ErrorFunction is a callback that is invoked to return an error to the
    11  // web user.
    12  type ErrorFunction func(w http.ResponseWriter, r *http.Request, err error)
    13  
    14  // DefaultOnError is the default ErrorFunction implementation. It prints
    15  // an message via the standard log package and returns a simple text
    16  // "Forbidden" message to the user.
    17  func DefaultOnError(w http.ResponseWriter, _ *http.Request, err error) {
    18  	if parseErr, ok := err.(*saml.InvalidResponseError); ok {
    19  		log.Printf("WARNING: received invalid saml response: %s (now: %s) %s",
    20  			parseErr.Response, parseErr.Now, parseErr.PrivateErr)
    21  	} else {
    22  		log.Printf("ERROR: %s", err)
    23  	}
    24  	http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
    25  }