PrimusSaaS.Identity.Validator 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PrimusSaaS.Identity.Validator --version 1.0.0
                    
NuGet\Install-Package PrimusSaaS.Identity.Validator -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="PrimusSaaS.Identity.Validator" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PrimusSaaS.Identity.Validator" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PrimusSaaS.Identity.Validator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PrimusSaaS.Identity.Validator --version 1.0.0
                    
#r "nuget: PrimusSaaS.Identity.Validator, 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.
#:package PrimusSaaS.Identity.Validator@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PrimusSaaS.Identity.Validator&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PrimusSaaS.Identity.Validator&version=1.0.0
                    
Install as a Cake Tool

Primus SaaS Identity Validator - .NET SDK

Official .NET SDK for validating JWT tokens issued by the Primus SaaS Portal. This package provides middleware and extensions for ASP.NET Core applications to easily authenticate users.

Installation

dotnet add package PrimusSaaS.Identity.Validator

Or via NuGet Package Manager:

Install-Package PrimusSaaS.Identity.Validator

Quick Start

1. Configure in Program.cs or Startup.cs

using PrimusSaaS.Identity.Validator;

var builder = WebApplication.CreateBuilder(args);

// Add Primus Identity validation
builder.Services.AddPrimusIdentity(options =>
{
    options.PortalUrl = "https://portal.primus-saas.com";
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.JwtSecret = "your-jwt-secret-key";
    
    // Optional: Configure additional settings
    options.ValidateLifetime = true;
    options.RequireHttpsMetadata = true; // Set false for development
    options.ClockSkew = TimeSpan.FromMinutes(5);
});

// Add authorization
builder.Services.AddAuthorization();

var app = builder.Build();

// Enable authentication & authorization middleware
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.Run();

2. Protect Your API Endpoints

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PrimusSaaS.Identity.Validator;

[ApiController]
[Route("api/[controller]")]
public class SecureController : ControllerBase
{
    [HttpGet]
    [Authorize] // Requires valid Primus SaaS JWT token
    public IActionResult GetSecureData()
    {
        // Get the authenticated Primus user
        var primusUser = HttpContext.GetPrimusUser();
        
        return Ok(new
        {
            message = "Secure data accessed successfully",
            user = new
            {
                userId = primusUser?.UserId,
                email = primusUser?.Email,
                name = primusUser?.Name,
                roles = primusUser?.Roles
            }
        });
    }

    [HttpGet("admin")]
    [Authorize(Roles = "Admin")] // Requires Admin role
    public IActionResult GetAdminData()
    {
        return Ok(new { message = "Admin-only data" });
    }
}

3. Access User Information

// In any controller or middleware
var primusUser = HttpContext.GetPrimusUser();

if (primusUser != null)
{
    Console.WriteLine($"User ID: {primusUser.UserId}");
    Console.WriteLine($"Email: {primusUser.Email}");
    Console.WriteLine($"Name: {primusUser.Name}");
    Console.WriteLine($"Roles: {string.Join(", ", primusUser.Roles)}");
    
    // Access additional claims
    foreach (var claim in primusUser.AdditionalClaims)
    {
        Console.WriteLine($"{claim.Key}: {claim.Value}");
    }
}

Configuration Options

Option Required Description Default
PortalUrl Yes Base URL of Primus SaaS Portal -
ClientId Yes Your application's Client ID -
ClientSecret Yes Your application's Client Secret -
JwtSecret Yes JWT secret key from portal -
Issuer No Expected token issuer PortalUrl
Audience No Expected token audience ClientId
ValidateLifetime No Validate token expiration true
RequireHttpsMetadata No Require HTTPS for metadata true
ClockSkew No Allowed time difference 5 minutes

Configuration from appsettings.json

{
  "PrimusIdentity": {
    "PortalUrl": "https://portal.primus-saas.com",
    "ClientId": "your-client-id",
    "ClientSecret": "your-client-secret",
    "JwtSecret": "your-jwt-secret-key",
    "RequireHttpsMetadata": false
  }
}
builder.Services.AddPrimusIdentity(options =>
{
    builder.Configuration.GetSection("PrimusIdentity").Bind(options);
});

Client Usage Example

To call your protected API from a client application:

using System.Net.Http.Headers;

var httpClient = new HttpClient();
var jwtToken = "your-jwt-token-from-primus-portal";

// Add token to Authorization header
httpClient.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", jwtToken);

var response = await httpClient.GetAsync("https://your-api.com/api/secure");
var data = await response.Content.ReadAsStringAsync();

Development Tips

Disable HTTPS Requirement for Local Development

builder.Services.AddPrimusIdentity(options =>
{
    options.PortalUrl = "http://localhost:5000";
    options.RequireHttpsMetadata = false; // Allow HTTP in development
    // ... other options
});

Enable Detailed Logging

The SDK automatically logs authentication events to the console. For more detailed logging, enable ASP.NET Core logging:

{
  "Logging": {
    "LogLevel": {
      "Microsoft.AspNetCore.Authentication": "Debug"
    }
  }
}

Requirements

  • .NET 7.0 or later
  • ASP.NET Core 7.0 or later

Support

For issues, questions, or contributions, visit:

License

MIT License - see LICENSE file for details

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
2.0.1 95 4/19/2026
2.0.0 321 1/12/2026
1.5.0 863 12/3/2025
1.3.6 286 11/30/2025
1.3.5 271 11/30/2025
1.3.3 283 11/29/2025
1.3.2 141 11/29/2025
1.3.1 150 11/28/2025
1.3.0 217 11/24/2025
1.2.3 210 11/24/2025
1.2.2 209 11/24/2025
1.2.1 205 11/24/2025
1.2.0 200 11/23/2025
1.1.0 168 11/23/2025
1.0.0 324 11/21/2025