Documentation
¶
Index ¶
- Variables
- func ConcatenateJSON(first, second []byte) ([]byte, error)
- func FormRequest(ctx context.Context, endpoint string, request any, encoder Encoder, authFn any) (*http.Request, error)
- func HttpRequest(client *http.Client, req *http.Request, response any) error
- func MarshalJSON(w http.ResponseWriter, i any)
- func MarshalJSONWithStatus(w http.ResponseWriter, i any, status int)
- func StartServer(ctx context.Context, port string)
- func URLEncodeParams(resp any, encoder Encoder) (url.Values, error)
- type CookieHandler
- func (c *CookieHandler) CheckCookie(r *http.Request, name string) (string, error)
- func (c *CookieHandler) CheckQueryCookie(r *http.Request, name string) (string, error)
- func (c *CookieHandler) CreateCookie(name, value string) (*http.Cookie, error)
- func (c *CookieHandler) CreateSecureCookie(r *http.Request, name, value string) (*http.Cookie, error)
- func (c *CookieHandler) DeleteCookie(w http.ResponseWriter, name string)
- func (c *CookieHandler) IsRequestAware() bool
- func (c *CookieHandler) SetCookie(w http.ResponseWriter, name, value string) error
- func (c *CookieHandler) SetRequestAwareCookie(r *http.Request, w http.ResponseWriter, name string, value string) error
- type CookieHandlerOpt
- type Decoder
- type Encoder
- type FormAuthorization
- type RequestAuthorization
Constants ¶
This section is empty.
Variables ¶
var DefaultHTTPClient = &http.Client{ Timeout: 30 * time.Second, }
Functions ¶
func ConcatenateJSON ¶
func FormRequest ¶
func MarshalJSON ¶
func MarshalJSON(w http.ResponseWriter, i any)
func MarshalJSONWithStatus ¶
func MarshalJSONWithStatus(w http.ResponseWriter, i any, status int)
func StartServer ¶
Types ¶
type CookieHandler ¶
type CookieHandler struct {
// contains filtered or unexported fields
}
func NewCookieHandler ¶
func NewCookieHandler(hashKey, encryptKey []byte, opts ...CookieHandlerOpt) *CookieHandler
func NewRequestAwareCookieHandler ¶
func NewRequestAwareCookieHandler(secureCookieFunc func(r *http.Request) (*securecookie.SecureCookie, error), opts ...CookieHandlerOpt) *CookieHandler
func (*CookieHandler) CheckCookie ¶
func (*CookieHandler) CheckQueryCookie ¶
func (*CookieHandler) CreateCookie ¶
func (c *CookieHandler) CreateCookie(name, value string) (*http.Cookie, error)
func (*CookieHandler) CreateSecureCookie ¶
func (*CookieHandler) DeleteCookie ¶
func (c *CookieHandler) DeleteCookie(w http.ResponseWriter, name string)
func (*CookieHandler) IsRequestAware ¶
func (c *CookieHandler) IsRequestAware() bool
func (*CookieHandler) SetCookie ¶
func (c *CookieHandler) SetCookie(w http.ResponseWriter, name, value string) error
func (*CookieHandler) SetRequestAwareCookie ¶
func (c *CookieHandler) SetRequestAwareCookie(r *http.Request, w http.ResponseWriter, name string, value string) error
type CookieHandlerOpt ¶
type CookieHandlerOpt func(*CookieHandler)
func WithDomain ¶
func WithDomain(domain string) CookieHandlerOpt
func WithMaxAge ¶
func WithMaxAge(maxAge int) CookieHandlerOpt
func WithPath ¶
func WithPath(path string) CookieHandlerOpt
func WithSameSite ¶
func WithSameSite(sameSite http.SameSite) CookieHandlerOpt
func WithUnsecure ¶
func WithUnsecure() CookieHandlerOpt
type FormAuthorization ¶
type RequestAuthorization ¶
func AuthorizeBasic ¶
func AuthorizeBasic(user, password string) RequestAuthorization
AuthorizeBasic returns a RequestAuthorization that sets HTTP Basic authentication on the request using the provided user and password.
Per RFC 6749 §2.3.1, OAuth 2.0 clients SHOULD encode client_id and client_secret via application/x-www-form-urlencoded before applying Basic auth:
base64(formUrlEncode(client_id) + ":" + formUrlEncode(client_secret))
This is correct per spec, and some authorization servers (e.g. Keycloak) strictly URL-decode credentials on receipt. However, many other servers (Auth0, Okta, Google, GitHub) accept raw credentials directly, and double-encoding secrets containing '@' or ':' causes authentication failures with those providers.
We pass raw values to SetBasicAuth for broader real-world compatibility. Downstream callers that need strict RFC compliance should use their own RequestAuthorization.
To restore RFC-compliant behaviour, replace the body with:
req.SetBasicAuth(url.QueryEscape(user), url.QueryEscape(password))