.NET SDK

Coming Soon

Official OAuth42 SDK for .NET. Works with ASP.NET Core, Blazor, and any .NET application.

Installation

Install via NuGet Package Manager:

dotnet add package OAuth42.Client

Or via Package Manager Console:

Install-Package OAuth42.Client

Quick Start

using OAuth42.Client;

var client = new OAuth42Client(new OAuth42Config
{
    ClientId = Environment.GetEnvironmentVariable("OAUTH42_CLIENT_ID"),
    ClientSecret = Environment.GetEnvironmentVariable("OAUTH42_CLIENT_SECRET"),
    RedirectUri = "https://yourapp.com/callback"
});

// Start authorization
var authData = await client.AuthorizeAsync(new AuthorizeParams
{
    Scope = new[] { "openid", "profile", "email" }
});

// Exchange code for tokens
var tokens = await client.ExchangeCodeAsync(new ExchangeParams
{
    Code = code,
    CodeVerifier = codeVerifier
});

ASP.NET Core Integration

using Microsoft.AspNetCore.Mvc;
using OAuth42.Client;

public class AuthController : Controller
{
    private readonly OAuth42Client _oauth42Client;

    public AuthController(OAuth42Client oauth42Client)
    {
        _oauth42Client = oauth42Client;
    }

    public async Task<IActionResult> Login()
    {
        var authData = await _oauth42Client.AuthorizeAsync(new AuthorizeParams
        {
            Scope = new[] { "openid", "profile", "email" }
        });

        HttpContext.Session.SetString("code_verifier", authData.CodeVerifier);
        HttpContext.Session.SetString("state", authData.State);

        return Redirect(authData.Url);
    }

    public async Task<IActionResult> Callback(string code, string state)
    {
        var storedState = HttpContext.Session.GetString("state");
        if (state != storedState)
        {
            return BadRequest("Invalid state");
        }

        var tokens = await _oauth42Client.ExchangeCodeAsync(new ExchangeParams
        {
            Code = code,
            CodeVerifier = HttpContext.Session.GetString("code_verifier")
        });

        HttpContext.Session.SetString("access_token", tokens.AccessToken);
        return RedirectToAction("Dashboard");
    }
}

Best Practices

Use Dependency Injection

Register OAuth42Client in ConfigureServices for lifetime management.

Use Configuration

Store credentials in appsettings.json or environment variables.

Next Steps