Class ApiKeyInterceptor
Server interceptor enforcing x-api-key authentication on every gRPC
call (including JSON-transcoded ones) when Enabled.
Health-check methods stay open so probes and load balancers keep working, and
so do the Dapr sidecar's own app callbacks (see
Virtufin.Api.Auth.ApiKeyInterceptor.DaprAppCallbackPrefix).
public sealed class ApiKeyInterceptor : Interceptor
- Inheritance
-
ApiKeyInterceptor
- Inherited Members
Constructors
ApiKeyInterceptor(ApiKeyAuthOptions, ILogger<ApiKeyInterceptor>)
public ApiKeyInterceptor(ApiKeyAuthOptions options, ILogger<ApiKeyInterceptor> logger)
Parameters
optionsApiKeyAuthOptionsloggerILogger<ApiKeyInterceptor>
Fields
HeaderName
Request metadata header carrying the API key.
public const string HeaderName = "x-api-key"
Field Value
UserStateKey
UserState entry holding the authenticated key name.
public const string UserStateKey = "ApiKeyName"
Field Value
Methods
Authenticate(string, string?)
Core auth decision, separated from ServerCallContext for testability. Returns the authenticated key name, or null when the call is allowed without a key (auth disabled or exempt method). Throws RpcException (Unauthenticated) when a required key is missing or invalid.
public string? Authenticate(string method, string? presentedKey)
Parameters
Returns
ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, ServerCallContext, ClientStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting client streaming call.
public override Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, ServerCallContext context, ClientStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestStreamIAsyncStreamReader<TRequest>The request stream of the incoming invocation.
contextServerCallContextAn instance of ServerCallContext representing the context of the invocation.
continuationClientStreamingServerMethod<TRequest, TResponse>A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and return the response value of the RPC. The interceptor can choose to call it zero or more times at its discretion.
Returns
- Task<TResponse>
A future representing the response value of the RPC. The interceptor can simply return the return value from the continuation intact, or an arbitrary response value as it sees fit. The interceptor has the ability to wrap or substitute the request stream when calling the continuation.
Type Parameters
TRequestRequest message type for this method.
TResponseResponse message type for this method.
DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest>, IServerStreamWriter<TResponse>, ServerCallContext, DuplexStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting bidirectional streaming calls.
public override Task DuplexStreamingServerHandler<TRequest, TResponse>(IAsyncStreamReader<TRequest> requestStream, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, DuplexStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestStreamIAsyncStreamReader<TRequest>The request stream of the incoming invocation.
responseStreamIServerStreamWriter<TResponse>The response stream of the incoming invocation.
contextServerCallContextAn instance of ServerCallContext representing the context of the invocation.
continuationDuplexStreamingServerMethod<TRequest, TResponse>A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and the interceptor can choose to call it zero or more times at its discretion. The interceptor has the ability to wrap or substitute the request and response streams when calling the continuation.
Returns
Type Parameters
TRequestRequest message type for this method.
TResponseResponse message type for this method.
ServerStreamingServerHandler<TRequest, TResponse>(TRequest, IServerStreamWriter<TResponse>, ServerCallContext, ServerStreamingServerMethod<TRequest, TResponse>)
Server-side handler for intercepting server streaming call.
public override Task ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, IServerStreamWriter<TResponse> responseStream, ServerCallContext context, ServerStreamingServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestTRequestThe request value of the incoming invocation.
responseStreamIServerStreamWriter<TResponse>The response stream of the incoming invocation.
contextServerCallContextAn instance of ServerCallContext representing the context of the invocation.
continuationServerStreamingServerMethod<TRequest, TResponse>A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and the interceptor can choose to call it zero or more times at its discretion. The interceptor has the ability to wrap or substitute the request value and the response stream when calling the continuation.
Returns
Type Parameters
TRequestRequest message type for this method.
TResponseResponse message type for this method.
UnaryServerHandler<TRequest, TResponse>(TRequest, ServerCallContext, UnaryServerMethod<TRequest, TResponse>)
Server-side handler for intercepting an incoming unary call.
public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation) where TRequest : class where TResponse : class
Parameters
requestTRequestThe request value of the incoming invocation.
contextServerCallContextAn instance of ServerCallContext representing the context of the invocation.
continuationUnaryServerMethod<TRequest, TResponse>A delegate that asynchronously proceeds with the invocation, calling the next interceptor in the chain, or the service request handler, in case of the last interceptor and return the response value of the RPC. The interceptor can choose to call it zero or more times at its discretion.
Returns
- Task<TResponse>
A future representing the response value of the RPC. The interceptor can simply return the return value from the continuation intact, or an arbitrary response value as it sees fit.
Type Parameters
TRequestRequest message type for this method.
TResponseResponse message type for this method.