Table of Contents

Class ApiKeyInterceptor

Namespace
Virtufin.Api.Auth
Assembly
Virtufin.Api.dll

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

options ApiKeyAuthOptions
logger ILogger<ApiKeyInterceptor>

Fields

HeaderName

Request metadata header carrying the API key.

public const string HeaderName = "x-api-key"

Field Value

string

UserStateKey

UserState entry holding the authenticated key name.

public const string UserStateKey = "ApiKeyName"

Field Value

string

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

method string
presentedKey string

Returns

string

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

requestStream IAsyncStreamReader<TRequest>

The request stream of the incoming invocation.

context ServerCallContext

An instance of ServerCallContext representing the context of the invocation.

continuation ClientStreamingServerMethod<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

TRequest

Request message type for this method.

TResponse

Response 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

requestStream IAsyncStreamReader<TRequest>

The request stream of the incoming invocation.

responseStream IServerStreamWriter<TResponse>

The response stream of the incoming invocation.

context ServerCallContext

An instance of ServerCallContext representing the context of the invocation.

continuation DuplexStreamingServerMethod<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

Task

Type Parameters

TRequest

Request message type for this method.

TResponse

Response 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

request TRequest

The request value of the incoming invocation.

responseStream IServerStreamWriter<TResponse>

The response stream of the incoming invocation.

context ServerCallContext

An instance of ServerCallContext representing the context of the invocation.

continuation ServerStreamingServerMethod<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

Task

Type Parameters

TRequest

Request message type for this method.

TResponse

Response 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

request TRequest

The request value of the incoming invocation.

context ServerCallContext

An instance of ServerCallContext representing the context of the invocation.

continuation UnaryServerMethod<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

TRequest

Request message type for this method.

TResponse

Response message type for this method.