Documentation
¶
Overview ¶
Package zitadelgin provides a Gin middleware that authorizes incoming requests using the ZITADEL authorization SDK. It verifies the bearer token found in the request, optionally enforces role checks, and makes the resulting authorization context available to downstream handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interceptor ¶
type Interceptor[T authorization.Ctx] struct { // contains filtered or unexported fields }
Interceptor wraps a ZITADEL authorization.Authorizer and exposes Gin middleware for protecting routes. T is the concrete authorization context type used by the configured authorizer.
func NewZitadelGin ¶
func NewZitadelGin[T authorization.Ctx](authorizer *authorization.Authorizer[T]) *Interceptor[T]
NewZitadelGin returns an Interceptor backed by the given authorizer.
func (*Interceptor[T]) Context ¶
func (i *Interceptor[T]) Context(ctx context.Context) T
Context returns the authorization context stored on ctx by Interceptor.RequireAuthorization. If no authorization context is present the zero value of T is returned.
func (*Interceptor[T]) RequireAuthorization ¶
func (i *Interceptor[T]) RequireAuthorization(options ...authorization.CheckOption) gin.HandlerFunc
RequireAuthorization returns a Gin middleware that verifies the request's authorization header before invoking the next handler. The optional authorization.CheckOption values (for example authorization.WithRole) impose additional requirements such as a granted role.
On success the verified authorization context is stored on the request context and can be retrieved with Interceptor.Context. On failure the request is aborted with an appropriate status code:
- 401 Unauthorized: the token is missing, malformed, or invalid.
- 403 Forbidden: the token is valid but lacks a required permission.
- 500 Internal Server Error: authorization could not be evaluated (for example ZITADEL was unreachable). The underlying error is not exposed to the caller.