Documentation ¶
Index ¶
- Variables
- func AuthServerUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, ...) (any, error)
- func AuthoriseJWT(ctx context.Context) (context.Context, error)
- func AuthoriseRequestInterceptor(serverPath string) grpc.UnaryServerInterceptor
- func CreateJWT(username string) (string, error)
- func InjectClaimsIntoContext(ctx context.Context, claims jwt.Claims) context.Context
- type AuthServer
- func (s *AuthServer) ChangePassword(ctx context.Context, req *authpb.ChangePasswordRequest) (*authpb.ChangePasswordResponse, error)
- func (s *AuthServer) CreateNewUser(ctx context.Context, req *authpb.CreateNewUserRequest) (*authpb.CreateNewUserResponse, error)
- func (s *AuthServer) Login(ctx context.Context, req *authpb.LoginRequest) (*authpb.LoginResponse, error)
- type FlaggerJWTClaims
Constants ¶
This section is empty.
Variables ¶
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.
var EAuthMetadataNotFound = status.Error( codes.Unauthenticated, "authorization metdata not found", )
EAuthMetadataNotFound is a GRPC error that is returned when "authorization" metadata was not found.
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.
var EInvalidJWT = status.Error(codes.Unauthenticated, "invalid jwt")
EInvalidJWT is a GRPC error that is returned when the provided JWT doesn't complete validation.
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.
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.
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.
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 ¶
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.
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 (s *AuthServer) ChangePassword( ctx context.Context, req *authpb.ChangePasswordRequest, ) (*authpb.ChangePasswordResponse, error)
func (*AuthServer) CreateNewUser ¶
func (s *AuthServer) CreateNewUser( ctx context.Context, req *authpb.CreateNewUserRequest, ) (*authpb.CreateNewUserResponse, error)
func (*AuthServer) Login ¶
func (s *AuthServer) Login( ctx context.Context, req *authpb.LoginRequest, ) (*authpb.LoginResponse, error)
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.