mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
Add support for chaning passwords
This commit is contained in:
@@ -3,20 +3,18 @@ using MQTTnet.Core.Serializer;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public abstract class BaseMqttClientOptions : IMqttClientOptions
|
||||
public class MqttClientOptions : IMqttClientOptions
|
||||
{
|
||||
public MqttClientTlsOptions TlsOptions { get; set; } = new MqttClientTlsOptions();
|
||||
|
||||
public MqttApplicationMessage WillMessage { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string ClientId { get; set; } = Guid.NewGuid().ToString("N");
|
||||
|
||||
public bool CleanSession { get; set; } = true;
|
||||
|
||||
public IMqttClientCredentials Credentials { get; set; } = new MqttClientCredentials();
|
||||
|
||||
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(5);
|
||||
|
||||
public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public interface IMqttClientCredentials
|
||||
{
|
||||
string Password { get; }
|
||||
string Username { get; }
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,14 @@ namespace MQTTnet.Core.Client
|
||||
{
|
||||
public interface IMqttClientOptions
|
||||
{
|
||||
bool CleanSession { get; }
|
||||
string ClientId { get; }
|
||||
bool CleanSession { get; }
|
||||
MqttApplicationMessage WillMessage { get; }
|
||||
IMqttClientCredentials Credentials { get; }
|
||||
|
||||
TimeSpan DefaultCommunicationTimeout { get; }
|
||||
TimeSpan KeepAlivePeriod { get; }
|
||||
string Password { get; }
|
||||
MqttProtocolVersion ProtocolVersion { get; }
|
||||
MqttClientTlsOptions TlsOptions { get; }
|
||||
string UserName { get; }
|
||||
MqttApplicationMessage WillMessage { get; }
|
||||
}
|
||||
}
|
||||
@@ -186,8 +186,8 @@ namespace MQTTnet.Core.Client
|
||||
var connectPacket = new MqttConnectPacket
|
||||
{
|
||||
ClientId = _options.ClientId,
|
||||
Username = _options.UserName,
|
||||
Password = _options.Password,
|
||||
Username = _options.Credentials?.Username,
|
||||
Password = _options.Credentials?.Password,
|
||||
CleanSession = _options.CleanSession,
|
||||
KeepAlivePeriod = (ushort)_options.KeepAlivePeriod.TotalSeconds,
|
||||
WillMessage = willApplicationMessage
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public class MqttClientCredentials : IMqttClientCredentials
|
||||
{
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public class MqttClientTcpOptions : BaseMqttClientOptions
|
||||
public class MqttClientTcpOptions : MqttClientOptions
|
||||
{
|
||||
public string Server { get; set; }
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Net;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public class MqttClientWebSocketOptions : BaseMqttClientOptions
|
||||
public class MqttClientWebSocketOptions : MqttClientOptions
|
||||
{
|
||||
public string Uri { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user