internal static IAuthenticationMethod GetAuthenticationMethod(ServiceConnectionStringBuilder iotHubConnectionStringBuilder)
        {
            if (string.IsNullOrWhiteSpace(iotHubConnectionStringBuilder.SharedAccessKey))
            {
                return(new ServiceAuthenticationWithSharedAccessPolicyToken(iotHubConnectionStringBuilder.SharedAccessKeyName, iotHubConnectionStringBuilder.SharedAccessSignature));
            }
            else if (string.IsNullOrWhiteSpace(iotHubConnectionStringBuilder.SharedAccessSignature))
            {
                return(new ServiceAuthenticationWithSharedAccessPolicyKey(iotHubConnectionStringBuilder.SharedAccessKeyName, iotHubConnectionStringBuilder.SharedAccessKey));
            }

            throw new InvalidOperationException("Unsupported Authentication Method {0}".FormatInvariant(iotHubConnectionStringBuilder));
        }
        public ServiceConnectionStringBuilder Populate(ServiceConnectionStringBuilder provisioningConnectionStringBuilder)
        {
            if (provisioningConnectionStringBuilder == null)
            {
                throw new ArgumentNullException(nameof(provisioningConnectionStringBuilder));
            }

            provisioningConnectionStringBuilder.SharedAccessKey       = this.Key;
            provisioningConnectionStringBuilder.SharedAccessKeyName   = this.PolicyName;
            provisioningConnectionStringBuilder.SharedAccessSignature = null;

            return(provisioningConnectionStringBuilder);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Factory for new Connection String object.
        /// </summary>
        /// <remarks>
        /// The connection string contains a set of information that uniquely identify an IoT Service.
        ///
        /// A valid connection string shall be in the following format:
        /// <code>
        /// HostName=[ServiceName];SharedAccessKeyName=[keyName];SharedAccessKey=[Key]
        /// </code>
        ///
        /// This object parse the connection string providing the artifacts to the <see cref="ServiceConnectionString"/> object.
        /// </remarks>
        /// <param name="serviceConnectionString">the <code>string</code> with the connection string information.</param>
        /// <returns>A <code>ServiceConnectionStringBuilder</code> object with the parsed connection string.</returns>
        public static ServiceConnectionStringBuilder Create(string serviceConnectionString)
        {
            if (string.IsNullOrWhiteSpace(serviceConnectionString))
            {
                throw new ArgumentNullException("serviceConnectionString");
            }

            var serviceConnectionStringBuilder = new ServiceConnectionStringBuilder();

            serviceConnectionStringBuilder.Parse(serviceConnectionString);
            serviceConnectionStringBuilder.AuthenticationMethod = AuthenticationMethodFactory.GetAuthenticationMethod(serviceConnectionStringBuilder);

            return(serviceConnectionStringBuilder);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// CONSTRUCOR
        /// </summary>
        /// <param name="builder">the <see cref="ServiceConnectionStringBuilder"/> with the connection string content.</param>
        /// <exception cref="ArgumentNullException">if the provided builder is null.</exception>
        public ServiceConnectionString(ServiceConnectionStringBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            HostName              = builder.HostName;
            SharedAccessKeyName   = builder.SharedAccessKeyName;
            SharedAccessKey       = builder.SharedAccessKey;
            SharedAccessSignature = builder.SharedAccessSignature;
            ServiceName           = builder.ServiceName;
            HttpsEndpoint         = new UriBuilder("https", builder.HostName).Uri;
        }
Ejemplo n.º 5
0
        public static ServiceConnectionString Parse(string connectionString)
        {
            var builder = ServiceConnectionStringBuilder.Create(connectionString);

            return(new ServiceConnectionString(builder));
        }