A .NET MAUI app is one C# codebase that ships as four very different binaries: a packaged Windows app, a notarized Mac app, an App Store IPA, and a Play Store AAB. The appeal is that MainPage.xaml and your view models do not care which one they are. Licensing is where that stops being true — not because the Keyright SDK calls differ across platforms, they do not, but because the three things any licensing SDK leans on are provided by the operating system, and all three look different on a phone than on a desktop.
Those three things are a stable identity for the device, somewhere safe to keep the issued token, and a way to check the license when there is no network — a subway, a plane, a customer site with no guest Wi-Fi. On Windows and macOS you can reach for a machine GUID, a file under the user profile, and the assumption that the app launches often. On iOS and Android the first is deliberately taken away from you, the second has a right answer that is not a file, and the third is the normal case rather than the edge. This post is the cross-platform version of the story, built on Keyright and the MAUI primitives Microsoft.Maui.Devices and Microsoft.Maui.Storage.SecureStorage.
The identity you cannot have, and the one you make
The instinct from desktop licensing is to anchor the device on something the hardware hands you: a serial number, a MAC address, a disk id. On mobile, every one of those is either gone or a trap.
Apple does not expose a device serial to apps, and identifierForVendor resets once you uninstall every app from a given vendor. Android quietly stopped returning the real MAC years ago (you get 02:00:00:00:00:00), Settings.Secure.ANDROID_ID is scoped per signing key and resets on a factory reset, and the hardware serial now needs a privileged permission an ordinary app will never be granted. The advertising id is worse: it is user-resettable by design, and requesting it for anything that is not advertising is an App Store review rejection. The platforms are not being awkward. A durable, app-readable hardware fingerprint is a tracking vector, so they removed it on purpose.
So the device identity for a licensing check is not something you read. It is something you create once and keep. Generate a GUID on first run, persist it in secure storage, and treat that value as the anchor. Microsoft.Maui.Devices.DeviceInfo then gives you a handful of permission-free signals — model, manufacturer, platform, idiom — that are useful as a human-readable descriptor in the dashboard but must never be the identity, because they are shared across millions of identical phones.
using Microsoft.Maui.Devices;
using Microsoft.Maui.Storage;
public static class DeviceIdentity
{
const string DeviceIdKey = "keyright.device_id";
/// <summary>A stable per-install anchor. Created once, kept in SecureStorage, never derived from hardware.</summary>
public static async Task<string> GetOrCreateAsync()
{
string? id = await SecureStorage.Default.GetAsync(DeviceIdKey);
if (string.IsNullOrEmpty(id))
{
id = Guid.NewGuid().ToString("N");
await SecureStorage.Default.SetAsync(DeviceIdKey, id);
}
return id;
}
/// <summary>Permission-free soft signals — a label for the dashboard, not the identity.</summary>
public static string Describe() =>
$"{DeviceInfo.Current.Manufacturer} {DeviceInfo.Current.Model}; " +
$"{DeviceInfo.Current.Platform}; {DeviceInfo.Current.Idiom}";
}
This is a soft binding, and the word is doing real work. The id is stable for the life of the install, which is enough to count a seat, recognise the device on the next launch, and notice when one key suddenly appears on fifty "devices". It is not tamper-proof hardware attestation, and it is not meant to be. Be honest about that in your own head when you design the seat policy, and you will not build a support nightmare out of a security property the platform never offered you.
Keeping the token behind the keystore
Activation exchanges a license key plus that device id for a signed entitlement token. Where that token lives matters, because a plain file in the app's data directory is readable by a file browser on a rooted or jailbroken device and, on desktop, by anything running as the user.
MAUI's answer is SecureStorage, and it is backed by the platform keystore on every target: the Keychain on iOS and macOS, the Android Keystore by way of EncryptedSharedPreferences, and DPAPI on Windows. The value is encrypted at rest and scoped to your app. You write to it exactly the same way everywhere.
using Microsoft.Maui.Storage;
public static class LicenseStore
{
const string TokenKey = "keyright.license_token";
const string LastSeenKey = "keyright.last_seen_utc";
public static Task SaveTokenAsync(string token) =>
SecureStorage.Default.SetAsync(TokenKey, token);
public static Task<string?> ReadTokenAsync() =>
SecureStorage.Default.GetAsync(TokenKey);
// A monotonic timestamp, kept to catch a clock wound backwards during the offline window.
public static Task StampSeenAsync(DateTimeOffset now) =>
SecureStorage.Default.SetAsync(LastSeenKey, now.ToUnixTimeSeconds().ToString());
public static async Task<DateTimeOffset?> ReadLastSeenAsync()
{
string? raw = await SecureStorage.Default.GetAsync(LastSeenKey);
return long.TryParse(raw, out long s) ? DateTimeOffset.FromUnixTimeSeconds(s) : null;
}
}
A signed license token is not a secret the way a password is — it is bound to the entitlements and the licensee, not to a credential, and a copy of it buys an attacker nothing the signature does not already permit. But it names the licensee and lists what they paid for, and SecureStorage costs nothing to use, so there is no reason to leave it in the open. The one thing to know is that SecureStorage can be cleared — an OS backup restored to a new device, a keystore reset, an app reinstall — and the design below treats a missing token as "not yet activated", never as an error.
Verify on launch, against a key you pinned
The token is a document the licensing service signed with its private key. Your app ships the matching public key, compiled in, and verifies against that and only that — pinning the key is what stops a man-in-the-middle or a swapped endpoint from handing your app a forged license, and it is the subject of its own pinned-key guidance in the docs. Because verification is pure signature math over the token bytes, it needs no network at all.
That is the whole offline story. The token carries, inside the signed payload, the granted entitlements, the term end, and an offline-grace deadline the service stamped at issuance — "this snapshot is good to run without checking back until this instant". On every launch the app reads the cached token and verifies it locally; it only needs the service when the grace window has run out.
Here is the launch gate that implements the figure. LicenseVerifier takes the pinned public key and does the offline check; ILicenseClient is the online side, used only to refresh. The entitlement keys (export.pdf, sync.cloud, projects.unlimited) are example names a vendor picks for their own features — they are not Keyright internals, and you choose whatever reads well for your product.
using Keyright.Client;
public sealed class MauiLicenseGate
{
static readonly TimeSpan RefreshIfOlderThan = TimeSpan.FromDays(1);
readonly LicenseVerifier _verifier;
readonly ILicenseClient _client;
public MauiLicenseGate()
{
// The verification public key is pinned in the app: offline checks trust this and nothing else.
_verifier = new LicenseVerifier(AcmeKeys.LicenseVerificationPublicKey);
_client = new LicenseClient(new LicenseClientOptions
{
Product = "acme-mobile",
ServiceUrl = "https://licensing.acme.example",
Verifier = _verifier,
});
}
public async Task<Entitlements> VerifyOnLaunchAsync(CancellationToken ct = default)
{
string? token = await LicenseStore.ReadTokenAsync();
if (string.IsNullOrEmpty(token))
return Entitlements.CommunityEdition; // never activated, or SecureStorage was cleared
DateTimeOffset now = DateTimeOffset.UtcNow;
// Clock-rollback guard: a time wound backwards past our last launch is not trustworthy.
DateTimeOffset? lastSeen = await LicenseStore.ReadLastSeenAsync();
if (lastSeen is { } seen && now < seen)
return await RevalidateOrCommunityAsync(token, ct);
// Pure offline verification against the pinned key — signature, term, and grace deadline.
LicenseVerification v = _verifier.Verify(token, now);
await LicenseStore.StampSeenAsync(now);
if (v.Status == LicenseStatus.SignatureInvalid || v.Status == LicenseStatus.Expired)
return Entitlements.CommunityEdition;
if (now > v.OfflineGraceUntilUtc)
return await RevalidateOrCommunityAsync(token, ct); // snapshot too old to trust blindly
// Good, and offline. Refresh in the background if it is stale and we happen to be online.
if (now - v.IssuedUtc > RefreshIfOlderThan)
_ = TryRefreshAsync(ct);
return v.Entitlements;
}
async Task<Entitlements> RevalidateOrCommunityAsync(string token, CancellationToken ct)
{
return await TryRefreshAsync(ct) is { } fresh ? fresh.Entitlements
: Entitlements.CommunityEdition;
}
async Task<LicenseVerification?> TryRefreshAsync(CancellationToken ct)
{
try
{
string deviceId = await DeviceIdentity.GetOrCreateAsync();
RefreshResult r = await _client.RefreshAsync(deviceId, ct); // re-signs the current entitlements
if (r.Verification.Status == LicenseStatus.Valid)
{
await LicenseStore.SaveTokenAsync(r.Token);
return r.Verification;
}
}
catch (LicenseTransportException)
{
// Offline or the service is unreachable: keep whatever we had, never downgrade on a network error.
}
return null;
}
}
The shape worth noticing: the fast path is entirely local, the network is touched only to extend trust, and a failed network call never makes things worse than the cached snapshot already was. First-time activation is the one explicit online step, and it is where the device id is minted and sent:
public async Task<Entitlements> ActivateAsync(string licenseKey, CancellationToken ct = default)
{
string deviceId = await DeviceIdentity.GetOrCreateAsync();
ActivationResult r = await _client.ActivateAsync(licenseKey, deviceId, DeviceIdentity.Describe(), ct);
if (r.Verification.Status != LicenseStatus.Valid)
return Entitlements.CommunityEdition;
await LicenseStore.SaveTokenAsync(r.Token); // straight into the keystore
await LicenseStore.StampSeenAsync(DateTimeOffset.UtcNow);
return r.Verification.Entitlements;
}
Gating a feature on the result
With the gate returning an Entitlements set, a feature check is a lookup — no network, no latency, callable from a view model on any platform:
Entitlements ent = await _gate.VerifyOnLaunchAsync();
ExportButton.IsEnabled = ent.Has("export.pdf");
CloudSyncSwitch.IsEnabled = ent.Has("sync.cloud");
_projectLimit = ent.Has("projects.unlimited") ? int.MaxValue : 3;
The Entitlements.CommunityEdition fallback is deliberate: when there is no valid license, the app does not crash or lock — it runs as Keyright's free Community Edition tier, with the paid features off. A user whose keystore was wiped by a phone migration opens the app, sees the free tier, re-enters their key, and is back. That is a far better failure than a modal that says "license error" over an app they paid for.
Where this binding gives, honestly
Three limits are built into the approach, and each is a trade you are choosing on purpose.
The device id is soft. It survives for the life of the install and no longer. A reinstall, a factory reset, or a migration to a new phone clears SecureStorage, the persisted GUID is gone, and the next activation looks like a brand-new device. There is no mobile mechanism that would make it otherwise without the privacy permissions you must not request. So design for re-activation rather than against it: make the key easy to re-enter, keep server-side activation idempotent so re-binding the same license to the same account does not quietly consume a second seat where you can match it, and ship an in-app deactivate so a real device move frees the old seat cleanly.
SecureStorage can be cleared. It is encrypted and app-scoped, not indestructible. OS backups, keystore resets and reinstalls all take it with them. The code treats an absent token as "not activated", which is why a wipe degrades to the free tier and a prompt, not to a broken app.
Offline grace is latency against revocation. A fourteen-day grace window is fourteen days during which a device that has gone dark keeps its entitlements on the strength of the last token it saw — including, in the worst case, a license you revoked on day one. Shrink the window and offline users re-authenticate more often and feel the licensing more; widen it and a revoked or refunded license lingers longer on a disconnected device. There is no setting that is free of this trade; there is only the window that fits how your customers actually use the app, and the opportunistic refresh that keeps the honest majority topped up without them ever noticing.
Takeaway
MAUI gives you one codebase; the platforms underneath it give you one licensing shape, not one licensing primitive. You cannot read a durable hardware id on mobile, so you mint and persist your own and accept a soft binding. You should not keep the token in a file, so you put it in SecureStorage and get the Keychain, the Keystore and DPAPI for free. And you cannot assume a network, so you verify a signed token offline against a pinned public key and let a grace window carry the app until a connection — any connection, on any launch — quietly refreshes it. Build it that way and the same four lines of feature-gating run identically on a Surface, a MacBook, an iPhone and a Pixel, which was the point of writing it in MAUI to begin with.
Top comments (0)