authnrpc

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated = newError(connect.CodeUnauthenticated, "missing or invalid authentication")
	ErrInternal        = newError(connect.CodeInternal, "internal error")
)

Common errors to be returned by handler methods.

Functions

This section is empty.

Types

type Handler

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

Handler implements the AuthnService RPC.

func New

func New(issuer Issuer, parser Parser) *Handler

New creates a new Handler.

func (*Handler) Authenticate

func (h *Handler) Authenticate(
	ctx context.Context,
	req *connect.Request[authnv1.AuthenticateRequest],
) (*connect.Response[authnv1.AuthenticateResponse], error)

Authenticate validates the given token and returns a subset of the claims for use in other logic.

func (*Handler) Login

func (h *Handler) Login(
	ctx context.Context,
	req *connect.Request[authnv1.LoginRequest],
) (*connect.Response[authnv1.LoginResponse], error)

Login returns a JWT for the ID in the request.

No validation of the caller's identity is performed, nor whether the given secret is in any way valid. While this is normally indefensible, this method exists only as a means to experiment with authorization implementations, and is thus acceptable.

In a production environment, this would likely involve checking the identity exists in a database. Additionally, validation that the secret is acceptable for that identity would be performed.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux, opts []connect.HandlerOption)

Register adds the handler to the given multiplexer.

type Issuer

type Issuer interface {
	Issue(string, uint32) (string, error)
}

Issuer is used to issue JWTs.

type Parser

type Parser interface {
	Parse(string) (jwt.Claims, error)
}

Parser is used to parse a JWT.

Jump to

Keyboard shortcuts

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