-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*Merge master into release branch Co-authored-by: Ryan Nowak <nowakra@gmail.com> Co-authored-by: Ryan Nowak <nowakra@gmail.com> Co-authored-by: Carlos Mendible <cmendible@gmail.com> Co-authored-by: Arghya Sadhu <arghya88@gmail.com> Co-authored-by: Per Ökvist <perokvist@users.noreply.github.com> Co-authored-by: Sander Molenkamp <a.molenkamp@gmail.com> Co-authored-by: LukePammant <Luke.pammant@gmail.com>
- Loading branch information
1 parent
191fd65
commit a4f6f04
Showing
150 changed files
with
6,424 additions
and
3,797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,6 @@ bld/ | |
.vscode/ | ||
|
||
# coverlet code coverage results | ||
coverage.json | ||
coverage.json | ||
.fake | ||
.ionide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Configure API token for authentication | ||
|
||
Dapr runtime supports token based authentication wherein it requires every incoming API request to include an authentication token in the request headers. For more information, refer [here](https://docs.dapr.io/operations/security/api-token/). | ||
|
||
Dotnet Sdk supports this by providing a mechanism to allow the user to specify a token. | ||
|
||
# Dapr Client | ||
You can use the code below to specify an api token:- | ||
``` | ||
var daprClient = new DaprClientBuilder() | ||
.UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient }) | ||
.UseDaprApiToken("your_token") | ||
.Build(); | ||
``` | ||
|
||
# Actors | ||
With actors, you can specify the api token using ActorProxyOptions as below:- | ||
``` | ||
var actorId = new ActorId("abc"); | ||
var factory = new ActorProxyFactory(); | ||
factory.DefaultOptions.DaprApiToken = "your_token"; | ||
// Make strongly typed Actor calls with Remoting. | ||
var remotingProxy = factory.CreateActorProxy<IDemoActor>(actorId, "DemoActor"); | ||
// Making calls without Remoting, this shows method invocation using InvokeMethodAsync methods, the method name and its payload is provided as arguments to InvokeMethodAsync methods. | ||
var nonRemotingProxy = factory.Create(actorId, "DemoActor"); | ||
``` | ||
You need to configure the token in the actor itself as below:- | ||
``` | ||
..... | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
.... | ||
services.AddActors(options => | ||
{ | ||
options.DaprApiToken = "your_token"; | ||
options.Actors.RegisterActor<YourActor>(); | ||
}); | ||
.... | ||
} | ||
``` | ||
|
||
The calls made using the proxy created with the above code will have the request headers with:- | ||
"dapr-api-token":"your_token" | ||
|
||
Alternatively, the user can set an environment variable "DAPR_API_TOKEN" with the token value. In case the user has specified the token using code as well as the environment variable is set, the value set via code will be used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Working with cancellation tokens | ||
|
||
Asynchronous APIs exposed by `DaprClient` accept a cancellation token and by default, if the operation is canceled, you will get an OperationCanceledException. However, if you choose to initialize and pass in your own GrpcChannelOptions to the client builder, then unless you enable the [ThrowOperationCanceledOnCancellation setting](https://grpc.github.io/grpc/csharp-dotnet/api/Grpc.Net.Client.GrpcChannelOptions.html#Grpc_Net_Client_GrpcChannelOptions_ThrowOperationCanceledOnCancellation), the exception thrown would be an RpcException with StatusCode as Cancelled. To get an OperationCanceledException instead, refer to the code below:- | ||
```c# | ||
var httpClient = new HttpClient(); | ||
var daprClient = new DaprClientBuilder() | ||
.UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient, ThrowOperationCanceledOnCancellation = true }) | ||
.Build(); | ||
``` |
Oops, something went wrong.