Skip to content

Login library

.NET Framework 4.8 library that adds Authenticator login to Tekla Structures plugins.

  • Browser login (default): the system browser opens as soon as the login window appears, so users log in with the company web login, including two-factor authentication and passkeys. The plugin never sees a password.
  • Email and password with a two-factor step, as a fallback in the same WPF window.
  • The login token is stored encrypted per Windows user (DPAPI); the password is never stored.
  • Works offline: a stored login stays valid until it expires.
  • No keys to configure: the server’s signing keys are trusted through a root key embedded in the library, so a key rotation on the server needs no plugin release.
  • Revocations (user removed, version blocked, logged out remotely, …) take effect the next time the plugin starts while online.
if (!await Auth.EnsureLoggedInAsync()) return;
  • .NET Framework 4.8, WPF.
  • An Authenticator server with:
    • an application for the plugin, with the plugin DLL uploaded as an allowed version (the server identifies the plugin by the SHA-256 of its DLL, so upload every build you ship);
    • the users who may use the plugin added as allowed users.

The library depends only on BouncyCastle.Cryptography (to verify Ed25519 token signatures, which .NET Framework can’t do natively). JSON uses the framework’s own serializer to avoid version conflicts with assemblies loaded by Tekla.

using Plugboard.Authenticate.Client;
Auth.Configure(new AuthenticatorOptions
{
BaseUrl = new Uri("https://authenticator.example.com/"),
PluginAssembly = typeof(PurlinDesignerPlugin).Assembly, // the DLL uploaded as a version
ApplicationName = "Purlin Designer", // shown in the login window
// Optional:
// Logo = new Uri("pack://application:,,,/PurlinDesigner;component/Resources/logo.png"), // shown at the top of the login window
// PreferredLoginMethod = LoginMethod.Password, // start with the email/password form instead of opening the browser
// BrowserLoginTimeout = TimeSpan.FromMinutes(5),
// RequestTimeout = TimeSpan.FromSeconds(10),
});

PluginAssembly must be the plugin’s own assembly (not Assembly.GetExecutingAssembly() inside a helper library), because its file hash must match the uploaded version.

Logo: add the image (PNG, JPG, BMP, GIF or ICO) to the plugin project with the build action Resource and refer to it with a pack URI: pack://application:,,,/<plugin assembly name>;component/<path in the project>. A file path (new Uri(@"C:\…\logo.png")) also works. The logo is scaled down to at most 64 px high and the window width. Without a Logo, or when it can’t be loaded, the window shows the library’s default logo; a broken logo never stops the login. The window icon is always the library’s favicon.ico.

Create the pack URI inside the AuthenticatorOptions initializer, as above. Tekla has no WPF Application, and the library registers the pack:// scheme when AuthenticatorOptions is first used. A new Uri("pack://…") created earlier in the plugin throws “Invalid URI: Invalid port specified”.

Login window: with the default LoginMethod.Browser, the system browser opens as soon as the window appears; the window offers “Cancel browser login” to switch to email and password. When the window has a message to show (e.g. “Your login has expired”), the browser isn’t opened automatically, so the user sees why they have to log in again.

No keys need to be configured: the library embeds the Authenticator’s root public key (RootKeys.Default) and fetches the server’s token signing keys itself (see Signing keys).

Two optional settings exist for special cases:

  • RootPublicKeys: replaces the embedded roots, for a test or self-hosted server.
  • PublicKeys: signing keys (kid → x from GET /api/app-auth/public-key) to trust directly, without a certificate. Plugins configured this way keep working as before.
if (!await Auth.EnsureLoggedInAsync())
{
return; // the user cancelled the login
}
var user = Auth.CurrentUser; // Id, Name, Email, ExpiresAt

EnsureLoggedInAsync returns immediately when a valid login is stored. Otherwise it shows the login window and returns true after a successful login, or false when the user cancels.

When the server checks a stored login, it also says whether a newer published version of the plugin is available: Auth.LatestUpdate (UpdateAvailable, CurrentVersion, LatestVersion, ReleaseNotes, DownloadUrl, …), or null when there was no check. A plugin that also uses Plugboard.Tracking.Core doesn’t need it: its update notification uses this answer automatically (see Update notifications).

await Auth.LogoutAsync();

This revokes the token on the server (when reachable) and deletes it from the PC.

