auth

package
v0.3.7-alpha6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const KeyClaim claim = "claim"

Variables

View Source
var ErrInvalidToken = errors.New("invalid token claims")
View Source
var ErrUnexpectedSigningToken = errors.New("unexpected token signing method")

Functions

func AlwaysAllowFunc

func AlwaysAllowFunc() bool

Types

type Config

type Config struct {
	Secret           string `default:"changeme"`
	TimeoutInSeconds uint64 `default:"86400"`
}

type Interceptor

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

func NewAuthInterceptor

func NewAuthInterceptor(jwtManager *Manager, policyClient *policyclient.Client) *Interceptor

NewAuthInterceptor returns an instance of Interceptor. It takes in Manager struct, and policyClient as input. Policy Client allows to dynamically change authorization policies.

func (*Interceptor) Stream

func (interceptor *Interceptor) Stream() grpc.StreamServerInterceptor

Custom Stream interceptor that adds claim extraction and authorization

func (*Interceptor) Unary

func (interceptor *Interceptor) Unary() grpc.UnaryServerInterceptor

Custom Unary( interceptor that adds claim extraction and authorization

type Manager

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

func NewJWTManager

func NewJWTManager(config Config) *Manager

func (*Manager) Generate

func (manager *Manager) Generate(ctx context.Context, user *user.User) (string, error)

Generate creates user claim based on passed user parameter, and encodes it to JWT token.

func (*Manager) Verify

func (manager *Manager) Verify(ctx context.Context, accessToken string) (*UserClaims, error)

Verify ensures that the token provided by the client is valid, after which it extracts the claims and returns them.

type StreamClaimInjector

type StreamClaimInjector struct {
	grpc.ServerStream
	Claims *UserClaims
}

Custom Stream that allows embedding of user claims for stream grpc (Similar to what describe in: https://stackoverflow.com/questions/60982406/how-to-safely-add-values-to-grpc-serverstream-in-interceptor)

func (StreamClaimInjector) Context

func (s StreamClaimInjector) Context() context.Context

type UserClaims

type UserClaims struct {
	jwt.RegisteredClaims
	Username string `json:"username"`
	TeamID   string `json:"team_id"`
	Role     string `json:"role"`
}

UserClaims represents contents of JWT token.

Jump to

Keyboard shortcuts

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