MasterBlazor.AspNetCore.Authentication.PingFederate 1.0.1

dotnet add package MasterBlazor.AspNetCore.Authentication.PingFederate --version 1.0.1                
NuGet\Install-Package MasterBlazor.AspNetCore.Authentication.PingFederate -Version 1.0.1                
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="MasterBlazor.AspNetCore.Authentication.PingFederate" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MasterBlazor.AspNetCore.Authentication.PingFederate --version 1.0.1                
#r "nuget: MasterBlazor.AspNetCore.Authentication.PingFederate, 1.0.1"                
#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.
// Install MasterBlazor.AspNetCore.Authentication.PingFederate as a Cake Addin
#addin nuget:?package=MasterBlazor.AspNetCore.Authentication.PingFederate&version=1.0.1

// Install MasterBlazor.AspNetCore.Authentication.PingFederate as a Cake Tool
#tool nuget:?package=MasterBlazor.AspNetCore.Authentication.PingFederate&version=1.0.1                

The project is for ASP.NET applications, Web API's, and Blazors app that can use authentication provider as ADFS WS-Federation and working with PingFederate authentication provider servers.

This project is a Nuget can use directly in ASP.NET application and will list the step how to add authentication to the Blazor Wasm with Server Hosted.

First, You need to know all the information that is related with PingFederate server and how to interact with your ASP.NET application,

Ask the administrator for the following:

1- Create domain (urn) for your web site inside the PingFederate server, like if you need to connect your website https://yourweb.company.com then you need to get an Idp like urn:yourweb:company:com, this will be considered as realm for your application PingFederate Idp (I'll explain later).

2- Ask for the full path to the authentication provider url, it will be like "https://company.com:[port]/idp/prp.wsf" the default port is 9031 but you need to know that from your Authentication Provider admin more information

3- Need to create high trust certificate Second, Create a Blazor Wasm project, and in the Server part of the project add the following:

Server Project:

  • Add MasterBlazor.AspNetCore.Authentication Nuget

  • Open the Server.csproj file, Add the following:

<ItemGroup>
	<Folder Include="Controllers\" />
</ItemGroup>
  • appsetting.json

//after "AllowedHosts": "*" add the PingFederate information:

  "issuer": "https://[YOUR_COMPANY_AUTH_SERVER]:[port]/idp/prp.wsf",
  "validIssuer": "urn:[your_company_domain]:[com or net]",
  "metadataAddress": "https://[YOUR_COMPANY_AUTH_SERVER]:[port]/[folder]/metadata.xml",
  "realm": "urn:[your_host_site]:[maybe sub domain]:[com or net or ...]",
  "certificatePath": "[local path]\\[certificate name].cer",
  "validAudience": "urn:[your_host_site]:[maybe sub domain]:[com or net or ...]"

an example to these information is:

  "issuer": "https://company.net:9031/idp/prp.wsf",
  "validIssuer": "urn:company:net",
  "metadataAddress": "https://ping.company.net:9031/files/metadata.xml",
  "realm": "urn:yourweb:company:com",
  "certificatePath": "C:\\my certificate folder\\mystrusted.cer",
  "validAudience": "urn:yourweb:company:com"
  • Open the Program.cs:
// Add services to the container.
MasterBlazor.Authentication.Authentication.Auth(builder.Services, new MasterBlazor.Authentication.AuthenticationOption
{
    Issuer = builder.Configuration.GetValue<string>("issuer"),
    ValidIssuer = builder.Configuration.GetValue<string>("validIssuer"),
    Wtrealm = builder.Configuration.GetValue<string>("realm"),
    ValidAudience = builder.Configuration.GetValue<string>("validAudience"),
    MetadataAddress = builder.Configuration.GetValue<string>("metadataAddress"),
    CertificatePath = builder.Configuration.GetValue<string>("certificatePath")
});
  • Add the 2 lines as well:
//Add after routing
app.UseAuthentication();
app.UseAuthorization();

Client Project:

  • Add the folder "Authentication" to the project

  • Add UserState.razor page to the that folder


@inject HttpClient Http

<div style="float:right;" class="userState">
    <ul class="nav">
        @if (isAuthenticated)
        {
            <li class="nav-link">
                <div class="loginuser" upn="@userName">@userName</div>
            </li>
            <li class="nav-link">
                <a href="/Account/SignOut" id="loginLink">Sign out</a>
            </li>
        }
        else
        {
            <li class="nav-link">
                <a href="/Account/SignIn" id="loginLink">Sign in</a>
            </li>
        }
    </ul>
</div>

and this is code part:

@code {

    private bool isAuthenticated = false;
    private string userName{get;set;}

    protected override async Task OnInitializedAsync()
    {
        userName="";
        var ret = await Http.GetStringAsync("Account/IsAuthenticated");
        if (ret != "")
        {
            isAuthenticated = true;
            userName = ret;
        }
        else
            isAuthenticated = false;
    }
}



Add <UserStatus /> to the layout page

<MasterBlazor.App.Client.Authentication.UserState/>

When signout it will return to the home page, but in case a special page requires just add another .razor inside the "Authenticaion" folder:

Signout.razor:

@page "/signout"
<h2><a href="/">Home</a></h2>
<h3>You are signed out successfully.</h3>

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MasterBlazor.AspNetCore.Authentication.PingFederate:

Package Downloads
MasterBlazor.AspNetCore.Authentication

ADFS WS-Federation SSO

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 348 12/13/2022
1.0.0 363 12/11/2022