FusionAuth C# Client

C# Client Library

The C# client library allows you to integrate FusionAuth with your C# application.

Source Code:

NuGet Package:

To install the FusionAuth C# Client from NuGet run:

PM> Install-Package FusionAuth.Client

The following code assumes FusionAuth is running on http://localhost:9011 and uses an API key 6b87a398-39f2-4692-927b-13188a81a9a3, you will need to supply your own API key, and if you are not running FusionAuth locally, your host parameter may be different.

Here is an example of using the RetrieveUserByEmail method to retrieve a User by an email address.

using FusionAuth;
using FusionAuth.Domain;

namespace Example
{
    public class Example
    {
        private readonly string apiKey = "6b87a398-39f2-4692-927b-13188a81a9a3";

        private readonly string fusionauthURL = "http://localhost:9011";

        private readonly FusionAuthClient client;

        public Example(string apiKey, string fusionauthURL)
        {
            client = new FusionAuthClient(apiKey, fusionauthURL);
        }

        public User GetUserByEmail(string email)
        {
            var response = client.RetrieveUserByEmail("user@example.com");
            if (response.WasSuccessful())
            {
                var user = response.successResponse.user;
                return user;
            }
            else if (response.errorResponse != null)
            {
                // Error Handling
                var errors = response.errorResponse;
                return null;
            }
            else if (response.exception != null)
            {
                // Exception Handling
                var exception = response.exception;
                return null;
            }

            return null;
        }
    }
}