Skip to content

Commit

Permalink
Continue consolidating the auth methods for the hub device (#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
brycewang-microsoft committed Oct 20, 2022
1 parent d368def commit 27efde5
Show file tree
Hide file tree
Showing 32 changed files with 585 additions and 983 deletions.
1 change: 1 addition & 0 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ but users are still encouraged to migrate to version 2 when they have the chance
- The exponential back-off retry policy has updated parameters and logic.
- Remote certificate validation is no natively longer supported for AMQP web socket connections.
- The supported workaround is to provide a client web socket instance in the client options.
- The authentication classes for devices and modules have been consolidated.

#### Notable additions

Expand Down
8 changes: 4 additions & 4 deletions e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public async Task X509_Cert_Chain_Install_Test_MqttTcp()
};
var auth = new ClientAuthenticationWithX509Certificate(
s_chainCertificateWithPrivateKey,
TestConfiguration.IotHub.X509ChainDeviceName,
chainCertificates: chainCerts);
chainCerts,
TestConfiguration.IotHub.X509ChainDeviceName);
using var deviceClient = new IotHubDeviceClient(
_hostName,
auth,
Expand All @@ -139,8 +139,8 @@ public async Task X509_Cert_Chain_Install_Test_AmqpTcp()
};
var auth = new ClientAuthenticationWithX509Certificate(
s_chainCertificateWithPrivateKey,
TestConfiguration.IotHub.X509ChainDeviceName,
chainCertificates: chainCerts);
chainCerts,
TestConfiguration.IotHub.X509ChainDeviceName);
using var deviceClient = new IotHubDeviceClient(
_hostName,
auth,
Expand Down
4 changes: 2 additions & 2 deletions e2e/test/iothub/DeviceTokenRefreshE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public async Task IotHubDeviceClient_TokenConnectionDoubleRelease_Ok()
Target = $"{iotHub}/devices/{WebUtility.UrlEncode(deviceId)}",
};

var auth = new ClientAuthenticationWithToken(builder.ToSignature(), deviceId);
var auth = new ClientAuthenticationWithSharedAccessSignature(builder.ToSignature(), deviceId);

using var deviceClient = new IotHubDeviceClient(iotHub, auth, new IotHubClientOptions(new IotHubClientAmqpSettings()));
VerboseTestLogger.WriteLine($"{deviceId}: Created {nameof(IotHubDeviceClient)}");
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task IotHubDeviceClient_CreateFromConnectionString_TokenIsRefreshed
using var deviceDisconnected = new SemaphoreSlim(0);

TestDevice testDevice = await TestDevice.GetTestDeviceAsync(DevicePrefix).ConfigureAwait(false);
var auth = new ClientAuthenticationWithConnectionString(testDevice.ConnectionString, sasTokenTimeToLive, sasTokenRenewalBuffer);
var auth = new ClientAuthenticationWithSharedAccessKeyRefresh(testDevice.ConnectionString, sasTokenTimeToLive, sasTokenRenewalBuffer);

var options = new IotHubClientOptions(new IotHubClientMqttSettings());

Expand Down
2 changes: 1 addition & 1 deletion e2e/test/provisioning/ProvisioningE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ public static ProvisioningClientOptions CreateProvisioningClientOptionsFromName(
}
else if (provisioningAuth is AuthenticationProviderSymmetricKey symmetricKeyAuth)
{
auth = new ClientAuthenticationWithRegistrySymmetricKey(symmetricKeyAuth.GetPrimaryKey(), deviceId);
auth = new ClientAuthenticationWithSharedAccessKeyRefresh(symmetricKeyAuth.GetPrimaryKey(), deviceId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static async Task<int> Main(string[] args)
new X509Certificate2(parameters.Intermediate2CertPath)
};
using var deviceCert = new X509Certificate2(parameters.DevicePfxPath, parameters.DevicePfxPassword);
var auth = new ClientAuthenticationWithX509Certificate(deviceCert, parameters.DeviceName, chainCertificates: chainCerts);
var auth = new ClientAuthenticationWithX509Certificate(deviceCert, chainCerts, parameters.DeviceName);

var options = new IotHubClientOptions(parameters.GetHubTransportSettings());
using var deviceClient = new IotHubDeviceClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static async Task<IotHubDeviceClient> SetupDeviceClientAsync(Parameters
case "dps":
logger.LogDebug($"Initializing via DPS");
DeviceRegistrationResult dpsRegistrationResult = await ProvisionDeviceAsync(parameters, cancellationToken);
var authMethod = new ClientAuthenticationWithRegistrySymmetricKey(parameters.DeviceSymmetricKey, dpsRegistrationResult.DeviceId);
var authMethod = new ClientAuthenticationWithSharedAccessKeyRefresh(parameters.DeviceSymmetricKey, dpsRegistrationResult.DeviceId);
deviceClient = InitializeDeviceClient(dpsRegistrationResult.AssignedHub, authMethod);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static async Task<IotHubDeviceClient> SetupDeviceClientAsync(Parameters
case "dps":
logger.LogDebug($"Initializing via DPS");
DeviceRegistrationResult dpsRegistrationResult = await ProvisionDeviceAsync(parameters, cancellationToken);
var authMethod = new ClientAuthenticationWithRegistrySymmetricKey(parameters.DeviceSymmetricKey, dpsRegistrationResult.DeviceId);
var authMethod = new ClientAuthenticationWithSharedAccessKeyRefresh(parameters.DeviceSymmetricKey, dpsRegistrationResult.DeviceId);
deviceClient = InitializeDeviceClient(dpsRegistrationResult.AssignedHub, authMethod);
break;

Expand Down
143 changes: 0 additions & 143 deletions iothub/device/src/Authentication/AuthenticationWithTokenRefresh.cs

This file was deleted.

This file was deleted.

0 comments on commit 27efde5

Please sign in to comment.