### Add DuoUniversal NuGet Package Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/README.md Install the DuoUniversal NuGet package to your .NET project. Ensure you specify the desired version. ```bash dotnet add package DuoUniversal --version 1.3.1 ``` -------------------------------- ### Run with .NET CLI (netcoreapp3.1) Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/DuoUniversal.Example/README.md Command to run the C# sample application using the .NET Command Line Interface, targeting the .NET Core 3.1 framework. Ensure you are in the DuoUniversal.Example base directory. ```bash dotnet run --framework netcoreapp3.1 ``` -------------------------------- ### Run with .NET CLI (net6.0) Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/DuoUniversal.Example/README.md Command to run the C# sample application using the .NET Command Line Interface, targeting the .NET 6.0 framework. Ensure you are in the DuoUniversal.Example base directory. ```bash dotnet run --framework net6.0 ``` -------------------------------- ### Build Project with .NET CLI Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/README.md Compile the project assemblies using the .NET CLI. This command is run from the root directory of the project. ```bash dotnet build ``` -------------------------------- ### Run Tests with .NET CLI Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/README.md Execute project tests using the .NET CLI. This requires .NET Core 6.0 and should be run from the root directory. ```bash dotnet test ``` -------------------------------- ### Verify Code Format with .NET CLI Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/README.md Check the code's formatting against project standards without making changes. This command ensures code consistency. ```bash dotnet format --verify-no-changes ``` -------------------------------- ### Synchronous Wrapper for Async Call (Task.Run) Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/DuoUniversal.Example/README.md This approach wraps an asynchronous Duo client call within Task.Run to be used in a synchronous ASP.NET web application context. It's a reported working solution by users. ```csharp var token = Task.Run(async () => { return await duoClient.ExchangeAuthorizationCodeFor2faResult(context.Request["code"], username); }).Result; ``` -------------------------------- ### Synchronous Wrapper for Async Call (GetAwaiter().GetResult()) Source: https://github.com/duosecurity/duo_universal_csharp/blob/main/DuoUniversal.Example/README.md This method uses GetAwaiter().GetResult() to synchronously execute an asynchronous Duo client method. This approach has been used internally by Duo for their products. ```csharp var _idToken = duoClient.ExchangeAuthorizationCodeFor2faResult(duoCode, username).GetAwaiter().GetResult(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.