Documentation ¶
Overview ¶
Package transport - HTTP request and response methods
Index ¶
- Variables
- func AddClientHeader(ctx context.Context, header http.Header) context.Context
- func AuthorizeOIDC(authorizer Authorizer, allowUnauthorized bool) httptransport.ServerOption
- func GetHeaders(ctx context.Context) http.Header
- func GetParams(ctx context.Context) url.Values
- func GetURLParams(ctx context.Context) url.Values
- func NewHTTPHandler(endpoints HTTPEndpoints, logger *logger.Logger, duration metrics.Histogram) *mux.Router
- func ServerOptions(opt ...httptransport.ServerOption) []httptransport.ServerOption
- func SetCors(domain string) httptransport.ServerOption
- func SetJWTAuthHeader(ctx context.Context, jwtToken string) context.Context
- type Authorizer
- type ClientEndpoints
- type EmptyAuthorizer
- type ErrorStatus
- type HTTPEndpoint
- type HTTPEndpoints
- type LocalAuthorizer
- type OIDCAuthorizer
- type UserClaims
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMethodNotAllowed when HTTP request method is not handled ErrMethodNotAllowed = errors.New("method not allowed") // ErrInvalidRequest when HTTP request is invalid ErrInvalidRequest = errors.New("invalid request") // ErrInvalidJSON when the request is invalid json ErrInvalidJSON = errors.New("invalid json") ErrUnauthorized = errors.New("unauthorized") // ErrHTTPClientError when HTTP request status is not 200 ErrHTTPClientError = errors.New("request error") )
Functions ¶
func AddClientHeader ¶
AddClientHeader adds header to the http client context
func AuthorizeOIDC ¶
func AuthorizeOIDC(authorizer Authorizer, allowUnauthorized bool) httptransport.ServerOption
AuthorizeOIDC checks the Authorization header OIDC token, verifies it and gets the user info
func GetHeaders ¶
GetHeaders returns the HTTP Request headers
func GetURLParams ¶
GetURLParams returns URL params of the request path
func NewHTTPHandler ¶
func NewHTTPHandler(endpoints HTTPEndpoints, logger *logger.Logger, duration metrics.Histogram) *mux.Router
NewHTTPHandler returns an HTTP handler that makes a set of endpoints
func ServerOptions ¶
func ServerOptions(opt ...httptransport.ServerOption) []httptransport.ServerOption
ServerOptions returns an array of httptransport.ServerOption
func SetCors ¶
func SetCors(domain string) httptransport.ServerOption
SetCors sets CORS HTTP response headers for specific domains
Types ¶
type Authorizer ¶
type Authorizer interface {
Authorize(header http.Header) (*UserClaims, error)
}
Authorizer interface for implementing API Authorization
func NewOIDCAuthorizer ¶
func NewOIDCAuthorizer(clientID, oidcProvider string, claims ...string) (Authorizer, error)
NewOIDCAuthorizer creates a new instance of OIDCAuthorizer
type ClientEndpoints ¶
ClientEndpoints is a map of all exported client endpoints
func NewHTTPClient ¶
func NewHTTPClient(instance string, endpoints HTTPEndpoints, logger *logger.Logger) (ClientEndpoints, error)
NewHTTPClient returns an HTTP handler that makes a set of endpoints
type EmptyAuthorizer ¶
type EmptyAuthorizer struct{}
EmptyAuthorizer implements empty Authorizer
func (*EmptyAuthorizer) Authorize ¶
func (a *EmptyAuthorizer) Authorize(header http.Header) (*UserClaims, error)
Authorize checks the IDToken
type ErrorStatus ¶
ErrorStatus is a map of errors to http response status codes
func (ErrorStatus) ResponseStatus ¶
func (e ErrorStatus) ResponseStatus(err error) (statusCode int, statusText string)
ResponseStatus returns the status code and status text based on the error type
type HTTPEndpoint ¶
type HTTPEndpoint struct { Path string Method string Endpoint endpoint.Endpoint NewRequest func() interface{} NewResponse func() interface{} ErrStatus ErrorStatus Options []httptransport.ServerOption }
HTTPEndpoint defines a single endpoint
type HTTPEndpoints ¶
type HTTPEndpoints map[string]HTTPEndpoint
HTTPEndpoints is a map of endpoints Key is the name of the endpoint
type LocalAuthorizer ¶
type LocalAuthorizer struct{}
LocalAuthorizer implements JWT Authorizer without verifying the signature For testing purposes only
func (*LocalAuthorizer) Authorize ¶
func (a *LocalAuthorizer) Authorize(header http.Header) (*UserClaims, error)
Authorize checks the IDToken
type OIDCAuthorizer ¶
type OIDCAuthorizer struct { ClientID string RequestUserInfo bool ClaimsSupported []string Provider *oidc.Provider }
OIDCAuthorizer implements OIDC/OAuth2 JWT token authorization token authorizer
func (*OIDCAuthorizer) Authorize ¶
func (a *OIDCAuthorizer) Authorize(header http.Header) (*UserClaims, error)
Authorize checks the IDToken
type UserClaims ¶
type UserClaims map[string]interface{}
UserClaims holds information about the claims from the UserInfo endpoint
func GetUserInfo ¶
func GetUserInfo(ctx context.Context) *UserClaims
GetUserInfo returns the authorized user info
func (*UserClaims) GetString ¶
func (uc *UserClaims) GetString(key string) string
GetString returns a value of a key if exists