Skip to main content

Authentication

The daemon owns authentication. It manages all credentials and session tokens; your application passes authentication commands through KapeAuthClient and never holds or stores secrets itself.

Login​

using Kape.Auth;

var auth = new KapeAuthClient(handle);
await auth.LoginAsync(activationCode);

LoginAsync completes when the daemon has accepted the login and throws KapeError if it was rejected.

info

The exact authentication flow is agreed per integration and may be slightly customised. The recommended model is token handoff: your application supplies its own token, the SDK uses it to authenticate, and your application refreshes it periodically. Details will be finalised together with your integration team.

Authentication State​

auth.AuthState // KapeAuthState
auth.AuthStateChanged // event Action<KapeAuthState>
StateMeaning
AuthenticatedUser is logged in
UnauthenticatedUser is logged out

There is no Initializing state: KapeSdkHandle.CreateAsync waits for the daemon's state, so the client is resolved from the moment it exists.

auth.AuthStateChanged += state =>
Dispatcher.Invoke(() => showLogin = state == KapeAuthState.Unauthenticated);

Querying the Session​

if (auth.CurrentAuthenticationSession is { } session)
Console.WriteLine(session.Email);

CurrentAuthenticationSession is null while logged out. Email is null when the session carries no email, as with activation-code logins.

Logout​

await auth.LogoutAsync();

Clears the daemon's stored credentials and raises AuthStateChanged with Unauthenticated.

Error Handling​

Every call throws KapeError. Domain says whether the daemon rejected the call (KapeError.DaemonDomain, with the daemon's error name as the message) or the connection to it failed (KapeError.TransportDomain):

try
{
await auth.LoginAsync(activationCode);
}
catch (KapeError error)
{
Console.WriteLine($"[{error.Domain}] {error.Message}");
}

Authentication failures during a VPN connection surface through KapeVpnManager.ConnectionError as KapeVpnError.AuthenticationFailed or KapeVpnError.SessionExpired — see Connecting.