Egov.Integrations.MPass.Saml 8.0.56

dotnet add package Egov.Integrations.MPass.Saml --version 8.0.56
                    
NuGet\Install-Package Egov.Integrations.MPass.Saml -Version 8.0.56
                    
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="Egov.Integrations.MPass.Saml" Version="8.0.56" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Egov.Integrations.MPass.Saml" Version="8.0.56" />
                    
Directory.Packages.props
<PackageReference Include="Egov.Integrations.MPass.Saml" />
                    
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 Egov.Integrations.MPass.Saml --version 8.0.56
                    
#r "nuget: Egov.Integrations.MPass.Saml, 8.0.56"
                    
#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 Egov.Integrations.MPass.Saml@8.0.56
                    
#: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=Egov.Integrations.MPass.Saml&version=8.0.56
                    
Install as a Cake Addin
#tool nuget:?package=Egov.Integrations.MPass.Saml&version=8.0.56
                    
Install as a Cake Tool

MPass SAML Authentication

This package is intended for Service Provider integration built on ASP.NET Core 8.0+ with MPass using SAML v2.0 protocol for authentication.

Getting Started

Please go through the following instructions to integrate your project with MPass.

Prerequisites

Before being able to integrate with MPass, a Service Provider, including its certificate, must be registered accordingly in MPass. MPass accepts certificates issued by STISC.

Installing

Install the following package from NuGet

Install-Package Egov.Integrations.MPass.Saml

Note: This package is dependent on Egov.Extensions.Configuration.

Then follow the instructions from Configuration and Usage sections below.

Configuration

Add the following configuration section to your appsettings.json:

{
   ...
    "Certificate": {
      "Path": "Files\\Certificates\\yourcertificate.pfx",
      "Password": "yourcertificatepassword"
   }
   ...
   "MPassSaml": {
      "SamlRequestIssuer": "https://sampleservice.md",
      "IdentityProviderCertificatePath": "Files\\Certificates\\idp.cer",
      "SamlMessageTimeout": "00:10:00",
      "SamlLoginDestination": "https://mpass.staging.egov.md/login/saml",
      "SamlLogoutDestination": "https://mpass.staging.egov.md/logout/saml",
      "ServiceRootUrl": "https://localhost:44379"
   }
   ...
}

where ServiceRootUrl is the base path of your published service.

Please note that your Service must be published using https protocol.

Usage

Add the following code snippet to your Startup.ConfigureServices method:

builder.Services.AddSystemCertificate(builder.Configuration.GetSection("Certificate"));

services.AddAuthentication(sharedOptions =>
{
    sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    sharedOptions.DefaultChallengeScheme = MPassSamlDefaults.AuthenticationScheme;
})
.AddCookie()
.AddMPassSaml(builder.Configuration.GetSection("MPassSaml"));

In your Startup.Configure add the Authentication Middleware.

app.UseAuthentication();

This package allows you to enable default endpoints mapper, so you don't have to implement login, logout, and user-details endpoints manually.

app.MapMPassSaml();

MapMPassSaml - registers 3 endpoints in your application under the /account path:

  • /account/login - Initiates SAML authentication with MPass. Accepts optional query parameters:
    • returnUrl - URL to redirect after successful authentication (defaults to /)
    • passive - Set to true for passive authentication (defaults to false)
    • lang - Language preference (ro, ru, or en)
  • /account/logout - Handles logout from both local and remote sessions. Accepts optional query parameter:
    • returnUrl - URL to redirect after logout (defaults to /)
  • /account/me - Returns the current user's claims as JSON. Returns 204 No Content if the user is not authenticated.

Authentication is started automatically if you are not already authenticated with code →


    // DefaultAuthenticateScheme causes User to be set
    var user = context.User;

    // Not authenticated
    if (user == null || !user.Identities.Any(identity => identity.IsAuthenticated))
    {
        // This is what [Authorize] calls
        await context.ChallengeAsync();

        return;
    }

LogOut is initiated then Sign Out and Sign Out Remote buttons are pressed.
For local logout is used next part of code.


    if (context.Request.Path.Equals("/signout"))
    {
        await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
        await WriteHtmlAsync(context.Response, async res =>
        {
            await context.Response.WriteAsync($"<h1>Signed out {HtmlEncode(context.User.Identity.Name)}</h1>");
            await context.Response.WriteAsync("<a class=\"btn btn-link\" href=\"/\">Sign In</a>");
        });
        return;
    }

For remote logout is used next part of code.


    if (context.Request.Path.Equals("/signout-remote"))
    {
        if (context.User.Identity.IsAuthenticated)
        {
            // Redirects
            await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
            await context.SignOutAsync(MPassSamlDefaults.AuthenticationScheme,
                new AuthenticationProperties()
                {
                    RedirectUri = "/signedout"
                });
            return;
        }
        else
        {
            await WriteHtmlAsync(context.Response, async res =>
            {
                await context.Response.WriteAsync($"<h1>Signed out {HtmlEncode(context.User.Identity.Name)}</h1>");
                await context.Response.WriteAsync("<a class=\"btn btn-link\" href=\"/\">Sign In</a>");
            });
            return;
        }

    }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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
8.0.56 129 12/12/2025
8.0.55 118 12/11/2025
8.0.54 111 12/11/2025
8.0.53 121 12/11/2025