Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SharedAccessKeyAuthenticationAttribute"/> class.
        /// </summary>
        /// <param name="headerName">The name of the request header which value must match the stored secret.</param>
        /// <param name="queryParameterName">The name of the query parameter which value must match the stored secret.</param>
        /// <param name="secretName">The name of the secret that's being retrieved using the <see cref="ISecretProvider.GetRawSecretAsync"/> call.</param>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="secretName"/> is blank.</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="headerName"/> and the <paramref name="queryParameterName"/> are blank.</exception>
        public SharedAccessKeyAuthenticationAttribute(string secretName, string headerName = null, string queryParameterName = null)
            : base(typeof(SharedAccessKeyAuthenticationFilter))
        {
            Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Secret name cannot be blank");
            Guard.For <ArgumentException>(
                () => String.IsNullOrWhiteSpace(headerName) && String.IsNullOrWhiteSpace(queryParameterName),
                "Requires either a non-blank header name or query parameter name");

            _options  = new SharedAccessKeyAuthenticationOptions();
            Arguments = new object[] { headerName ?? String.Empty, queryParameterName ?? String.Empty, secretName, _options };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SharedAccessKeyAuthenticationFilter"/> class.
        /// </summary>
        /// <param name="headerName">The name of the request header which value must match the stored secret.</param>
        /// <param name="queryParameterName">The name of the query parameter which value must match the stored secret.</param>
        /// <param name="secretName">The name of the secret that's being retrieved using the <see cref="ISecretProvider.GetRawSecretAsync"/> call.</param>
        /// <param name="options">The set of additional consumer-configurable options to change the behavior of the shared access authentication.</param>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="secretName"/> is blank.</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="headerName"/> and <paramref name="queryParameterName"/> are blank.</exception>
        public SharedAccessKeyAuthenticationFilter(string headerName, string queryParameterName, string secretName, SharedAccessKeyAuthenticationOptions options)
        {
            Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Requires a non-blank secret name");
            Guard.For <ArgumentException>(
                () => String.IsNullOrWhiteSpace(headerName) && String.IsNullOrWhiteSpace(queryParameterName),
                "Requires either a non-blank header name or query parameter name");

            _headerName         = headerName;
            _queryParameterName = queryParameterName;
            _secretName         = secretName;
            _options            = options;
        }