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(IDeviceIdentity deviceIdentity, AmqpIotCbsLink amqpCbsLink) { _amqpIotCbsLink = amqpCbsLink; _connectionString = deviceIdentity.IotHubConnectionString; _audience = deviceIdentity.Audience; _amqpIotCbsTokenProvider = new AmqpIotCbsTokenProvider(_connectionString); if (Logging.IsEnabled) { Logging.Associate(this, deviceIdentity, nameof(DeviceIdentity)); Logging.Associate(this, amqpCbsLink, nameof(_amqpIotCbsLink)); } }