XmppSharp.Net
1.0.2
dotnet add package XmppSharp.Net --version 1.0.2
NuGet\Install-Package XmppSharp.Net -Version 1.0.2
<PackageReference Include="XmppSharp.Net" Version="1.0.2" />
<PackageVersion Include="XmppSharp.Net" Version="1.0.2" />
<PackageReference Include="XmppSharp.Net" />
paket add XmppSharp.Net --version 1.0.2
#r "nuget: XmppSharp.Net, 1.0.2"
#addin nuget:?package=XmppSharp.Net&version=1.0.2
#tool nuget:?package=XmppSharp.Net&version=1.0.2
XMPP#Net
Client and component connection implementations using XMPP#.
This package contains the implementation of the client and components protocols. The goal is to split this package for specific uses.
For example, XMPP# itself is a library that implements classes, functions, etc., for use with the XMPP protocol itself, so the additional packages are extensions for this.
This package also implements the SASL factory and mechanisms (authentication) for client connections.
Register custom SASL handler
To register a SASL handler or overwrite an existing one, simply follow these steps:
- Create the class that extends the base class
XmppSaslHandler
.
public class SaslPlainHandler : XmppSaslHandler
{
}
- Override the
Init
method to send the initial authentication packet:
protected internal override void Init()
{
var buf = new StringBuilder()
.Append('\0')
.Append(Connection.User)
.Append('\0')
.Append(Connection.Password)
.ToString()
.GetBytes();
var el = new Auth
{
Mechanism = "PLAIN",
Value = Convert.ToBase64String(buf)
};
Connection.Send(el);
}
In the case of the PLAIN mechanism, there are only 2 fields sent
nullchar + user + nullchar + password
.
- Override the
Invoke
method to handle xmpp elements in SASL handler:
protected internal override SaslHandlerResult Invoke(XmppElement e)
{
// server responded with success.
if (e is Success)
return SaslHandlerResult.Success;
// server responded with failure.
if (e is Failure failure)
return SaslHandlerResult.Failure(failure.Condition, failure.Text);
// is not SASL element, skip.
return SaslHandlerResult.Continue;
}
This is how the PLAIN mechanism is implemented on the client. And registering is simple. Just call the function: RegisterMechanism("PLAIN", c => new XmppSaslPlainHandler(c));
There are a few things to consider in this Invoke
method.
It expects to return a
SaslHandlerResult
that tellswhether the authentication failed, succeeded, or ignored.In the case of ignored, it means that the element was not processed by the SASL handler (it does not belong to the mechanism). If it is ignored, it will be sent to the
OnElement
event of the connection.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- XmppSharp (>= 6.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.