chore: make scim auth header case insensitive for 'bearer' (#15538)

Fixes status codes to return more than 500. The way we were using the
package, it always returned a status code 500
This commit is contained in:
Steven Masley
2024-11-15 12:30:11 -06:00
committed by GitHub
parent 4cb807670d
commit 16ade985ae
3 changed files with 91 additions and 22 deletions
+40 -1
View File
@@ -1,6 +1,11 @@
package scim
import "time"
import (
"encoding/json"
"time"
"github.com/imulab/go-scim/pkg/v2/spec"
)
type ServiceProviderConfig struct {
Schemas []string `json:"schemas"`
@@ -44,3 +49,37 @@ type AuthenticationScheme struct {
SpecURI string `json:"specUri"`
DocURI string `json:"documentationUri"`
}
// HTTPError wraps a *spec.Error for correct usage with
// 'handlerutil.WriteError'. This error type is cursed to be
// absolutely strange and specific to the SCIM library we use.
//
// The library expects *spec.Error to be returned on unwrap, and the
// internal error description to be returned by a json.Marshal of the
// top level error.
type HTTPError struct {
scim *spec.Error
internal error
}
func NewHTTPError(status int, eType string, err error) *HTTPError {
return &HTTPError{
scim: &spec.Error{
Status: status,
Type: eType,
},
internal: err,
}
}
func (e HTTPError) Error() string {
return e.internal.Error()
}
func (e HTTPError) MarshalJSON() ([]byte, error) {
return json.Marshal(e.internal)
}
func (e HTTPError) Unwrap() error {
return e.scim
}