Skip to content

Commit

Permalink
updated readme (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreloureiro88 committed Jan 19, 2022
1 parent ccc0060 commit 1587fe6
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# .NET SDK for Castle

[![Build status](https://ci.appveyor.com/api/projects/status/rf0304hhym6k7d7s/branch/master?svg=true)](https://ci.appveyor.com/project/DevTools/castle-dotnet)
[![NuGet](https://img.shields.io/nuget/v/castle.sdk.svg)](https://www.nuget.org/packages/Castle.Sdk/)
[![Coverage Status](https://coveralls.io/repos/github/castle/castle-dotnet/badge.svg?branch=master)](https://coveralls.io/github/castle/castle-dotnet?branch=master)

Supporting **.NET Standard 2.0** and **.NET Framework 4.6.1+**. Refer to Microsoft's [documentation](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) for compatibility information.
Supporting **.NET 6.0**, **.NET 5.0**, **.NET Core 3.0**, **.NET Standard 2.0** and **.NET Framework 4.6.1+**. Refer to Microsoft's [documentation](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) for compatibility information.

**[Castle](https://castle.io) analyzes user behavior in web and mobile apps to stop fraud before it happens.**

Expand Down Expand Up @@ -40,6 +41,7 @@ var client = new CastleClient("YOUR SECRET");
It's a good idea to set up your `CastleClient` instance using an IoC container.

### asp.net core

```csharp
public void ConfigureServices(IServiceCollection services)
{
Expand All @@ -51,24 +53,25 @@ public void ConfigureServices(IServiceCollection services)

The `CastleConfiguration` object has a number of properties that control the SDK.

Property | Default | Description
--- | --- | ---
ApiSecret | | Secret used to authenticate with the Castle Api. ***Required***
FailoverStrategy | Allow | The response action to return in case of a failover in an Authenticate request.
Timeout | 1000 | Timeout for requests, in milliseconds.
BaseUrl | https://api.castle.io | Base Castle Api url.
LogLevel | Error | The log level applied by the injected `ICastleLogger` implementation.
AllowList | | List of headers that should be passed intact to the API. A list of recommended .headers can be retrieved from the static property `Castle.Headers.AllowList` in the SDK
DenyList | | List of header that should *not* be passed intact to the API.
DoNotTrack | false | If true, no requests are actually sent to the Caste Api, and Authenticate returns a failover response.
Logger | | Your own logger implementation.
IpHeaders | | IP Headers to look for a client IP address
TrustedProxies | | Trusted public proxies list
TrustedProxyDepth | 0 | Number of trusted proxies used in the chain
TrustProxyChain | false | Is trusting all of the proxy IPs in X-Forwarded-For enabled
| Property | Default | Description |
| ----------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ApiSecret | | Secret used to authenticate with the Castle Api. **_Required_** |
| FailoverStrategy | Allow | The response action to return in case of a failover in an Authenticate request. |
| Timeout | 1000 | Timeout for requests, in milliseconds. |
| BaseUrl | https://api.castle.io | Base Castle Api url. |
| LogLevel | Error | The log level applied by the injected `ICastleLogger` implementation. |
| AllowList | | List of headers that should be passed intact to the API. A list of recommended .headers can be retrieved from the static property `Castle.Headers.AllowList` in the SDK |
| DenyList | | List of header that should _not_ be passed intact to the API. |
| DoNotTrack | false | If true, no requests are actually sent to the Caste Api, and Authenticate returns a failover response. |
| Logger | | Your own logger implementation. |
| IpHeaders | | IP Headers to look for a client IP address |
| TrustedProxies | | Trusted public proxies list |
| TrustedProxyDepth | 0 | Number of trusted proxies used in the chain |
| TrustProxyChain | false | Is trusting all of the proxy IPs in X-Forwarded-For enabled |

## Logging
The SDK allows customized logging by way of implementing the `ICastleLogger` interface and passing in an instance as part of the `CastleConfiguration`. Exactly what gets logged can be controlled by setting the `LogLevel` property of `CastleConfiguration`.

The SDK allows customized logging by way of implementing the `ICastleLogger` interface and passing in an instance as part of the `CastleConfiguration`. Exactly what gets logged can be controlled by setting the `LogLevel` property of `CastleConfiguration`.

```csharp
var client = new CastleClient(new CastleConfiguration("secret") {
Expand All @@ -77,6 +80,7 @@ var client = new CastleClient(new CastleConfiguration("secret") {
```

### Logger example

```csharp
public class DebugLogger : ICastleLogger
{
Expand All @@ -98,6 +102,7 @@ public class DebugLogger : ICastleLogger
```

##### ASP.NET MVC 5

```csharp
public class HomeController : Controller
{
Expand All @@ -110,6 +115,7 @@ public class HomeController : Controller
```

##### ASP.NET Core

```csharp
public class IndexModel : PageModel
{
Expand All @@ -121,18 +127,19 @@ public class IndexModel : PageModel
...
```


## Troubleshooting

### Can't find System.Runtime.InteropServices.RuntimeInformation

You target .NET Framework and get an exception on startup.

`System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.`

The Castle SDK has a dependency on [Sentry.PlatformAbstractions](https://www.nuget.org/packages/Sentry.PlatformAbstractions/), which in turn uses `System.Runtime.InteropServices.RuntimeInformation`, version 4.3.0.
#### Solution
Find the binding redirect for `System.Runtime.InteropServices.RuntimeInformation` in `web.config` and either remove the entire `dependentAssembly` element, or update `newVersion` to 4.3.0.

Find the binding redirect for `System.Runtime.InteropServices.RuntimeInformation` in `web.config` and either remove the entire `dependentAssembly` element, or update `newVersion` to 4.3.0.

# Demo application

Expand Down

0 comments on commit 1587fe6

Please sign in to comment.