auth_jwt

package
v0.4.42 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(
	cfg *ClientConfig,
) (*Client, error)

func (*Client) InjectTokenCtx

func (j *Client) InjectTokenCtx(ctx context.Context, header http.Header, spec connect.Spec) (context.Context, error)

Validates the ctx is authenticated. Stuffs the parsed token onto the context

type ClientConfig

type ClientConfig struct {
	// Standard Issuer Url. Used for building the JWKS Provider
	BackendIssuerUrl string
	// Optionally provide a frontend Issuer Url. Falls back to BackendIssuerUrl if not provided.
	// This should be equivalent to what will be present in the "iss" claim of the JWT token.
	// This may be different depending auth provider or if running thorugh a reverse proxy
	FrontendIssuerUrl  *string
	ApiAudiences       []string
	SignatureAlgorithm validator.SignatureAlgorithm
}

type CustomClaims

type CustomClaims struct {
	Scope       string   `json:"scope"`
	Permissions []string `json:"permissions,omitempty"`
	Email       *string  `json:"email,omitempty"`
}

CustomClaims contains custom data we want from the token.

func (CustomClaims) Validate

func (c CustomClaims) Validate(ctx context.Context) error

Validate does nothing for this example, but we need it to satisfy validator.CustomClaims interface.

type JwtValidator

type JwtValidator interface {
	ValidateToken(ctx context.Context, tokenString string) (any, error)
}

type MockJwtValidator

type MockJwtValidator struct {
	mock.Mock
}

MockJwtValidator is an autogenerated mock type for the JwtValidator type

func NewMockJwtValidator

func NewMockJwtValidator(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockJwtValidator

NewMockJwtValidator creates a new instance of MockJwtValidator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockJwtValidator) EXPECT

func (*MockJwtValidator) ValidateToken

func (_m *MockJwtValidator) ValidateToken(ctx context.Context, tokenString string) (interface{}, error)

ValidateToken provides a mock function with given fields: ctx, tokenString

type MockJwtValidator_Expecter

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

func (*MockJwtValidator_Expecter) ValidateToken

func (_e *MockJwtValidator_Expecter) ValidateToken(ctx interface{}, tokenString interface{}) *MockJwtValidator_ValidateToken_Call

ValidateToken is a helper method to define mock.On call

  • ctx context.Context
  • tokenString string

type MockJwtValidator_ValidateToken_Call

type MockJwtValidator_ValidateToken_Call struct {
	*mock.Call
}

MockJwtValidator_ValidateToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateToken'

func (*MockJwtValidator_ValidateToken_Call) Return

func (*MockJwtValidator_ValidateToken_Call) Run

func (*MockJwtValidator_ValidateToken_Call) RunAndReturn

type TokenContextData

type TokenContextData struct {
	ParsedToken *validator.ValidatedClaims
	RawToken    string

	Claims *CustomClaims

	AuthUserId string
	Scopes     []string // Contains Scopes & Permissions
}

func GetTokenDataFromCtx

func GetTokenDataFromCtx(ctx context.Context) (*TokenContextData, error)

func (*TokenContextData) HasScope

func (t *TokenContextData) HasScope(scope string) bool

type TokenContextKey

type TokenContextKey struct{}

Jump to

Keyboard shortcuts

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