Skip to content

Commit

Permalink
Rename methods to fit naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Dec 23, 2024
1 parent d156605 commit 46d0dac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Samples/Client/Client_Connection_Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static async Task Connect_Using_Enhanced_Authentication()
.WithTcpServer("localhost")
.WithProtocolVersion(MqttProtocolVersion.V500)
.WithEnhancedAuthenticationHandler(kerberosAuthenticationHandler)
.WithAuthentication("GS2-KRB5")
.WithEnhancedAuthentication("GS2-KRB5")
.Build();

var client = mqttClientFactory.CreateMqttClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public async Task Use_Enhanced_Authentication()
// Use Kerberos sample from the MQTT RFC.
var kerberosAuthenticationHandler = new TestClientKerberosAuthenticationHandler();

var clientOptions = testEnvironment.CreateDefaultClientOptionsBuilder().WithAuthentication("GS2-KRB5").WithEnhancedAuthenticationHandler(kerberosAuthenticationHandler);
var clientOptions = testEnvironment.CreateDefaultClientOptionsBuilder().WithEnhancedAuthentication("GS2-KRB5").WithEnhancedAuthenticationHandler(kerberosAuthenticationHandler);
var client = await testEnvironment.ConnectClient(clientOptions);

Assert.IsTrue(client.IsConnected);
Expand Down
36 changes: 14 additions & 22 deletions Source/MQTTnet/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;

namespace MQTTnet;

Expand Down Expand Up @@ -98,13 +98,6 @@ public MqttClientOptionsBuilder WithAddressFamily(AddressFamily addressFamily)
return this;
}

public MqttClientOptionsBuilder WithAuthentication(string method, byte[] data = null)
{
_options.AuthenticationMethod = method;
_options.AuthenticationData = data;
return this;
}

/// <summary>
/// Clean session is used in MQTT versions below 5.0.0. It is the same as setting "CleanStart".
/// </summary>
Expand Down Expand Up @@ -138,27 +131,19 @@ public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{
case "tcp":
case "mqtt":
WithTcpServer(uri.Host, port)
.WithAddressFamily(AddressFamily.Unspecified)
.WithProtocolType(ProtocolType.Tcp)
.WithTlsOptions(o => o.UseTls(false));
WithTcpServer(uri.Host, port).WithAddressFamily(AddressFamily.Unspecified).WithProtocolType(ProtocolType.Tcp).WithTlsOptions(o => o.UseTls(false));
break;

case "mqtts":
WithTcpServer(uri.Host, port)
.WithAddressFamily(AddressFamily.Unspecified)
.WithProtocolType(ProtocolType.Tcp)
.WithTlsOptions(o => o.UseTls(true));
WithTcpServer(uri.Host, port).WithAddressFamily(AddressFamily.Unspecified).WithProtocolType(ProtocolType.Tcp).WithTlsOptions(o => o.UseTls());
break;

case "ws":
WithWebSocketServer(o => o.WithUri(uri.ToString()))
.WithTlsOptions(o => o.UseTls(false));
WithWebSocketServer(o => o.WithUri(uri.ToString())).WithTlsOptions(o => o.UseTls(false));
break;

case "wss":
WithWebSocketServer(o => o.WithUri(uri.ToString()))
.WithTlsOptions(o => o.UseTls(true));
WithWebSocketServer(o => o.WithUri(uri.ToString())).WithTlsOptions(o => o.UseTls());
break;

// unix:///path/to/socket
Expand Down Expand Up @@ -220,6 +205,13 @@ public MqttClientOptionsBuilder WithEndPoint(EndPoint endPoint)
return this;
}

public MqttClientOptionsBuilder WithEnhancedAuthentication(string method, byte[] data = null)
{
_options.AuthenticationMethod = method;
_options.AuthenticationData = data;
return this;
}

public MqttClientOptionsBuilder WithEnhancedAuthenticationHandler(IMqttEnhancedAuthenticationHandler handler)
{
_options.EnhancedAuthenticationHandler = handler;
Expand Down

0 comments on commit 46d0dac

Please sign in to comment.