diff --git a/common/src/service/IAuthorizationHeaderProvider.cs b/common/src/service/IAuthorizationHeaderProvider.cs
index 207526a168..798ce5bfdb 100644
--- a/common/src/service/IAuthorizationHeaderProvider.cs
+++ b/common/src/service/IAuthorizationHeaderProvider.cs
@@ -3,7 +3,10 @@
namespace Microsoft.Azure.Devices
{
- interface IAuthorizationHeaderProvider
+ ///
+ /// Gets the authorization header for authenticated requests, regardless of choice of authentication.
+ ///
+ internal interface IAuthorizationHeaderProvider
{
string GetAuthorizationHeader();
}
diff --git a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinConnectionStringCredential.cs b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinConnectionStringCredential.cs
index 03838d7f40..a33d30c151 100644
--- a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinConnectionStringCredential.cs
+++ b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinConnectionStringCredential.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Azure.Devices.Authentication
///
/// Allows authentication to the API using a Shared Access Key generated from the connection string provided.
/// The PnP client is auto generated from swagger and needs to implement a specific class to pass to the protocol layer
- /// unlike the rest of the clients which are hand-written. So, this implementation for authentication is specific to digital twin (Pnp).
+ /// unlike the rest of the clients which are hand-written. So, this implementation for authentication is specific to digital twin (PnP).
///
internal class DigitalTwinConnectionStringCredential : DigitalTwinServiceClientCredentials
{
diff --git a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinSasCredential.cs b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinSasCredential.cs
index eb93a2e9ec..02d0a7bd2a 100644
--- a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinSasCredential.cs
+++ b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinSasCredential.cs
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using System;
-using System.Collections.Generic;
-using System.Text;
+
using Azure;
using Microsoft.Azure.Devices.Authentication;
@@ -11,11 +9,11 @@ namespace Microsoft.Azure.Devices.DigitalTwin.Authentication
///
/// Allows authentication to the API using a Shared Access Key provided by custom implementation.
/// The PnP client is auto generated from swagger and needs to implement a specific class to pass to the protocol layer
- /// unlike the rest of the clients which are hand-written. So, this implementation for authentication is specific to digital twin (Pnp).
+ /// unlike the rest of the clients which are hand-written. So, this implementation for authentication is specific to digital twin (PnP).
///
internal class DigitalTwinSasCredential : DigitalTwinServiceClientCredentials
{
- private AzureSasCredential _credential;
+ private readonly AzureSasCredential _credential;
public DigitalTwinSasCredential(AzureSasCredential credential)
{
diff --git a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinTokenCredential.cs b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinTokenCredential.cs
index 3b0bc31fe7..51a816e4b4 100644
--- a/iothub/service/src/DigitalTwin/Authentication/DigitalTwinTokenCredential.cs
+++ b/iothub/service/src/DigitalTwin/Authentication/DigitalTwinTokenCredential.cs
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using System;
-using System.Collections.Generic;
-using System.Text;
+
using System.Threading;
using Azure.Core;
using Microsoft.Azure.Devices.Authentication;
@@ -19,7 +17,7 @@ internal class DigitalTwinTokenCredential : DigitalTwinServiceClientCredentials
{
private readonly object _tokenLock = new object();
private AccessToken? _cachedAccessToken;
- private TokenCredential _credential;
+ private readonly TokenCredential _credential;
public DigitalTwinTokenCredential(TokenCredential credential)
{
diff --git a/iothub/service/src/IAuthenticationMethod.cs b/iothub/service/src/IAuthenticationMethod.cs
index 67abe5b9b8..5e7930a505 100644
--- a/iothub/service/src/IAuthenticationMethod.cs
+++ b/iothub/service/src/IAuthenticationMethod.cs
@@ -4,7 +4,7 @@
namespace Microsoft.Azure.Devices
{
///
- /// Authentication interface to use for IoTHub communications.
+ /// Authentication interface to use for IoT hub communications.
///
public interface IAuthenticationMethod
{
diff --git a/iothub/service/src/IotHubConnectionProperties.cs b/iothub/service/src/IotHubConnectionProperties.cs
index 89162d50c4..f3816297c8 100644
--- a/iothub/service/src/IotHubConnectionProperties.cs
+++ b/iothub/service/src/IotHubConnectionProperties.cs
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
using System;
using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Amqp;
using Microsoft.Azure.Devices.Common;
diff --git a/iothub/service/src/IotHubSasCredentialProperties.cs b/iothub/service/src/IotHubSasCredentialProperties.cs
index 0af2131065..933f400cd1 100644
--- a/iothub/service/src/IotHubSasCredentialProperties.cs
+++ b/iothub/service/src/IotHubSasCredentialProperties.cs
@@ -1,17 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Amqp;
-using System.Globalization;
-using System.Linq;
-using Microsoft.Azure.Devices.Common.Data;
#if !NET451
+using System.Collections.Generic;
+using System.Linq;
using Azure;
+using Microsoft.Azure.Devices.Common.Data;
#endif
diff --git a/iothub/service/src/IotHubTokenCredentialProperties.cs b/iothub/service/src/IotHubTokenCredentialProperties.cs
index 3591a66038..1efa16ecf2 100644
--- a/iothub/service/src/IotHubTokenCredentialProperties.cs
+++ b/iothub/service/src/IotHubTokenCredentialProperties.cs
@@ -1,16 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Amqp;
-using System.Threading;
-using Microsoft.Azure.Devices.Common;
#if !NET451
+using System.Threading;
using Azure.Core;
+using Microsoft.Azure.Devices.Common;
#endif
@@ -23,7 +22,7 @@ internal class IotHubTokenCrendentialProperties
: IotHubConnectionProperties
{
#if !NET451
- private const string _tokenType = "Bearer";
+ private const string TokenType = "Bearer";
private readonly TokenCredential _credential;
private readonly object _tokenLock = new object();
private AccessToken? _cachedAccessToken;
@@ -63,8 +62,7 @@ public override string GetAuthorizationHeader()
}
}
- return $"{_tokenType} {_cachedAccessToken.Value.Token}";
-
+ return $"{TokenType} {_cachedAccessToken.Value.Token}";
#endif
}
@@ -82,8 +80,8 @@ public async override Task GetTokenAsync(Uri namespaceAddress, string
new TokenRequestContext(CommonConstants.IotHubAadTokenScopes),
new CancellationToken()).ConfigureAwait(false);
return new CbsToken(
- $"{_tokenType} {token.Token}",
- _tokenType,
+ $"{TokenType} {token.Token}",
+ TokenType,
token.ExpiresOn.UtcDateTime);
#endif
}
diff --git a/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyKey.cs b/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyKey.cs
index 21bf338279..24d778c146 100644
--- a/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyKey.cs
+++ b/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyKey.cs
@@ -21,6 +21,16 @@ public ServiceAuthenticationWithDeviceSharedAccessPolicyKey(string deviceId, str
Key = sharedAccessKey;
}
+ ///
+ /// Shared access key of the device
+ ///
+ public string Key { get; set; }
+
+ ///
+ /// Name of device
+ ///
+ public string DeviceId { get; set; }
+
///
/// Populates the builder with values needed to authenticate with device's shared access key.
///
@@ -33,21 +43,11 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
throw new ArgumentNullException(nameof(iotHubConnectionStringBuilder));
}
- iotHubConnectionStringBuilder.SharedAccessKey = this.Key;
- iotHubConnectionStringBuilder.DeviceId = this.DeviceId;
+ iotHubConnectionStringBuilder.SharedAccessKey = Key;
+ iotHubConnectionStringBuilder.DeviceId = DeviceId;
iotHubConnectionStringBuilder.SharedAccessSignature = null;
return iotHubConnectionStringBuilder;
}
-
- ///
- /// Shared access key of the device
- ///
- public string Key { get; set; }
-
- ///
- /// Name of device
- ///
- public string DeviceId { get; set; }
}
}
diff --git a/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyToken.cs b/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyToken.cs
index 0d207fc9c6..d49772bb77 100644
--- a/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyToken.cs
+++ b/iothub/service/src/ServiceAuthenticationWithDeviceSharedAccessPolicyToken.cs
@@ -21,6 +21,16 @@ public ServiceAuthenticationWithDeviceSharedAccessPolicyToken(string deviceId, s
Token = sharedAccessSignature;
}
+ ///
+ /// Name of device
+ ///
+ public string DeviceId { get; set; }
+
+ ///
+ /// Shared access signature generated using device's shared access key
+ ///
+ public string Token { get; set; }
+
///
/// Populates the builder with values needed to authenticate with device's shared access signature.
///
@@ -34,20 +44,10 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
}
iotHubConnectionStringBuilder.SharedAccessKey = null;
- iotHubConnectionStringBuilder.DeviceId = this.DeviceId;
- iotHubConnectionStringBuilder.SharedAccessSignature = this.Token;
+ iotHubConnectionStringBuilder.DeviceId = DeviceId;
+ iotHubConnectionStringBuilder.SharedAccessSignature = Token;
return iotHubConnectionStringBuilder;
}
-
- ///
- /// Name of device
- ///
- public string DeviceId { get; set; }
-
- ///
- /// Shared access signature generated using device's shared access key
- ///
- public string Token { get; set; }
}
}
diff --git a/iothub/service/src/ServiceAuthenticationWithSharedAccessPolicyKey.cs b/iothub/service/src/ServiceAuthenticationWithSharedAccessPolicyKey.cs
index c30cfda7f8..b6bd3c6887 100644
--- a/iothub/service/src/ServiceAuthenticationWithSharedAccessPolicyKey.cs
+++ b/iothub/service/src/ServiceAuthenticationWithSharedAccessPolicyKey.cs
@@ -31,7 +31,7 @@ public ServiceAuthenticationWithSharedAccessPolicyKey(string policyName, string
public string PolicyName
{
get => _policyName;
- set { SetPolicyName(value); }
+ set => SetPolicyName(value);
}
///