auth

package
v0.0.0-...-ec63eb9 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EAuthMetadataLength = status.Error(
	codes.InvalidArgument,
	"invalid authorization metadata value",
)

EAuthMetadataLength is a GRPC error that is returned when the length of "authorization" metadata is of incorrect length.

View Source
var EAuthMetadataNotFound = status.Error(
	codes.Unauthenticated,
	"authorization metdata not found",
)

EAuthMetadataNotFound is a GRPC error that is returned when "authorization" metadata was not found.

View Source
var EIncorrectUsernameOrPassword = status.Error(
	codes.Unauthenticated,
	"incorrect username or password",
)

EIncorrectUsernameOrPassword is a GRPC error that is returned when the provided usernam or password is incorrect.

View Source
var EInvalidJWT = status.Error(codes.Unauthenticated, "invalid jwt")

EInvalidJWT is a GRPC error that is returned when the provided JWT doesn't complete validation.

View Source
var EInvalidTokenFormat = status.Error(
	codes.InvalidArgument,
	"invalid bearer header format",
)

EInvalidTokenFormat is a GRPC error that is returned when the format of the provided token does match the expected format.

View Source
var EJWTSign = status.Error(codes.Internal, "error while signing JWT")

EJWTSign is a GRPC error that is returned when an error occurs while signing a JWT.

View Source
var EMetadataNotFound = status.Error(
	codes.InvalidArgument,
	"could not find incoming request metadata",
)

EMetadataNotFound is a GRPC error that is returned when the request metadata could not be found.

View Source
var ENoTokenClaims = status.Error(
	codes.Internal,
	"could not find token claims",
)

ENoTokenClaims is a GRPC error that is returned when the claims in the provided token were not found.

Functions

func AuthServerUnaryInterceptor

func AuthServerUnaryInterceptor(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

AuthServerUnaryInterceptor intercepts the requests coming to the authentication service.

func AuthoriseJWT

func AuthoriseJWT(ctx context.Context) (context.Context, error)

AuthoriseJWT takes a GRPC context and validates that the current request has the "authorization" header and is a valid JWT. If the token is present and valid, adds the claims to the context and returns a new context for the handler. All errors from this middleware will be GRPC compliant.

func AuthoriseRequestInterceptor

func AuthoriseRequestInterceptor(serverPath string) grpc.UnaryServerInterceptor

AuthoriseRequestInterceptor checks if the provided serverPath is the prefix in the intercepted method and then validates the JWT in the request metadata.

func CreateJWT

func CreateJWT(username string) (string, error)

CreateJWT generates a new JWT with an expiry time that is 24 hours from now. It also adds the provided username to the `sub` field of the token.

func InjectClaimsIntoContext

func InjectClaimsIntoContext(
	ctx context.Context,
	claims jwt.Claims,
) context.Context

InjectClaimsIntoContext creates a new context with the claims of a JWT.

Types

type AuthServer

type AuthServer struct {
	authpb.UnimplementedAuthServer
	// contains filtered or unexported fields
}

func NewAuthServer

func NewAuthServer(userRepo user.UserRepository) *AuthServer

NewAuthServer creates a new server for the auth service.

func (*AuthServer) ChangePassword

func (*AuthServer) CreateNewUser

func (*AuthServer) Login

type FlaggerJWTClaims

type FlaggerJWTClaims struct {
	jwt.RegisteredClaims
}

FlaggerJWTClaims are the claims that a JWT must contain when authenticating with flagger.

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) (*FlaggerJWTClaims, bool)

ClaimsFromContext takes a context and tries to find the claims added by the authentication middleware.

func VerifyJWT

func VerifyJWT(str string) (*FlaggerJWTClaims, error)

VerifyJWT verifies that the provided string is valid and that it contains FlaggerJWTClaims as the claims. All errors returned from this function are GRPC compliant.

Jump to

Keyboard shortcuts

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