Liking cljdoc? Tell your friends :D

boundary.user.shell.middleware

Authentication and authorization middleware for HTTP endpoints.

This middleware provides:

  • JWT token validation
  • Session-based authentication
  • Role-based authorization
  • Request context enrichment with user information
Authentication and authorization middleware for HTTP endpoints.

This middleware provides:
- JWT token validation
- Session-based authentication
- Role-based authorization
- Request context enrichment with user information
raw docstring

create-forbidden-responseclj

(create-forbidden-response message reason)
(create-forbidden-response message reason request)

Creates standardized 403 Forbidden response.

For web UI requests (path starts with /web), redirects to login page. For API requests, returns JSON error response.

Args: message: Error message string reason: Keyword reason code request: Optional request map to determine response type

Returns: Ring response map

Creates standardized 403 Forbidden response.

For web UI requests (path starts with /web), redirects to login page.
For API requests, returns JSON error response.

Args:
  message: Error message string
  reason: Keyword reason code
  request: Optional request map to determine response type
  
Returns:
  Ring response map
sourceraw docstring

create-unauthorized-responseclj

(create-unauthorized-response message reason)
(create-unauthorized-response message reason request)

Creates standardized 401 Unauthorized response.

For web UI requests (path starts with /web), redirects to login page. For API requests, returns JSON error response.

Args: message: Error message string reason: Keyword reason code request: Optional request map to determine response type

Returns: Ring response map

Creates standardized 401 Unauthorized response.

For web UI requests (path starts with /web), redirects to login page.
For API requests, returns JSON error response.

Args:
  message: Error message string
  reason: Keyword reason code
  request: Optional request map to determine response type
  
Returns:
  Ring response map
sourceraw docstring

extract-bearer-tokenclj

(extract-bearer-token request)

Extracts Bearer token from Authorization header.

Args: request: HTTP request map

Returns: String token or nil if not found

Extracts Bearer token from Authorization header.

Args:
  request: HTTP request map
  
Returns:
  String token or nil if not found
sourceraw docstring

extract-session-tokenclj

(extract-session-token request)

Extracts session token from request headers or cookies.

Looks for token in:

  1. X-Session-Token header
  2. session-token cookie

Args: request: HTTP request map

Returns: String token or nil if not found

Extracts session token from request headers or cookies.

Looks for token in:
1. X-Session-Token header
2. session-token cookie

Args:
  request: HTTP request map
  
Returns:
  String token or nil if not found
sourceraw docstring

flexible-authentication-middlewareclj

(flexible-authentication-middleware user-service)
(flexible-authentication-middleware user-service handler)

Middleware that accepts either JWT or session token authentication.

Tries JWT first (from Authorization header), then falls back to session token. Adds user information to request on successful authentication.

This is a middleware factory function compatible with Reitit. Call with user-service to get a middleware function.

Args: user-service: User service instance for session validation handler: (optional, for direct wrapping) Handler function

Returns: Middleware function that takes handler and returns wrapped handler

Example: ;; In Reitit routes: {:middleware [[flexible-authentication-middleware user-service]]}

Middleware that accepts either JWT or session token authentication.

Tries JWT first (from Authorization header), then falls back to session token.
Adds user information to request on successful authentication.

This is a middleware factory function compatible with Reitit.
Call with user-service to get a middleware function.

Args:
  user-service: User service instance for session validation
  handler: (optional, for direct wrapping) Handler function
  
Returns:
  Middleware function that takes handler and returns wrapped handler
  
Example:
  ;; In Reitit routes:
  {:middleware [[flexible-authentication-middleware user-service]]}
sourceraw docstring

jwt-authentication-middlewareclj

(jwt-authentication-middleware handler)

Middleware that validates JWT tokens from Authorization header.

Extracts Bearer token, validates it, and adds user information to request. On validation failure, returns 401 response.

Args: handler: Next handler in the chain

Returns: Wrapped handler function

Middleware that validates JWT tokens from Authorization header.

Extracts Bearer token, validates it, and adds user information to request.
On validation failure, returns 401 response.

Args:
  handler: Next handler in the chain
  
Returns:
  Wrapped handler function
sourceraw docstring

protect-admin-onlyclj

(protect-admin-only user-service handler)

Wraps handler with admin-only access control.

Args: user-service: User service for session validation handler: Handler to protect

Returns: Protected handler with authentication and admin authorization

Wraps handler with admin-only access control.

Args:
  user-service: User service for session validation
  handler: Handler to protect
  
Returns:
  Protected handler with authentication and admin authorization
sourceraw docstring

protect-with-flexible-authclj

(protect-with-flexible-auth user-service handler)

Wraps handler with flexible authentication (JWT or session).

Args: user-service: User service for session validation handler: Handler to protect

Returns: Protected handler

Wraps handler with flexible authentication (JWT or session).

Args:
  user-service: User service for session validation
  handler: Handler to protect
  
Returns:
  Protected handler
sourceraw docstring

protect-with-jwtclj

(protect-with-jwt handler)

Wraps handler with JWT authentication.

Args: handler: Handler to protect

Returns: Protected handler

Wraps handler with JWT authentication.

Args:
  handler: Handler to protect
  
Returns:
  Protected handler
sourceraw docstring

protect-with-sessionclj

(protect-with-session user-service handler)

Wraps handler with session authentication.

Args: user-service: User service for session validation handler: Handler to protect

Returns: Protected handler

Wraps handler with session authentication.

Args:
  user-service: User service for session validation
  handler: Handler to protect
  
Returns:
  Protected handler
sourceraw docstring

require-admin-middlewareclj

(require-admin-middleware handler)

Middleware that requires admin role.

Args: handler: Next handler in the chain

Returns: Wrapped handler function

Middleware that requires admin role.

Args:
  handler: Next handler in the chain
  
Returns:
  Wrapped handler function
sourceraw docstring

require-role-middlewareclj

(require-role-middleware required-roles handler)

Middleware that requires user to have specific role(s).

Must be used after authentication middleware that sets :user in request.

Args: required-roles: Set of required roles (keywords) handler: Next handler in the chain

Returns: Wrapped handler function

Middleware that requires user to have specific role(s).

Must be used after authentication middleware that sets :user in request.

Args:
  required-roles: Set of required roles (keywords)
  handler: Next handler in the chain
  
Returns:
  Wrapped handler function
sourceraw docstring

session-authentication-middlewareclj

(session-authentication-middleware user-service handler)

Middleware that validates session tokens and updates session access time.

Extracts session token, validates it through user service, and adds user information to request. On validation failure, returns 401 response.

Args: user-service: User service instance for session validation handler: Next handler in the chain

Returns: Wrapped handler function

Middleware that validates session tokens and updates session access time.

Extracts session token, validates it through user service, and adds user
information to request. On validation failure, returns 401 response.

Args:
  user-service: User service instance for session validation
  handler: Next handler in the chain
  
Returns:
  Wrapped handler function
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close