diff --git a/src/Sdk/Cerbos/Sdk/Builder/CerbosClientBuilder.cs b/src/Sdk/Cerbos/Sdk/Builder/CerbosClientBuilder.cs
index bd19452..142cdcf 100644
--- a/src/Sdk/Cerbos/Sdk/Builder/CerbosClientBuilder.cs
+++ b/src/Sdk/Cerbos/Sdk/Builder/CerbosClientBuilder.cs
@@ -20,6 +20,7 @@ public sealed class CerbosClientBuilder
private StreamReader TlsCertificate { get; set; }
private StreamReader TlsKey { get; set; }
private GrpcChannelOptions GrpcChannelOptions { get; set; }
+ private Metadata Metadata { get; set; }
private CerbosClientBuilder(string target) {
Target = target;
@@ -30,6 +31,12 @@ public static CerbosClientBuilder ForTarget(string target)
return new CerbosClientBuilder(target);
}
+ public CerbosClientBuilder WithMetadata(Metadata headers)
+ {
+ Metadata = headers;
+ return this;
+ }
+
public CerbosClientBuilder WithPlaintext() {
Plaintext = true;
return this;
@@ -87,6 +94,14 @@ public CerbosClient Build()
callCredentials = CallCredentials.FromInterceptor((context, metadata) =>
{
metadata.Add(PlaygroundInstanceHeader, PlaygroundInstanceId.Trim());
+ if (Metadata != null)
+ {
+ foreach (var m in Metadata)
+ {
+ metadata.Add(m);
+ }
+ }
+
return Task.CompletedTask;
});
}
diff --git a/src/Sdk/Cerbos/Sdk/CerbosClient.cs b/src/Sdk/Cerbos/Sdk/CerbosClient.cs
index f004093..085f7c9 100644
--- a/src/Sdk/Cerbos/Sdk/CerbosClient.cs
+++ b/src/Sdk/Cerbos/Sdk/CerbosClient.cs
@@ -4,6 +4,7 @@
using System;
using System.Threading.Tasks;
using Cerbos.Sdk.Response;
+using Grpc.Core;
namespace Cerbos.Sdk
{
@@ -22,11 +23,11 @@ public CerbosClient(Api.V1.Svc.CerbosService.CerbosServiceClient cerbosServiceCl
///
/// Send a request consisting of a principal, resource(s) & action(s) to see if the principal is authorized to do the action(s) on the resource(s).
///
- public CheckResourcesResponse CheckResources(Builder.CheckResourcesRequest request)
+ public CheckResourcesResponse CheckResources(Builder.CheckResourcesRequest request, Metadata headers = null)
{
try
{
- return new CheckResourcesResponse(CerbosServiceClient.CheckResources(request.ToCheckResourcesRequest()));
+ return new CheckResourcesResponse(CerbosServiceClient.CheckResources(request.ToCheckResourcesRequest(), headers));
}
catch (Exception e)
{
@@ -37,12 +38,12 @@ public CheckResourcesResponse CheckResources(Builder.CheckResourcesRequest reque
///
/// Send an async request consisting of a principal, resource(s) & action(s) to see if the principal is authorized to do the action(s) on the resource(s).
///
- public Task CheckResourcesAsync(Builder.CheckResourcesRequest request)
+ public Task CheckResourcesAsync(Builder.CheckResourcesRequest request, Metadata headers = null)
{
try
{
return CerbosServiceClient
- .CheckResourcesAsync(request.ToCheckResourcesRequest())
+ .CheckResourcesAsync(request.ToCheckResourcesRequest(), headers)
.ResponseAsync
.ContinueWith(
r => new CheckResourcesResponse(r.Result)
@@ -57,11 +58,11 @@ public Task CheckResourcesAsync(Builder.CheckResourcesRe
///
/// Obtain a query plan for performing the given action on the given resource kind.
///
- public PlanResourcesResponse PlanResources(Builder.PlanResourcesRequest request)
+ public PlanResourcesResponse PlanResources(Builder.PlanResourcesRequest request, Metadata headers = null)
{
try
{
- return new PlanResourcesResponse(CerbosServiceClient.PlanResources(request.ToPlanResourcesRequest()));
+ return new PlanResourcesResponse(CerbosServiceClient.PlanResources(request.ToPlanResourcesRequest(), headers));
}
catch (Exception e)
{
@@ -72,12 +73,12 @@ public PlanResourcesResponse PlanResources(Builder.PlanResourcesRequest request)
///
/// Obtain a query plan for performing the given action on the given resource kind.
///
- public Task PlanResourcesAsync(Builder.PlanResourcesRequest request)
+ public Task PlanResourcesAsync(Builder.PlanResourcesRequest request, Metadata headers = null)
{
try
{
return CerbosServiceClient
- .PlanResourcesAsync(request.ToPlanResourcesRequest())
+ .PlanResourcesAsync(request.ToPlanResourcesRequest(), headers)
.ResponseAsync
.ContinueWith(
r => new PlanResourcesResponse(r.Result)