diff --git a/ElevenLabs-DotNet-Proxy/Readme.md b/ElevenLabs-DotNet-Proxy/Readme.md index 2319007..8aa3ae8 100644 --- a/ElevenLabs-DotNet-Proxy/Readme.md +++ b/ElevenLabs-DotNet-Proxy/Readme.md @@ -51,7 +51,7 @@ In this example, we demonstrate how to set up and use `ElevenLabsProxyStartup` i - Powershell install: `Install-Package ElevenLabs-DotNet-Proxy` - Manually editing .csproj: `` 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 `ElevenLabsProxyStartup.CreateDefaultHost` method, passing your custom `AuthenticationFilter` as a type argument. +4. In `Program.cs`, create a new proxy web application by calling `ElevenLabsProxyStartup.CreateWebApplication` method, passing your custom `AuthenticationFilter` as a type argument. 5. Create `ElevenLabsAuthentication` and `ElevenLabsClientSettings` as you would normally with your API keys, org id, or Azure settings. ```csharp @@ -63,7 +63,19 @@ public partial class Program { // You will need to implement your own class to properly test // custom issued tokens you've setup for your end users. - if (!request["xi-api-key"].ToString().Contains(userToken)) + if (!request["xi-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["xi-api-key"].ToString().Contains(TestUserToken)) { throw new AuthenticationException("User is not authorized"); } @@ -72,9 +84,9 @@ public partial class Program public static void Main(string[] args) { - var client = new ElevenLabsClient(); - var proxy = ElevenLabsProxyStartup.CreateDefaultHost(args, client); - proxy.Run(); + var auth = ElevenLabsAuthentication.LoadFromEnv(); + var client = new ElevenLabsClient(auth); + ElevenLabsProxyStartup.CreateWebApplication(args, client).Run(); } } ``` diff --git a/ElevenLabs-DotNet-Tests-Proxy/Program.cs b/ElevenLabs-DotNet-Tests-Proxy/Program.cs index d959642..37d5d1d 100644 --- a/ElevenLabs-DotNet-Tests-Proxy/Program.cs +++ b/ElevenLabs-DotNet-Tests-Proxy/Program.cs @@ -2,8 +2,8 @@ using ElevenLabs.Proxy; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Hosting; using System.Security.Authentication; +using System.Threading.Tasks; namespace ElevenLabs.Tests.Proxy { @@ -27,14 +27,25 @@ public override void ValidateAuthentication(IHeaderDictionary request) 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["xi-api-key"].ToString().Contains(TestUserToken)) + { + throw new AuthenticationException("User is not authorized"); + } + } } public static void Main(string[] args) { var auth = ElevenLabsAuthentication.LoadFromEnv(); var client = new ElevenLabsClient(auth); - var proxy = ElevenLabsProxyStartup.CreateDefaultHost(args, client); - proxy.Run(); + ElevenLabsProxyStartup.CreateWebApplication(args, client).Run(); } } } \ No newline at end of file diff --git a/ElevenLabs-DotNet/Authentication/ElevenLabsAuthentication.cs b/ElevenLabs-DotNet/Authentication/ElevenLabsAuthentication.cs index d33bc86..18ecbf1 100644 --- a/ElevenLabs-DotNet/Authentication/ElevenLabsAuthentication.cs +++ b/ElevenLabs-DotNet/Authentication/ElevenLabsAuthentication.cs @@ -51,9 +51,9 @@ public static ElevenLabsAuthentication Default return cachedDefault; } - var auth = (LoadFromDirectory()) ?? - LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ?? - LoadFromEnv(); + var auth = LoadFromDirectory() ?? + LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ?? + LoadFromEnv(); cachedDefault = auth; return auth; } diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index d7a2c84..fb235ad 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -19,6 +19,7 @@ - Changed ElevenLabsClient to be IDisposable - The ElevenLabsClient must now be disposed if you do not pass your own HttpClient - Updated ElevenLabsClientSettings to accept custom domains +- Added filesystemless overloads for uploading audio clips Version 2.1.1 - Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings Version 2.1.0 diff --git a/README.md b/README.md index f70299e..848f51c 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ In this example, we demonstrate how to set up and use `ElevenLabsProxyStartup` i - Powershell install: `Install-Package ElevenLabs-DotNet-Proxy` - Manually editing .csproj: `` 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 `ElevenLabsProxyStartup.CreateDefaultHost` method, passing your custom `AuthenticationFilter` as a type argument. +4. In `Program.cs`, create a new proxy web application by calling `ElevenLabsProxyStartup.CreateWebApplication` method, passing your custom `AuthenticationFilter` as a type argument. 5. Create `ElevenLabsAuthentication` and `ElevenLabsClientSettings` as you would normally with your API keys, org id, or Azure settings. ```csharp @@ -156,7 +156,19 @@ public partial class Program { // You will need to implement your own class to properly test // custom issued tokens you've setup for your end users. - if (!request["xi-api-key"].ToString().Contains(userToken)) + if (!request["xi-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["xi-api-key"].ToString().Contains(TestUserToken)) { throw new AuthenticationException("User is not authorized"); } @@ -165,9 +177,9 @@ public partial class Program public static void Main(string[] args) { - var client = new ElevenLabsClient(); - var proxy = ElevenLabsProxyStartup.CreateDefaultHost(args, client); - proxy.Run(); + var auth = ElevenLabsAuthentication.LoadFromEnv(); + var client = new ElevenLabsClient(auth); + ElevenLabsProxyStartup.CreateWebApplication(args, client).Run(); } } ```