BlockadeLabs-SDK-DotNet-Proxy 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlockadeLabs-SDK-DotNet-Proxy --version 1.0.0                
NuGet\Install-Package BlockadeLabs-SDK-DotNet-Proxy -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlockadeLabs-SDK-DotNet-Proxy" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlockadeLabs-SDK-DotNet-Proxy --version 1.0.0                
#r "nuget: BlockadeLabs-SDK-DotNet-Proxy, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlockadeLabs-SDK-DotNet-Proxy as a Cake Addin
#addin nuget:?package=BlockadeLabs-SDK-DotNet-Proxy&version=1.0.0

// Install BlockadeLabs-SDK-DotNet-Proxy as a Cake Tool
#tool nuget:?package=BlockadeLabs-SDK-DotNet-Proxy&version=1.0.0                

BlockadeLabs-SDK-DotNet-Proxy

NuGet version (BlockadeLabs-SDK-DotNet-Proxy)

A simple Proxy API gateway for BlockadeLabs-SDK-DotNet to make authenticated requests from a front end application without exposing your API keys.

Getting started

Install from NuGet

Install package BlockadeLabs-SDK-DotNet-Proxy from Nuget. Here's how via command line:

Install-Package BlockadeLabs-SDK-DotNet-Proxy

Documentation

Using either the BlockadeLabs-SDK-DotNet or com.rest.blockadelabs packages directly in your front-end app may expose your API keys and other sensitive information. To mitigate this risk, it is recommended to set up an intermediate API that makes requests to BlockadeLabs on behalf of your front-end app. This library can be utilized for both front-end and intermediary host configurations, ensuring secure communication with the BlockadeLabs API.

Front End Example

In the front end example, you will need to securely authenticate your users using your preferred OAuth provider. Once the user is authenticated, exchange your custom auth token with your API key on the backend.

Follow these steps:

  1. Setup a new project using either the BlockadeLabs-SDK-DotNet or com.rest.blockadelabs packages.
  2. Authenticate users with your OAuth provider.
  3. After successful authentication, create a new BlockadeLabsAuthentication object and pass in the custom token as your apiKey.
  4. Create a new BlockadeLabsSettings object and specify the domain where your intermediate API is located.
  5. Pass your new auth and settings objects to the BlockadeLabsClient constructor when you create the client instance.

Here's an example of how to set up the front end:

var authToken = await LoginAsync();
var auth = new BlockadeLabsAuthentication(authToken);
var settings = new BlockadeLabsSettings(domain: "api.your-custom-domain.com");
using var api = new BlockadeLabsClient(auth, settings);

This setup allows your front end application to securely communicate with your backend that will be using the BlockadeLabs-SDK-DotNet-Proxy, which then forwards requests to the BlockadeLabs API. This ensures that your BlockadeLabs API keys and other sensitive information remain secure throughout the process.

Back End Example

In this example, we demonstrate how to set up and use BlockadeLabsProxy in a new ASP.NET Core web app. The proxy server will handle authentication and forward requests to the BlockadeLabs API, ensuring that your API keys and other sensitive information remain secure.

  1. Create a new ASP.NET Core minimal web API project.
  2. Add the BlockadeLabs-SDK-DotNet nuget package to your project.
    • Powershell install: Install-Package BlockadeLabs-SDK-DotNet-Proxy
    • Manually editing .csproj: <PackageReference Include="BlockadeLabs-SDK-DotNet-Proxy" />
  3. Create a new class that inherits from AbstractAuthenticationFilter and override the ValidateAuthentication method. This will implement the IAuthenticationFilter that you will use to check user session token against your internal server.
  4. In Program.cs, create a new proxy web application by calling BlockadeLabsProxy.CreateWebApplication method, passing your custom AuthenticationFilter as a type argument.
  5. Create BlockadeLabsAuthentication as you would normally and load your API key from environment variable.
public partial class Program
{
    private class AuthenticationFilter : AbstractAuthenticationFilter
    {
        public override void ValidateAuthentication(IHeaderDictionary request)
        {
            // You will need to implement your own class to properly test
            // custom issued tokens you've setup for your end users.
            if (!request["x-api-key"].ToString().Contains(TestUserToken))
            {
                throw new AuthenticationException("User is not authorized");
            }
        }

        public override async Task ValidateAuthenticationAsync(IHeaderDictionary request)
        {
            await Task.CompletedTask; // remote resource call

            // You will need to implement your own class to properly test
            // custom issued tokens you've setup for your end users.
            if (!request["x-api-key"].ToString().Contains(TestUserToken))
            {
                throw new AuthenticationException("User is not authorized");
            }
        }
    }

    public static void Main(string[] args)
    {
        var auth = BlockadeLabsAuthentication.LoadFromEnvironment();
        using var blockadeLabsClient = new BlockadeLabsClient(auth);
        BlockadeLabsProxy.CreateWebApplication<AuthenticationFilter>(args, blockadeLabsClient).Run();
    }
}

Once you have set up your proxy server, your end users can now make authenticated requests to your proxy api instead of directly to the BlockadeLabs API. The proxy server will handle authentication and forward requests to the BlockadeLabs API, ensuring that your API keys and other sensitive information remain secure.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 157 8/7/2024
1.0.1 132 6/29/2024
1.0.0 120 6/29/2024