client

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2022 License: Apache-2.0 Imports: 12 Imported by: 13

Documentation

Index

Constants

View Source
const (
	UserContextKey  key = iota
	ChainContextKey key = iota
)

Variables

View Source
var (
	DefaultSubjectHeader    = http.CanonicalHeaderKey("X-Auth-User")
	DefaultIssuerHeader     = http.CanonicalHeaderKey("X-Auth-Source")
	DefaultVerifyHeader     = http.CanonicalHeaderKey("X-Auth-Verify")
	DefaultVerifyHashHeader = http.CanonicalHeaderKey("X-Auth-Hash-Verify")
	DefaultClaimPrefix      = "X-Auth-"
)
View Source
var (
	ErrMissingUser = errors.New("sub or iss has 0 segments")
)

Functions

func CopyTo added in v0.1.6

func CopyTo(src, dst *http.Request)

CopyTo copies user information from a source http.Request to a destination one this function is useful when proxying requests from one service to another and retaining user information

func PersistUserCtx added in v0.1.9

func PersistUserCtx(ctx context.Context, chain *ChainClaim, user *UserClaim) context.Context

PersistUserCtx injects the user/chain claims into a given context.Context.

`chain` or `user` can be nil if only one is required. Nil parameters will not overwrite existing values.

Types

type BaseVerifier

type BaseVerifier interface {
	IsValid(ctx context.Context, msg, sig, sigHash string) bool
}

type ChainClaim

type ChainClaim struct {
	Subjects  []string          `json:"subjects"`
	Issuers   []string          `json:"issuers"`
	Token     string            `json:"token"`
	TokenHash string            `json:"token_hash"` // hash of key used to sign authenticity token
	RawClaim  string            `json:"raw_claim"`
	Claims    map[string]string `json:"claims"`
}

func GetClaim

func GetClaim(r *http.Request) (*ChainClaim, error)

GetClaim creates a UserClaim from a given http.Request

func GetContextChain added in v0.1.9

func GetContextChain(ctx context.Context) (*ChainClaim, bool)

GetContextChain returns the user-chain saved into the given context.Context.

May return nil if not processed by a Client.

func GetRequestingChain added in v0.1.9

func GetRequestingChain(r *http.Request) (*ChainClaim, bool)

GetRequestingChain returns the user-chain saved into the given http.Request.

May return nil if not processed by a Client.

func (*ChainClaim) GetOriginalClaim

func (uc *ChainClaim) GetOriginalClaim(ctx context.Context) (*UserClaim, error)

GetOriginalClaim returns the 1st user within a chain as a new UserClaim

type Client added in v0.1.6

type Client struct {
	// contains filtered or unexported fields
}

Client provides simple utilities for extracting a user from an incoming request

func NewClient added in v0.1.6

func NewClient(v BaseVerifier) *Client

NewClient creates a new instance of Client

func (*Client) WithOptionalUser added in v0.3.0

func (c *Client) WithOptionalUser(h http.Handler) http.Handler

WithOptionalUser provides a http.Handler for injecting user information into the request context.Context if it is given.

func (*Client) WithOptionalUserFunc added in v0.3.0

func (c *Client) WithOptionalUserFunc(f http.HandlerFunc) http.HandlerFunc

WithOptionalUserFunc provides a http handler function for injecting user information into the request context.Context if it is given.

func (*Client) WithUser added in v0.1.6

func (c *Client) WithUser(h http.Handler) http.Handler

WithUser provides a http.Handler for injecting user information into the request Context

func (*Client) WithUserFunc added in v0.1.6

func (c *Client) WithUserFunc(f http.HandlerFunc) http.HandlerFunc

WithUserFunc provides a http handler function for injecting user information into the request Context

type UserClaim

type UserClaim struct {
	Sub       string            `json:"sub"`        // unique id or DN
	Iss       string            `json:"iss"`        // id of issuer (e.g. OIDC url) or DN of CA
	Token     string            `json:"token"`      // authenticity token
	TokenHash string            `json:"token_hash"` // hash of key used to sign authenticity token
	Claims    map[string]string `json:"claims"`
}

func GetContextUser added in v0.1.6

func GetContextUser(ctx context.Context) (*UserClaim, bool)

GetContextUser returns the user saved into the given context.Context.

May return nil if not processed by a Client.

func GetRequestingUser added in v0.1.6

func GetRequestingUser(r *http.Request) (*UserClaim, bool)

GetRequestingUser returns the user saved into the given http.Request.

May return nil if not processed by a Client.

func (*UserClaim) AsUsername

func (uc *UserClaim) AsUsername() string

type Verifier

type Verifier struct {
	BaseVerifier
	// contains filtered or unexported fields
}

func NewVerifier

func NewVerifier(ctx context.Context, url string) (*Verifier, error)

NewVerifier creates a Verifier and attempts to load the CAP10 public key

func (*Verifier) IsValid

func (v *Verifier) IsValid(ctx context.Context, msg, sig, sigHash string) bool

IsValid checks whether sig is a signed version of msg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL