Documentation
¶
Overview ¶
Package identity extracts the callers contextual identity information from the HTTP/TLS requests and exposes them for access via the generalized go context model.
Index ¶
- Constants
- func AddToContext(ctx context.Context, rq *RequestContext) context.Context
- func BasicAuthFromRequest(r *http.Request) (id string, secret string, err error)
- func ClientIPFromGRPC(ctx context.Context) string
- func ClientIPFromRequest(r *http.Request) string
- func NewAuthUnaryInterceptor(identityMapper ProviderFromContext) grpc.UnaryServerInterceptor
- func NewContextHandler(delegate http.Handler, identityMapper ProviderFromRequest) http.Handler
- func NewStreamServerInterceptor(identityMapper ProviderFromContext) grpc.StreamServerInterceptor
- func WithTestIdentity(r *http.Request, identity Identity) *http.Request
- type Context
- type Identity
- type ProviderFromContext
- type ProviderFromRequest
- type RequestContext
Constants ¶
const GuestRoleName = "guest"
GuestRoleName is default role name for guest
Variables ¶
This section is empty.
Functions ¶
func AddToContext ¶
func AddToContext(ctx context.Context, rq *RequestContext) context.Context
AddToContext returns a new golang context that adds `rq` as the request context.
func BasicAuthFromRequest ¶
BasicAuthFromRequest returns client id from Basic authentication, which is in base64encode(id:secret) form
func ClientIPFromGRPC ¶ added in v0.36.373
func ClientIPFromRequest ¶
ClientIPFromRequest return client's real public IP address from http request headers.
func NewAuthUnaryInterceptor ¶
func NewAuthUnaryInterceptor(identityMapper ProviderFromContext) grpc.UnaryServerInterceptor
NewAuthUnaryInterceptor returns grpc.UnaryServerInterceptor that identity to the context
func NewContextHandler ¶
func NewContextHandler(delegate http.Handler, identityMapper ProviderFromRequest) http.Handler
NewContextHandler returns a handler that will extact the role & contextID from the request and stash them away in the request context for later handlers to use. Also adds header to indicate which host is currently servicing the request
func NewStreamServerInterceptor ¶ added in v0.33.319
func NewStreamServerInterceptor(identityMapper ProviderFromContext) grpc.StreamServerInterceptor
Types ¶
type Context ¶
type Context interface {
Identity() Identity
ClientIP() string
// Target of the request, e.g. HTTP path or gRPC method
Target() string
UserAgent() string
}
Context represents user contextual information about a request being processed by the server, it includes identity, CorrelationID [for cross system request correlation].
type Identity ¶
type Identity interface {
// String returns the identity as a single string value
// in the format of role/subject
String() string
Role() string
Subject() string
Tenant() string
Claims() jwt.MapClaims
AccessToken() string
TokenType() string
}
Identity contains information about the identity of an API caller
func GuestIdentityForContext ¶
GuestIdentityForContext always returns "guest" for the role
func GuestIdentityMapper ¶
GuestIdentityMapper always returns "guest" for the role
type ProviderFromContext ¶
ProviderFromContext returns Identity from supplied context
type ProviderFromRequest ¶
ProviderFromRequest returns Identity from supplied HTTP request
type RequestContext ¶
type RequestContext struct {
// contains filtered or unexported fields
}
RequestContext represents user contextual information about a request being processed by the server, it includes identity, CorrelationID [for cross system request correlation].
func FromContext ¶
func FromContext(ctx context.Context) *RequestContext
FromContext extracts the RequestContext stored inside a go context. Returns null if no such value exists.
func FromRequest ¶
func FromRequest(r *http.Request) *RequestContext
FromRequest returns the full context associated with this http request.
func NewRequestContext ¶
func NewRequestContext(id Identity, target string) *RequestContext
NewRequestContext creates a request context with a specific identity.
func (*RequestContext) ClientIP ¶
func (c *RequestContext) ClientIP() string
ClientIP returns request's IP
func (*RequestContext) Identity ¶
func (c *RequestContext) Identity() Identity
Identity returns request's identity
func (*RequestContext) Target ¶ added in v0.36.373
func (c *RequestContext) Target() string
Target returns request's target
func (*RequestContext) UserAgent ¶ added in v0.36.373
func (c *RequestContext) UserAgent() string
UserAgent returns request's user agent