public async Task DeviceAuthenticationWithSakRefresh_SharedAccessKeyConnectionString_HasRefresher() { var csBuilder = IotHubConnectionStringBuilder.Create( TestIoTHubName, new DeviceAuthenticationWithRegistrySymmetricKey(TestDeviceId, TestSharedAccessKey)); IotHubConnectionString cs = csBuilder.ToIotHubConnectionString(); Assert.IsNotNull(cs.TokenRefresher); Assert.IsInstanceOfType(cs.TokenRefresher, typeof(DeviceAuthenticationWithSakRefresh)); var auth = (IAuthorizationProvider)cs; var cbsAuth = new AmqpIoTCbsTokenProvider(cs); string token1 = await auth.GetPasswordAsync().ConfigureAwait(false); CbsToken token2 = await cbsAuth.GetTokenAsync(new Uri("amqp://" + TestIoTHubName), "testAppliesTo", null).ConfigureAwait(false); Assert.IsNull(cs.SharedAccessSignature); Assert.AreEqual(TestDeviceId, cs.DeviceId); Assert.IsNotNull(token1); Assert.IsNotNull(token2); Assert.AreEqual(token1, token2.TokenValue); }
internal AmqpAuthenticationRefresher(DeviceIdentity deviceIdentity, AmqpIoTCbsLink amqpCbsLink) { _amqpIoTCbsLink = amqpCbsLink; _connectionString = deviceIdentity.IotHubConnectionString; _operationTimeout = deviceIdentity.AmqpTransportSettings.OperationTimeout; _audience = deviceIdentity.Audience; _amqpIoTCbsTokenProvider = new AmqpIoTCbsTokenProvider(_connectionString); if (Logging.IsEnabled) { Logging.Associate(this, deviceIdentity, $"{nameof(DeviceIdentity)}"); } if (Logging.IsEnabled) { Logging.Associate(this, amqpCbsLink, $"{nameof(_amqpIoTCbsLink)}"); } }