License Registration
Overview
When you buy a commercial version of JSPrintManager for Blazor you are provided with license information to register the product in your website. The license information you've received includes three values: the License Owner, the License Key and the License Token.
- License Owner and License Key are used to compute the license response for every validation request.
- License Token is a digitally signed proof of your license, issued by Neodynamic. It's returned as-is together with the license response and it's validated by JSPrintManager App version 9.0.26.1005 and later.
Note
If your license info does not include a License Token, you can still register the product with the License Owner and License Key only. Please contact our Support Team to get your License Token; future major versions of JSPrintManager App will require it.
There are three ways to setup the license info. License registration requires coding a .NET Controller so refer to Option ❶ or Option ❷ below. In case you cannot use a Controller, then please refer to Option ❸.
Important
Whatever option you choose, we strongly recommend protecting the license controller so that only your own app and users can get your license info.
❶ License Setting On Website
This license setting option is done on the same website that is using the JSPrintManager Razor Component (Neodynamic.Blazor.JSPrintManager.dll) file. To register JSPrintManager in your Blazor project, you must code a .NET Controller so the license information is returned by this URL: //ORIGIN/jspm where ORIGIN is the one displayed by localhost's origin entry for your website. Here's a sample from our online demo website:

In this case, the license info must be configured under https://jspmblazorserver.azurewebsites.net/jspm
Note
Alternatively you could specify a different path to provide the license info but it must be located under the same ORIGIN. For example, based on the website sample, if we decided to return the license info from https://jspmblazorserver.azurewebsites.net/licenses/jsprintmanager, then we must specify it in the JSPrintManager Start method as follows
JSPrintManager.Start("https://jspmblazorserver.azurewebsites.net/licenses/jsprintmanager");
❷ License Setting On an external server/URL
This license setting option is done outside the boundary of the Blazor app using the Neodynamic.Blazor.JSPrintManager.dll file. License registration requires coding a .NET Controller so if the website that is using the Neodynamic.Blazor.JSPrintManager.dll file does not allow you to write a Controller, then this option allows you to setup the license info on an external URL.
Important
This option requires a special License Owner format where the ORIGIN/DOMAIN (as described above and shown in the sample figure) of the printing website must be specified. You must request this type of license to our sales team after placing an order by specifying the ORIGIN value in your case. The URL from where the license info must be returned must be specified in the JSPrintManager Start method as shown in the following snipped code:
JSPrintManager.Start("https://external-server/whatever/get-jspm-license");
The specified licenseUrl must resolve to a .NET Controller.
❸ License Setting On Neodynamic server
If you cannot use a .NET Controller in your website and you cannot create another website to return the license info, then Neodynamic offers you to host your license info at https://neodynamic.com which runs on MS Azure data centers at no extra costs. If this is an option for you, then please contact our Support Team
How license validation works
When your Blazor app connects to JSPrintManager App, the app sends a request to your license controller (//ORIGIN/jspm or the licenseUrl specified in JSPrintManager.Start()) with these query string parameters:
| Parameter | Description |
|---|---|
timestamp |
A value that changes on every request. Your controller uses it to compute the license response. |
origin |
The origin of the page that is using JSPrintManager, e.g. https://app.yourcompany.com (JSPrintManager App 9.0.26.1005 and later). |
lv |
The license protocol version (JSPrintManager App 9.0.26.1005 and later). |
Your controller answers with the license info generated by Neodynamic.Blazor.JSPrintManager.GenerateLicense() in the response body, plus the following response headers (JSPrintManager App 9.0.26.1005 and later; older versions just ignore them):
| Response header | Description |
|---|---|
X-JSPM-License-Token |
Your License Token, as provided by Neodynamic. |
X-JSPM-License-TTL |
Number of seconds each JSPrintManager App may reuse a successful validation before asking your controller again. Allowed range: 300 (5 minutes) to 2592000 (30 days). If not specified, 30 days is used. |
X-JSPM-License-Grace |
Number of extra seconds a validation may still be used, once expired, if your controller cannot be reached (server down, network issues, etc.). Allowed range: 0 to 2592000 (30 days). If not specified, 0 (no offline tolerance) is used. |
The code below uses a TTL of 1 day and a grace period of 3 days. Adjust them to your needs:
- A shorter TTL means that changes on your side (e.g. stopping to serve the license to some origin or user) take effect sooner, at the cost of more requests to your controller.
- A longer grace period keeps your users printing during an outage of your controller; a grace period of 0 means users can't print as soon as the TTL expires and your controller is unreachable.
Important
To deny a request on purpose (e.g. an unauthorized caller), answer with HTTP status 200 and any text that is not a valid license (e.g. denied), as shown in Protecting the license controller. Any other status code (401, 403, 500, etc.) is treated as "controller unreachable", so a previously cached validation would still be honored during the grace period. That's why the license controller must not use the [Authorize] attribute: do the check inside the action instead.
Note
Make sure your controller response is never cached by proxies or CDNs (the code below sends Cache-Control: no-store). A cached response contains an old value and will fail validation.
Registering the License Info
Serving the license from your own Blazor project
Please do the following in the Blazor project where you'll be registering JSPrintManager:
Important
The following approach will work for Blazor Web App, Blazor Server and Blazor WebAssembly Hosted under ASP.NET Core projects. For Blazor WebAssembly Standalone apps, then refer to Option ❷ or Option ❸ described above.
Enable MVC controllers in your project:
- For .NET 6 and later (minimal hosting model), edit the Program.cs file and add these lines:
builder.Services.AddControllers(); // Needed for JSPrintManager licensing
var app = builder.Build();
//...
app.MapDefaultControllerRoute(); // Needed for JSPrintManager licensing
- For projects with a Startup.cs file, add
services.AddControllers();in the ConfigureServices method and the following in the Configure method:
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute(); // Needed for JSPrintManager licensing
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
Create a new Controller and name it JSPMController; or edit the file that will be pointed by the
licenseUrl(read about this param above)Then copy/paste the following code and specify the License Owner, License Key & License Token values you have received (if you don't have a License Token yet, leave it empty):
[Route("jspm")]
public class JSPMController : Controller
{
[AllowAnonymous]
public IActionResult Index(string timestamp)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
Response.Headers["Cache-Control"] = "no-store";
Response.Headers["X-JSPM-License-Token"] = license_token;
Response.Headers["X-JSPM-License-TTL"] = license_ttl.ToString();
Response.Headers["X-JSPM-License-Grace"] = license_grace.ToString();
return File(Neodynamic.Blazor.JSPrintManager.GenerateLicense(license_owner, license_key, timestamp), "text/plain");
}
}
Tip
Upgrading an existing license controller? Just add the License Token, TTL and grace period settings and the four Response.Headers lines. The response body does not change, so all JSPrintManager App versions keep working.
- That's it! Try running your app, when trying to print, the eval dialog should not be displayed to the user.
Serving the license from an Azure Function (C#)
Important
This option requires a special License Owner format where the ORIGIN/DOMAIN (as described above and shown in the sample figure) of the printing website must be specified. You must request this type of license to our sales team after placing an order by specifying the ORIGIN value in your case.
Create a new Azure Function (Http Trigger) and name it JSPMLic
Then copy/paste the following code:
public class JSPMLic
{
private readonly ILogger _logger;
public JSPMLic(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<JSPMLic>();
}
[Function("JSPMLic")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//OPTIONAL: authorize the request here (see "Protecting the license controller")
//DO NOT MODIFY THE FOLLOWING CODE
var queryCollection = HttpUtility.ParseQueryString(req.Url.Query);
string timestamp = queryCollection["timestamp"];
var licenseContent = Neodynamic.Blazor.JSPrintManager.GenerateLicense(license_owner, license_key, timestamp);
string licenseText = System.Text.Encoding.UTF8.GetString(licenseContent);
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.Headers.Add("Cache-Control", "no-store");
response.Headers.Add("X-JSPM-License-Token", license_token);
response.Headers.Add("X-JSPM-License-TTL", license_ttl.ToString());
response.Headers.Add("X-JSPM-License-Grace", license_grace.ToString());
response.WriteString(licenseText);
return response;
}
}
Then specify your Azure Function to the following call (change the URL based on your own value):
JSPrintManager.Start("https://azure-function-domain/api/JSPMLic");
- That's it! Try running your app, when trying to print, the eval dialog should not be displayed to the user.
Protecting the license controller
If your license controller allows anonymous access, anyone who knows its URL can request your license info. For licenses restricted to your website ORIGIN/DOMAIN the impact is limited, but for Unlimited WebApp/WebServer licenses and for licenses restricted to machine names, an unprotected controller could let third parties use your license. That's why we strongly recommend protecting it with one or more of the following options.
Authorization header
The license controller can be protected from unauthorized requests through any HTTP Authorization Header protection options. The Authorization header content must be specified through the licenseAuthorizationHeader param of the JSPrintManager.Start() method. For instance, you could use JSON Web Tokens (JWT) and set it as follows:
// Set the JSON Web Token (JWT) ... REPLACE <token> with the real value!!!
var licenseAuthorizationHeader = "Bearer <token>";
// Start WebSocket comm
JSPrintManager.Start("LIC_URL", 29443, "127.0.0.1", true, licenseAuthorizationHeader);
//... more code...
Tip
The Authorization header value reaches the user's browser, so a fixed password or token hardcoded in your app does not protect the controller: anyone using your app could read it. The recommended approach is to issue a short-lived value per signed-in user, as shown next.
Recommended: per-user, time-limited value with ASP.NET Core Data Protection
ASP.NET Core includes everything needed to issue and validate short-lived, tamper-proof values, without extra packages or a JWT library. This works when the license controller is in the same app (Option ❶).
- Register Data Protection in Program.cs (most Blazor apps already have it registered; calling it again is harmless):
builder.Services.AddDataProtection(); // Needed to protect the JSPrintManager license controller
- Issue the value where you call
JSPrintManager.Start(). For Blazor Server (or interactive server components in a Blazor Web App):
@using Microsoft.AspNetCore.DataProtection
@using Microsoft.AspNetCore.Components.Authorization
@inject IDataProtectionProvider DataProtectionProvider
@inject AuthenticationStateProvider AuthStateProvider
@code {
private async Task StartJSPrintManagerAsync()
{
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
var userName = authState.User.Identity?.Name ?? "";
// Per-user value, valid for 8 hours
var protector = DataProtectionProvider.CreateProtector("JSPM.License").ToTimeLimitedDataProtector();
var licenseAuthorizationHeader = "Bearer " + protector.Protect(userName, TimeSpan.FromHours(8));
// Start WebSocket comm
JSPrintManager.Start("LIC_URL", 29443, "127.0.0.1", true, licenseAuthorizationHeader);
}
}
Note
In Blazor WebAssembly Hosted apps, components run in the browser, so issue the value from an authenticated API endpoint of the server project and call it from the client before JSPrintManager.Start():
// using Microsoft.AspNetCore.DataProtection;
[Authorize]
[HttpGet("/jspm-auth")]
public string GetJspmAuth([FromServices] IDataProtectionProvider dp)
=> "Bearer " + dp.CreateProtector("JSPM.License").ToTimeLimitedDataProtector()
.Protect(User.Identity?.Name ?? "", TimeSpan.FromHours(8));
- Validate the value in the license controller and deny (HTTP 200 + invalid text) when it's missing, tampered or expired:
using System.Security.Cryptography;
using Microsoft.AspNetCore.DataProtection;
public class JSPMController : Controller
{
private readonly ITimeLimitedDataProtector _protector;
public JSPMController(IDataProtectionProvider dataProtectionProvider)
{
_protector = dataProtectionProvider.CreateProtector("JSPM.License").ToTimeLimitedDataProtector();
}
[AllowAnonymous] // the check is done below, so a denied request still gets HTTP 200
public IActionResult Index(string timestamp)
{
//SET THE LICENSE INFO
string license_owner = "YOUR-LICENSE-OWNER-HERE";
string license_key = "YOUR-LICENSE-KEY-HERE";
string license_token = "YOUR-LICENSE-TOKEN-HERE"; // leave it empty if you don't have one
//LICENSE VALIDATION CACHING (seconds)
int license_ttl = 86400; // 1 day
int license_grace = 259200; // 3 days
//AUTHORIZE THE REQUEST
if (!IsAuthorized())
return Content("denied", "text/plain");
//DO NOT MODIFY THE FOLLOWING CODE
Response.Headers["Cache-Control"] = "no-store";
Response.Headers["X-JSPM-License-Token"] = license_token;
Response.Headers["X-JSPM-License-TTL"] = license_ttl.ToString();
Response.Headers["X-JSPM-License-Grace"] = license_grace.ToString();
return File(Neodynamic.Blazor.JSPrintManager.GenerateLicense(license_owner, license_key, timestamp), "text/plain");
}
private bool IsAuthorized()
{
string auth = Request.Headers["Authorization"].ToString();
if (!auth.StartsWith("Bearer ", StringComparison.Ordinal))
return false;
try
{
_protector.Unprotect(auth.Substring(7)); // throws if tampered or expired
return true;
}
catch (CryptographicException)
{
return false;
}
}
}
Note
If your app runs on several servers/instances, they must share the Data Protection key ring so a value issued by one instance can be validated by another (see Configure ASP.NET Core Data Protection). Azure App Service already shares it between instances of the same app.
Custom headers
You could also provide any custom headers if the standard HTTP Authorization Header is not sufficient or not required. If that's your case, then it must be specified through the licenseCustomHeaders param of the JSPrintManager.Start() method. Each custom header must be on a new line (\n) and follow the 'Name: Value' format e.g. "Header-Name: value\nAnother-Header: value" format. Here is an example:
// Set custom headers with the real value!!!
var licenseCustomHeaders = "CF-Access-Client-Id: abc123\nCF-Access-Client-Secret: xyz789";
// Start WebSocket comm
JSPrintManager.Start("LIC_URL", 29443, "127.0.0.1", true, licenseAuthorizationHeader, true, licenseCustomHeaders);
//... more code...
Allowed origins
Starting with JSPrintManager App 9.0.26.1005, the origin query string parameter tells your controller which website is asking for the license. You can answer only for your own websites, which is especially useful for Unlimited licenses. For example, at the beginning of the controller action:
string[] allowed_origins = { "https://app.yourcompany.com", "https://intranet.yourcompany.com" };
// requests from older JSPrintManager App versions don't include "lv" nor "origin"
if (!string.IsNullOrEmpty(Request.Query["lv"]) && !allowed_origins.Contains(Request.Query["origin"].ToString()))
return Content("denied", "text/plain"); // deny with HTTP 200 + invalid text
Note
The origin check is a convenient filter, but it's not a replacement for the authorization header: the origin value is reported by the client, so it should be combined with one of the options above.
IMPORTANT: Be aware that if you do not provide any authorization method, then you must allow ANONYMOUS access on the license controller.