If you need several independent instances (e.g. in tests), use new PluginAuthenticator(options) instead of the static Auth class.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using Tekla.Structures.Plugins;
using Plugboard.Authenticate.Client;
[Plugin("PurlinDesigner")]
[PluginUserInterface("PurlinDesigner.MainWindow")]
public class PurlinDesignerPlugin : PluginBase
{
static PurlinDesignerPlugin()
{
Auth.Configure(new AuthenticatorOptions
{
BaseUrl = new Uri("https://authenticator.example.com/"),
PluginAssembly = typeof(PurlinDesignerPlugin).Assembly,
ApplicationName = "Purlin Designer",
});
}
public override List<InputDefinition> DefineInput() => new List<InputDefinition>();
public override bool Run(List<InputDefinition> input)
{
// Run() is synchronous; wait for the login without blocking WPF's message loop.
var loggedIn = Task.Run(() => Auth.EnsureLoggedInAsync()).GetAwaiter().GetResult();
if (!loggedIn)
{
return false;
}
// ... create the purlins ...
return true;
}
}

In a plugin’s WPF window (for example in the Loaded handler), call it directly:

private async void OnLoaded(object sender, RoutedEventArgs e)
{
if (!await Auth.EnsureLoggedInAsync())
{
Close();
}
}

The login window is a WPF dialog. When called from a WPF UI thread it is shown there; from any other thread (as in Run() above) it is shown on its own STA thread.

On start-up (EnsureLoggedInAsync):

  1. Load the stored token. If there is none, or its signature is invalid, show the login window.
  2. If it has expired, show the login window (“Your login has expired”).
  3. Ask the server (POST /api/app-auth/check) whether it is still valid:
    • valid → logged in;
    • revoked → delete it and show the login window with the reason (e.g. “Your account no longer has access to this plugin”);
    • server unreachable → logged in if the token’s signature was verified with a trusted signing key (offline use until expiry).

Signing keys: tokens are signed with the server’s signing key, which changes from time to time. The library trusts a signing key when the Authenticator’s root key certified it:

  1. The library embeds the root public key (RootKeys.Default). The root’s secret key is kept offline, never on the server.
  2. GET /api/app-auth/public-key returns each signing key with a certificate: the root’s Ed25519 signature over the key ID, the key and an expiry date.
  3. The library fetches the keys when a token’s key isn’t trusted yet (at login and after the start-up check) and otherwise at most once a day, keeps only those whose certificate verifies, and caches them with their certificates in %LOCALAPPDATA%\Plugboard.Authenticate\<server>.keys.json.
  4. Certificates are checked again whenever the cache is loaded, so editing the cache can’t add a key. A key whose certificate has expired is no longer trusted offline.

The keys are only fetched after the server has answered, so a failed fetch never blocks the start: the online check decides as before.

Rotating the signing key needs no plugin release: the server operator certifies the new key with php artisan plugin-auth:certify-key and publishes it.

Rotating the root key needs a library release: generate the new root with php artisan plugin-auth:generate-root-key, add it to RootKeys.Default next to the old one, and remove the old root only once every plugin in use has the new release. Certify the signing keys with the new root once plugins trust it.

Browser login (OAuth 2.0 for native apps, RFC 8252, with PKCE):

  1. The plugin listens on http://127.0.0.1:<random port>/callback and opens /app-auth/authorize?file_hash=…&pc_name=…&redirect_uri=…&code_challenge=…&code_challenge_method=S256&state=….
  2. The user logs in to the web app if needed and confirms the login.
  3. The browser is redirected to the plugin’s listener with a one-time code, which the plugin exchanges (with the PKCE verifier) at POST /api/app-auth/token for the token.

No URL reservation or administrator rights are needed: the listener is a plain socket on the loopback interface.

Password login: POST /api/app-auth/login with email, password, the DLL hash and the PC name; users with two-factor authentication then enter their code (POST /api/app-auth/2fa).

Token storage: %LOCALAPPDATA%\Plugboard.Authenticate\<server>-<assembly>.token, encrypted with DPAPI for the current Windows user.

The login window shows clear messages for the common cases: wrong email or password, account not allowed to use the plugin, plugin version blocked or not recognised (install an official release), logging in disabled for the plugin, server unreachable, too many attempts, and an expired two-factor or browser step.

This repo also contains the usage tracking library for Tekla plugins and tools. It’s separate from the login library and can be used with or without it:

  • Plugboard.Tracking.Core: config file, automatic start, context, custom events (with the logged-in account from the login library), standalone tool sessions, unhandled exceptions, form and button clicks, and the background sender with an offline buffer.
  • Plugboard.Tracking.Tekla: tracked base classes for model and drawing plugins (run events, plugin data) and their WinForms and WPF dialogs.
  • examples/: example plugins and tools, and a quick start.