MudraX.Blazor.Jwt.Maui 9.0.0.5

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

MudraX.Blazor.Jwt.Maui

MudraX.Blazor.Jwt.Maui is a robust library designed to integrate XAF Web API authentication seamlessly into Blazor and .NET MAUI applications. Built with .NET 9, this library is optimized for modern cross-platform development, enabling developers to implement secure and scalable authentication solutions with ease.

Upgrade your project to .NET 9.*

<PackageReference Include="Microsoft.Maui.Controls" Version="9.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.*" />

XAF Web API service - Startup.cs

options.BusinessObject<ApplicationUser>();

Installation

To install the library, use the following NuGet command:

Install-Package MudraX.Blazor.Jwt.Maui

For Android Emulator in Debug Mode

HttpMessageHandler.cs

Add the HttpMessageHandler.cs class to your project:

public static partial class HttpMessageHandler
{
    static readonly System.Net.Http.HttpMessageHandler PlatformHttpMessageHandler;
    public static System.Net.Http.HttpMessageHandler GetMessageHandler() => PlatformHttpMessageHandler;
}

AndroidHttpMessageHandler.cs

Add the AndroidHttpMessageHandler.cs class to Platforms\Android :

using Your_Maui_project_namespace.Platforms.Android;

namespace Your_Maui_project_namespace.Platforms.Android
{
    class AndroidMessageHandler : Xamarin.Android.Net.AndroidMessageHandler
    {
        public AndroidMessageHandler()
           => ServerCertificateCustomValidationCallback = (_, cert, _, errors)
              => cert is { Issuer: "CN=localhost" } || errors == System.Net.Security.SslPolicyErrors.None;

        protected override Javax.Net.Ssl.IHostnameVerifier GetSSLHostnameVerifier(Javax.Net.Ssl.HttpsURLConnection connection)
           => new HostnameVerifier();

        private sealed class HostnameVerifier : Java.Lang.Object, Javax.Net.Ssl.IHostnameVerifier
        {
#pragma warning disable CS8767
            public bool Verify(string hostname, Javax.Net.Ssl.ISSLSession session)
#pragma warning restore CS8767
               => Javax.Net.Ssl.HttpsURLConnection.DefaultHostnameVerifier!.Verify(hostname, session) ||
               hostname == "10.0.2.2" && session.PeerPrincipal?.Name == "CN=localhost";
        }
    }
}
namespace Your_Maui_project_namespace
{
    public static partial class HttpMessageHandler
    {
        static HttpMessageHandler() => PlatformHttpMessageHandler = new AndroidMessageHandler();
    }
}

MauiProgram.cs

builder.Services.AddMudraBlazorServices(supportedCultures: ["en-US", "zh-TW"]);
//Dependency Injection JwtIdentityService
#if ANDROID && DEBUG
    builder.Services.AddJwtTokenAuthentication(options =>
    {
        options.AuthenticateAddress = $"https://10.0.2.2:5001/api/Authentication/Authenticate";
        options.BaseAddress = $"https://10.0.2.2:5001/api";
        options.ODataAddress = $"https://10.0.2.2:5001/api/odata";
        options.JwtSecret = "<API_SERVER_KEY>";
        options.Issuer = "<ISSUER>";
        options.TokenKeyName = "MyToken";
        options.ExpiresIn = 60;
        options.HttpClientMessageHandler = HttpMessageHandler.GetMessageHandler();
    });
#else
    builder.Services.AddJwtTokenAuthentication(options =>
    {
        options.AuthenticateAddress = $"https://localhost:5003/api/Authentication/Authenticate";
        options.BaseAddress = $"https://localhost:5001/api";
        options.ODataAddress = $"https://localhost:5001/api/odata";
        options.JwtSecret = "<API_SERVER_KEY>";
        options.Issuer = "<ISSUER>";
        options.TokenKeyName = "MyToken";
        options.ExpiresIn = 60;
    });
#endif

    builder.Services.AddMudraBlazorServices(supportedCultures: ["en-US", "zh-TW"]);

_Imports.razor

@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization

@using System.Globalization
@using Microsoft.Extensions.Localization

@using MudBlazor
@using MudBlazor.Services
@using MudExtensions

@using MudraX.Blazor.Core.Services

@using MudraX.Blazor.Maui
@using MudraX.Blazor.Maui.Components
@using MudraX.Blazor.Maui.Components.Layout
@using MudraX.Blazor.Maui.Services

@using MudraX.Blazor.Jwt.Maui.Components.Layout

MainLayout.razor

Add AppUserMenu to MainLayout.razor

@inherits LayoutComponentBase
@attribute [Authorize]

<ApplicationLayout>
    <ApplcationBar>

        <AppUserMenu />

    </ApplcationBar>

    <DrawerMenu>

    </DrawerMenu>

    <Body>
        @Body
    </Body>
</ApplicationLayout>

Routes.razor

Add the following route to your Routes.razor file:

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(MauiProgram).Assembly"
            AdditionalAssemblies="new[] { typeof(AppUserMenu).Assembly }">
        <Found Context="routeData">

            <CascadingValue Value="routeData">
                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
                    <Authorizing>
                        <p>Determining session state, please wait...</p>
                    </Authorizing>
                    <NotAuthorized>
                        <MudraX.Blazor.Jwt.Maui.Pages.Login />
                    </NotAuthorized>
                </AuthorizeRouteView>
            </CascadingValue>
            <FocusOnNavigate RouteData="routeData" Selector="h1" />

        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(Layout.MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

wwwroot/index.html

Add the following script to your index.html file:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<link href="_content/CodeBeam.MudBlazor.Extensions/MudExtensions.min.css" rel="stylesheet" />

...

<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="_content/CodeBeam.MudBlazor.Extensions/MudExtensions.min.js"></script>

Contributing

Contributions are welcome! To get started:

  1. Fork the repository and create a new branch for your feature or bug fix.
  2. Follow the contribution guidelines for detailed instructions.
  3. Submit a pull request with a clear description of your changes.

For any questions or discussions, feel free to open an issue or join our community forums.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
9.0.0.5 305 11/13/2025
9.0.0.4 204 10/14/2025
9.0.0.3 207 9/10/2025
9.0.0.2 217 5/7/2025
9.0.0.1 202 5/6/2025