pub trait Middleware {
type AuthOk: Send;
// Required method
fn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
operation_id: &'life1 str,
headers: &'life2 HeaderMap,
request_context: &'life3 ApiGatewayProxyRequestContext,
lambda_context: &'life4 LambdaContext,
) -> Pin<Box<dyn Future<Output = Result<Self::AuthOk, HttpResponse>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
// Provided methods
fn wrap_handler_authed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
auth_ok: Self::AuthOk,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>
where F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext, Self::AuthOk) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn wrap_handler_unauthed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>
where F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}
Expand description
Middleware interface for handling request authentication and optionally wrapping each request (e.g., to perform logging/telemetry).
This trait is intended to be used with the #[async_trait]
attribute.
Required Associated Types§
Sourcetype AuthOk: Send
type AuthOk: Send
Type returned by a successful call to authenticate
.
This might represent a user, authentication session, or other abstraction relevant to
your API. If none of the API endpoints require authentication, simply use the unit type
(()
).
Required Methods§
Sourcefn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
operation_id: &'life1 str,
headers: &'life2 HeaderMap,
request_context: &'life3 ApiGatewayProxyRequestContext,
lambda_context: &'life4 LambdaContext,
) -> Pin<Box<dyn Future<Output = Result<Self::AuthOk, HttpResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
operation_id: &'life1 str,
headers: &'life2 HeaderMap,
request_context: &'life3 ApiGatewayProxyRequestContext,
lambda_context: &'life4 LambdaContext,
) -> Pin<Box<dyn Future<Output = Result<Self::AuthOk, HttpResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Authenticate the current request.
§Arguments
operation_id
- Operation ID associated with the current request (as defined in the OpenAPI definition).headers
- HTTP request headers (e.g.,Authorization
,Cookie
, etc.).request_context
- Amazon API Gateway request context containing information to identify the AWS account and resources invoking the Lambda function. It also includes Cognito identity information for the caller (see theidentity
field).lambda_context
- Lambda function execution context.
Provided Methods§
Sourcefn wrap_handler_authed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
auth_ok: Self::AuthOk,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>where
F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext, Self::AuthOk) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wrap_handler_authed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
auth_ok: Self::AuthOk,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>where
F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext, Self::AuthOk) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Wrap an authenticated request.
This method serves as an optional hook for running arbitrary code before and/or after each
request handler is invoked. For example, it may be used to implement logging or telemetry, or
to add HTTP response headers prior to returning the handler’s HttpResponse
to the client.
If implemented, this method should invoke the api_handler
argument as follows:
api_handler(headers, request_context, lambda_context, auth_ok)
§Arguments
api_handler
- API handler function to invoke.operation_id
- Operation ID associated with the current request (as defined in the OpenAPI definition).headers
- HTTP request headers (e.g.,Authorization
,Cookie
, etc.).request_context
- Amazon API Gateway request context containing information to identify the AWS account and resources invoking the Lambda function. It also includes Cognito identity information for the caller (see theidentity
field).lambda_context
- Lambda function execution context.auth_ok
- Output of successful call toauthenticate
method.
Sourcefn wrap_handler_unauthed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>where
F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wrap_handler_unauthed<'life0, 'life1, 'async_trait, F, Fut>(
&'life0 self,
api_handler: F,
operation_id: &'life1 str,
headers: HeaderMap,
request_context: ApiGatewayProxyRequestContext,
lambda_context: LambdaContext,
) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'async_trait>>where
F: FnOnce(HeaderMap, ApiGatewayProxyRequestContext, LambdaContext) -> Fut + Send + 'async_trait,
Fut: Future<Output = HttpResponse> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Wrap an unauthenticated request.
This method serves as an optional hook for running arbitrary code before and/or after each
request handler is invoked. For example, it may be used to implement logging or telemetry, or
to add HTTP response headers prior to returning the handler’s HttpResponse
to the client.
If implemented, this method should invoke the api_handler
argument as follows:
api_handler(headers, request_context, lambda_context)
§Arguments
api_handler
- API handler function to invoke.operation_id
- Operation ID associated with the current request (as defined in the OpenAPI definition).headers
- HTTP request headers (e.g.,Authorization
,Cookie
, etc.).request_context
- Amazon API Gateway request context containing information to identify the AWS account and resources invoking the Lambda function. It also includes Cognito identity information for the caller (see theidentity
field).lambda_context
- Lambda function execution context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.