/// <summary> /// Creates a <see cref="ServiceClient"/> using Azure Active Directory credentials and the specified transport type. /// </summary> /// <param name="hostName">IoT hub host name.</param> /// <param name="credential">Azure Active Directory credentials to authenticate with IoT hub. See <see cref="TokenCredential"/></param> /// <param name="transportType">Specifies whether Amqp or Amqp_WebSocket_Only transport is used.</param> /// <param name="transportSettings">Specifies the AMQP_WS and HTTP proxy settings for service client.</param> /// <param name="options">The options that allow configuration of the service client instance during initialization.</param> /// <returns>An instance of <see cref="ServiceClient"/>.</returns> public static ServiceClient Create( string hostName, TokenCredential credential, TransportType transportType = TransportType.Amqp, ServiceClientTransportSettings transportSettings = default, ServiceClientOptions options = default) { if (string.IsNullOrEmpty(hostName)) { throw new ArgumentNullException($"{nameof(hostName)}, Parameter cannot be null or empty"); } if (credential == null) { throw new ArgumentNullException($"{nameof(credential)}, Parameter cannot be null"); } var tokenCredentialProperties = new IotHubTokenCrendentialProperties(hostName, credential); bool useWebSocketOnly = transportType == TransportType.Amqp_WebSocket_Only; return(new AmqpServiceClient( tokenCredentialProperties, useWebSocketOnly, transportSettings ?? new ServiceClientTransportSettings(), options)); }
/// <summary> /// Creates an instance of <see cref="JobClient"/>. /// </summary> /// <param name="hostName">IoT hub host name.</param> /// <param name="credential">Azure Active Directory credentials to authenticate with IoT hub. See <see cref="TokenCredential"/></param> /// <param name="transportSettings">The HTTP transport settings.</param> /// <param name="options">Options that allow configuration of the JobClient instance during initialization.</param> /// <returns>An instance of <see cref="JobClient"/>.</returns> /// <remarks> /// For more information on configuring IoT hub with Azure Active Directory, see <see href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-dev-guide-azure-ad-rbac"/> /// This constructor sets the default for <see cref="JobClientOptions.TokenCredentialAuthenticationScopes"/> to /// <see cref="IotHubAuthenticationScopes.DefaultAuthenticationScopes"/>, which is used for any public or private cloud other than Azure US Government cloud. /// For Azure US Government cloud users, set the <see cref="JobClientOptions.TokenCredentialAuthenticationScopes"/> /// to <see cref="IotHubAuthenticationScopes.AzureGovernmentAuthenticationScopes"/>. /// </remarks> public static JobClient Create( string hostName, TokenCredential credential, HttpTransportSettings transportSettings = default, JobClientOptions options = default) { if (string.IsNullOrEmpty(hostName)) { throw new ArgumentNullException(nameof(hostName), "Parameter cannot be null or empty."); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } if (options == null) { options = new JobClientOptions(); } var tokenCredentialProperties = new IotHubTokenCrendentialProperties( hostName, credential, options.TokenCredentialAuthenticationScopes); return(new HttpJobClient(tokenCredentialProperties, transportSettings ?? new HttpTransportSettings())); }
/// <summary> /// Creates JobClient, authenticating using an identity in Azure Active Directory (AAD). /// </summary> /// <remarks> /// For more about information on the options of authenticating using a derived instance of <see cref="TokenCredential"/>, see /// <see href="https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme"/>. /// For more information on configuring IoT hub with Azure Active Directory, see /// <see href="https://docs.microsoft.com/azure/iot-hub/iot-hub-dev-guide-azure-ad-rbac"/> /// </remarks> /// <param name="hostName">IoT hub host name.</param> /// <param name="credential">Azure Active Directory (AAD) credentials to authenticate with IoT hub. See <see cref="TokenCredential"/></param> /// <param name="transportSettings">The HTTP transport settings.</param> /// <returns>A JobClient instance.</returns> public static JobClient Create( string hostName, TokenCredential credential, HttpTransportSettings transportSettings = default) { if (string.IsNullOrEmpty(hostName)) { throw new ArgumentNullException(nameof(hostName)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } var tokenCredentialProperties = new IotHubTokenCrendentialProperties(hostName, credential); return(new JobClient(tokenCredentialProperties, transportSettings ?? new HttpTransportSettings())); }