How to pass claims / JWT to a Service Fabric stateless service?
<p>Is claims-based authorisation supported in Service Fabric stateless services?</p>

<p>Let's say that I have a web api that receives a JWT in the header. Can I pass the JWT or claims within to a Service fabric stateless service so that it can do some checking on the claims before performing sensitive operations? </p>

<p>I can see that we can pass in claims to a service by using ClaimsCredentials:</p>

<pre><code>var serviceProxyFactory = new ServiceProxyFactory(
    (callbackClient) =&gt; new FabricTransportServiceRemotingClientFactory(
        new FabricTransportSettings
        {
            SecurityCredentials = new ClaimsCredentials
            {
                LocalClaims = "[JWT HERE? or just Claims JSON?]"
            }
        }));

IMyService service = serviceProxyFactory.CreateServiceProxy&lt;IMyService&gt;(new Uri("fabric:/MyThing/MyService"));
</code></pre>

<p><a href="https://msdn.microsoft.com/en-us/library/azure/system.fabric.claimscredentials.localclaims.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/azure/system.fabric.claimscredentials.localclaims.aspx</a> says that LocalClaims is "the string representation of claims token acquired from STS (security token service)."</p>

<p>Also:</p>

<ul>
<li><p>Is ClaimsCredentials actually the base64 encoded JWT, or just a JSON payload of claim key:value properties?</p></li>
<li><p>Is there any specific configuration or code needed to be done in the stateless service?</p></li>
<li><p>How do you get access to the claims from the stateless service? </p></li>
</ul>

<p>At the moment, when I call the service, I get the following error, no matter what value I set LocalClaims to:</p>

<pre><code>System.Fabric.FabricCannotConnectException: Error in Connection during ServiceCommunication 
 ---&gt; System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80071C4C\r\n   
 at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Common.NativeServiceCommunication.IFabricServiceCommunicationClient2.EndRequest(IFabricAsyncOperationContext context)\r\n   
 at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)\r\n   at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)\r\n   --- End of inner exception stack trace ---\r\n   
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
 at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.&lt;RequestResponseAsync&gt;d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.&lt;InvokeWithRetryAsync&gt;d__7`1.MoveNext()
</code></pre>

<p>Thanks!</p>