{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreieeospm75if4lykd4ejrzcdwptilddbiymwcsss2ges4rfj4newpm",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mpnyfkmmgyi2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreih7q3twflrplqagloofbpownoj44krotmsntpb57pxq3g7zscij3q"
    },
    "mimeType": "image/webp",
    "size": 59308
  },
  "path": "/mafzal88_dev_net/blazor-jwt-authentication-with-radzen-net-10-complete-starter-template-56mo",
  "publishedAt": "2026-07-02T11:27:34.000Z",
  "site": "https://dev.to",
  "tags": [
    "blazor",
    "authentication",
    "dotnet",
    "webdev",
    "https://localhost:5002",
    "https://github.com/mafzal88/BlazorJWTTokenStarter"
  ],
  "textContent": "Learn secure authentication in Blazor with this production-ready starter\ntemplate. JWT tokens, cookies, Radzen UI, and clean architecture explained.\n\n##  The Problem: Authentication is Complicated\n\nBuilding a secure Blazor application with authentication can be overwhelming:\n\n  * JWT vs Cookie authenticationβ€”which one?\n  * How do you handle token refresh?\n  * Where do you store secrets?\n  * How do you integrate Radzen components with auth?\n  * What's the best project structure?\n\n\n\n**This template answers all these questions in one place.**\n\n> **πŸ‘‰ Want to skip the setup?** Clone the repo and have authentication\n>  running in 5 minutes. No need to understand everything right now!\n\nIf you're looking for a quick-start template that demonstrates Blazor authentication with JWT tokens, Radzen components, and a clean .NET 10 architecture, this guide is for you.\n\nI've created a production-ready starter template that integrates all the best practices for authentication in Blazor applications. Let me walk you through it and show you how to use it to accelerate your projects.\n\n##  What is Blazor JWT Token Starter?\n\nBlazor JWT Token Starter is a comprehensive template demonstrating secure authentication in Blazor applications with a separation of concerns architecture. It combines:\n\n  * βœ… Blazor Server-side rendering with interactive components\n  * βœ… JWT Bearer authentication for secure API communication\n  * βœ… Cookie-based authentication for the Blazor app\n  * βœ… Radzen UI components for a professional, polished interface\n  * βœ… Clean architecture with Domain, Application, Infrastructure, and Shared layers\n  * βœ… .NET 10 with modern ASP.NET Core features\n\n\n\nWhether you're building an enterprise application or experimenting with secure authentication patterns, this template saves you hours of setup time.\n\n##  Repository Structure\n\nThe template follows a layered architecture pattern:\n\n`BlazorJWTTokenStarter/\nβ”œβ”€β”€ WebAPI/ # ASP.NET Core Web API (JWT Authentication)\nβ”œβ”€β”€ WebApp/ # Blazor Server Application (Cookie Auth)\nβ”œβ”€β”€ Domain/ # Domain entities and interfaces\nβ”œβ”€β”€ Application/ # Business logic and security services\nβ”œβ”€β”€ Infrastructure/ # Database and external dependencies\n└── Shared/ # Shared DTOs and utilities (45% C#, 31% HTML, 19% CSS, 5% JS)`\n\n##  Key Components\n\n  1. WebAPI Project - JWT Token Authority The API project is your authentication server. Key features:\n\n\n  * JWT Bearer Authentication: Configured in Program.cs with industry-standard token validation\n  * Token Settings: Secure key management through appsettings.json\n  * Authentication Controller: Issues tokens based on user credentials\n  * Scalar API Reference: Built-in interactive API documentation\n\n\n\n\n    // JWT configuration from Program.cs\n    builder.Services.AddAuthentication(options =>\n    {\n        options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;\n        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;\n    })\n    .AddJwtBearer(options =>\n    {\n        options.TokenValidationParameters = new TokenValidationParameters\n        {\n            ValidateIssuer = true,\n            ValidateAudience = true,\n            ValidateLifetime = true,\n            ValidateIssuerSigningKey = true,\n\n            ValidIssuer = jwtSettings.Issuer,\n            ValidAudience = jwtSettings.Audience,\n            IssuerSigningKey = new SymmetricSecurityKey(\n                Encoding.UTF8.GetBytes(jwtSettings.Key))\n        };\n    });\n\n\n  1. WebApp Project - Blazor Client Application The Blazor Server app handles user interactions with secure authentication:\n\n\n  * Cookie Authentication: Secure, server-side session management\n  * Login/Logout Endpoints: Minimal APIs for authentication flow\n  * Radzen Components: Beautiful, ready-to-use UI elements\n  * Current User Context: Service to access authenticated user information\n\n\n\n\n    // Cookie authentication setup\n    builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)\n        .AddCookie(options =>\n        {\n            options.LoginPath = \"/login\";\n            options.LogoutPath = \"/logout-user\";\n            options.Cookie.HttpOnly = true;\n            options.Cookie.SecurePolicy = CookieSecurePolicy.Always;\n            options.ExpireTimeSpan = TimeSpan.FromMinutes(30);\n            options.SlidingExpiration = true;\n        });\n\n\n  1. Domain Layer - Business Rules Contains core domain logic:\n\n\n  * User entities and constants\n  * Interface definitions for repositories\n  * Domain-specific business rules\n\n\n  1. Application Layer - Security & Services Handles authentication logic:\n\n\n  * JWT token generation and validation\n  * User authentication services\n  * Security configuration\n\n\n  1. Shared Layer - Common DTOs Reusable data transfer objects:\n\n\n  * ApiResponse.cs - Standardized API responses\n  * ResultDto.cs - Result types for operations\n  * LoginRequest - User login credentials\n\n\n\n##  Getting Started: Quick Setup Guide\n\nPrerequisites\n\n  * .NET 10 SDK or later\n  * Visual Studio 2022 or VS Code\n  * Basic knowledge of C# and Blazor\n\n\n\nStep 1: Clone the Repository\n\n\n\n    git clone https://github.com/mafzal88/BlazorJWTTokenStarter.git\n    cd BlazorJWTTokenStarter\n\n\nStep 2: Update Configuration\nEdit WebAPI/appsettings.json with your JWT settings:\n\n\n\n    {\n      \"JwtSettings\": {\n        \"Key\": \"your-secret-key-here-min-32-chars\",\n        \"Issuer\": \"YourAppName\",\n        \"Audience\": \"YourAppUsers\",\n        \"DurationInMinutes\": 60\n      },\n      \"ConnectionStrings\": {\n        \"DefaultConnection\": \"your-database-connection-string\"\n      }\n    }\n\n\nStep 3: Run the Applications\nTerminal 1 - Start WebAPI:\n\n\n\n    cd WebAPI\n    dotnet run\n    # Runs on https://localhost:5001\n    # Visit https://localhost:5001/scalar/v1 for API documentation\n\n\nTerminal 2 - Start WebApp:\n\n\n\n    cd WebApp\n    dotnet run\n    # Runs on https://localhost:5002\n\n\nStep 4: Test Authentication\n\n  * Navigate to https://localhost:5002\n  * Click \"Login\"\n  * Use your test credentials\n  * On success, you'll be authenticated and see the user dashboard\n\n\n\n##  Core Authentication Flow\n\n\n    User β†’ Blazor App (WebApp)\n      ↓\n    Login Form (Radzen Components)\n      ↓\n    POST /login-user (Minimal API)\n      ↓\n    Validate against WebAPI\n      ↓\n    Create Claims & Cookie\n      ↓\n    Redirect to Dashboard\n\n\n##  Why This Template is Powerful\n\n🎯 Production-Ready\nSecurity best practices implemented\nSecure cookie handling with HttpOnly and SameSite flags\nToken validation on every request\n30-minute sliding expiration with auto-refresh\n🧩 Modular Architecture\nClear separation of concerns\nEasy to extend with business logic\nTestable service layer\nReusable shared components\n🎨 UI/UX with Radzen\nProfessional-looking forms and components\nResponsive design out-of-the-box\nTheme support with cookie persistence\nCustom notification system\n⚑ Modern .NET Stack\n.NET 10 latest features\nMinimal APIs for lightweight endpoints\nBuilt-in OpenAPI/Swagger support\nAsync/await throughout\n\nFull code :\nhttps://github.com/mafzal88/BlazorJWTTokenStarter",
  "title": "Blazor JWT Authentication with Radzen & .NET 10: Complete Starter Template"
}