Documentation ¶
Overview ¶
Package ctxtg provides Context which should be passed between all our services. Also ctxtg provides Token Signer, Parser and test helper implementations in ctxtgtest.
Index ¶
- Constants
- Variables
- func DataFromContext(ctx context.Context) map[string]interface{}
- func ValueFromData(ctx context.Context, key string) interface{}
- func WithDataValue(parent context.Context, key string, value interface{}) context.Context
- type Claims
- type ClaimsFunc
- type Context
- type CtxClaimsFunc
- type RSATokenParser
- type RSATokenSigner
- type Token
- type TokenParser
- type TokenSigner
- type UserID
Constants ¶
const ( TokenKey key TracingIDKey DataKey )
Values to access ctxtg values inside context.Context
Variables ¶
var ( ErrInvalidToken = jsonrpc2.NewError(1, "INVALID_TOKEN") ErrTokenExpired = jsonrpc2.NewError(2, "TOKEN_EXPIRED") )
Global errors for all projects
Functions ¶
func DataFromContext ¶
DataFromContext returns map from Data key from ctx or nil
func ValueFromData ¶
ValueFromData returns value from Data map inside ctx or nil
Types ¶
type ClaimsFunc ¶
ClaimsFunc is function in which claims will be passed if JWT Token is fine
type Context ¶
Context for microservices communication
func FromContext ¶
FromContext convert context.Context to Context correctly extracting required fields
type CtxClaimsFunc ¶
CtxClaimsFunc is function in which claims and converted context.Context will be passed if JWT Token is fine
type RSATokenParser ¶
type RSATokenParser struct {
// contains filtered or unexported fields
}
RSATokenParser for parsing JWT token Implements TokenParser
func NewRSATokenParser ¶
func NewRSATokenParser(publicKey []byte) (*RSATokenParser, error)
NewRSATokenParser parse publicKey and return correct instance or error
func (*RSATokenParser) Parse ¶
func (p *RSATokenParser) Parse(t Token) (*Claims, error)
Parse JWT token and return Claims or error
func (*RSATokenParser) ParseCtxWithClaims ¶
func (p *RSATokenParser) ParseCtxWithClaims(context Context, f CtxClaimsFunc) error
ParseCtxWithClaims takes context, parse JWT token, convert context and, if token valid, calls f with converted context and JWT Claims
func (*RSATokenParser) ParseWithClaims ¶
func (p *RSATokenParser) ParseWithClaims(t Token, f ClaimsFunc) error
ParseWithClaims takes t, parse JWT token and, if token valid, calls f with JWT Claims
type RSATokenSigner ¶
type RSATokenSigner struct {
// contains filtered or unexported fields
}
RSATokenSigner for signing JWT tokens Implements TokenSigner
func NewRSATokenSigner ¶
func NewRSATokenSigner(privateKey []byte) (*RSATokenSigner, error)
NewRSATokenSigner parse privateKey and return correct instance
type TokenParser ¶
type TokenParser interface { Parse(Token) (*Claims, error) ParseWithClaims(Token, ClaimsFunc) error ParseCtxWithClaims(Context, CtxClaimsFunc) error }
TokenParser interface for JWT token parsers and point for mocking (see ctxtgtest subpackage)
type TokenSigner ¶
TokenSigner interface for JWT token signing and point for mocking (see ctxtgtest subpackage)