Plugboard.Authenticate.Client
0.1.2
dotnet add package Plugboard.Authenticate.Client --version 0.1.2
NuGet\Install-Package Plugboard.Authenticate.Client -Version 0.1.2
<PackageReference Include="Plugboard.Authenticate.Client" Version="0.1.2" />
<PackageVersion Include="Plugboard.Authenticate.Client" Version="0.1.2" />
<PackageReference Include="Plugboard.Authenticate.Client" />
paket add Plugboard.Authenticate.Client --version 0.1.2
#r "nuget: Plugboard.Authenticate.Client, 0.1.2"
#:package Plugboard.Authenticate.Client@0.1.2
#addin nuget:?package=Plugboard.Authenticate.Client&version=0.1.2
#tool nuget:?package=Plugboard.Authenticate.Client&version=0.1.2
Plugboard.Authenticate.Client
.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;
Requirements
- .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 build by the SHA-256 of its DLL or, when the plugin has no file of its own because Tekla loads plugins from memory, by its MVID, the ID the compiler gives each build; 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.
Setup
1. Configure once
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 MVID and 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→xfromGET /api/app-auth/public-key) to trust directly, without a certificate. Plugins configured this way keep working as before.
2. Require a login
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).
3. Log out (optional)
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.
Example plugin
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.
Complete, buildable examples are in examples/: a Tekla model plugin with a WPF dialog (AuthModelPluginExample) and a standalone WPF app (AuthWpfAppExample).
How it works
On start-up (EnsureLoggedInAsync):
- Load the stored token. If there is none, or its signature is invalid, show the login window.
- If it has expired, show the login window ("Your login has expired").
- 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:
- The library embeds the root public key (
RootKeys.Default). The root's secret key is kept offline, never on the server. GET /api/app-auth/public-keyreturns each signing key with a certificate: the root's Ed25519 signature over the key ID, the key and an expiry date.- 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. - 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):
- The plugin listens on
http://127.0.0.1:<random port>/callbackand opens/app-auth/authorize?file_hash=…&mvid=…&pc_name=…&redirect_uri=…&code_challenge=…&code_challenge_method=S256&state=…. - The user logs in to the web app if needed and confirms the login.
- 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/tokenfor 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.
Error messages
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.
Usage tracking
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.
Building and testing
dotnet build Plugboard.slnx
dotnet test Plugboard.slnx
Requires Windows with the .NET SDK and the .NET Framework 4.8 targeting pack. The .NET Framework test host can't load test adapters from network paths (including \\wsl.localhost\…); run the tests from a local drive.
If a rebuild fails because Plugboard.Tracking.Build.Tasks.dll is locked by MSBuild, run dotnet build-server shutdown and build again. Projects in this repo run the config check from the freshly built task; projects using the package aren't affected.
The usage tracking tests (tests/Plugboard.Tracking.Tests) are mostly unit tests. They also include:
- UI tests with real WinForms and WPF windows, shown off-screen;
- integration tests against a local stand-in for the usage events API (
FakeUsageApi, with the server's validation rules); - end-to-end tests that start a real tracked EXE (
tests/Plugboard.Tracking.TestApp) and check what reaches that API, for a normal exit, a crash, and an offline run.
CI (.gitlab-ci.yml) builds and tests everything on every push. It also builds Plugboard.Tracking.Tekla against the newest Tekla API, to check it uses nothing that Tekla has removed.
Releasing
The packages are published to nuget.org and to this project's GitLab NuGet registry, with semantic versions. A release tag picks what is released:
| Tag | Packages |
|---|---|
plugboard-authenticate-v<version> |
Plugboard.Authenticate.Client |
plugboard-tracking-v<version> |
Plugboard.Tracking.Core and Plugboard.Tracking.Tekla, always together with the same version |
For a tracking release, move the
[Unreleased]notes insrc/Plugboard.Tracking.Core/CHANGELOG.mdunder a new## [x.y.z]heading. The pack job fails if the changelog has no section for the version.Merge to
main, then tag the commit and push the tag:git tag plugboard-tracking-v0.2.0 git push origin plugboard-tracking-v0.2.0CI packs the packages with that version and publishes them. Pre-release tags such as
plugboard-tracking-v0.2.0-beta.1work too. A version published to nuget.org can't be deleted, only unlisted.
Publishing to nuget.org uses Trusted Publishing, so no API key is stored: the job exchanges a GitLab ID token for a nuget.org key that is valid for one hour. It needs, once:
- a Trusted Publishing policy on nuget.org (Account › Federated credentials, provider GitLab) for namespace
atsolutions1and projecttekla-authenticator-client, packagesPlugboard.*, environmentnuget-org, and no ref (nuget.org only accepts branch names there, and releases run on tags); - a CI/CD variable
NUGET_USERNAME: the nuget.org user name (not the email address) of the policy owner; - the tags
plugboard-*protected (Settings › Repository › Protected tags), so only maintainers can start a release.
To use the packages from the GitLab registry instead of nuget.org, add it as a NuGet source. Use a personal or deploy token with read_package_registry:
dotnet nuget add source "https://gitlab.com/api/v4/projects/89235817/packages/nuget/index.json" --name ats-gitlab --username <user> --password <token>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- BouncyCastle.Cryptography (>= 2.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.