Пример #1
0
        public ApiExplorerBuilder AddSecurityScheme(string scheme, SecuritySchemeType type)
        {
            Services.Configure <SwaggerGenOptions>(options =>
            {
                options.AddSecurityDefinition(scheme, new OpenApiSecurityScheme
                {
                    Scheme = scheme,
                    Type   = type
                });

                options.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference()
                            {
                                Id   = scheme,
                                Type = ReferenceType.SecurityScheme
                            }
                        },
                        Array.Empty <string>()
                    }
                });
            });

            return(this);
        }
        public void Given_Value_Property_Should_Return_Value(string schemeName, SecuritySchemeType schemeType)
        {
            var attribute = new OpenApiSecurityAttribute(schemeName, schemeType);

            attribute.SchemeName.Should().Be(schemeName);
            attribute.SchemeType.Should().Be(schemeType);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SharedAccessKeyAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"sharedaccesskey"</c>.</param>
        /// <param name="securitySchemeType">The type of the security scheme. Default value is <c>ApiKey</c>.</param>
        public SharedAccessKeyAuthenticationOperationFilter(
            string securitySchemeName             = DefaultSecuritySchemeName,
            SecuritySchemeType securitySchemeType = SecuritySchemeType.ApiKey)
        {
            Guard.NotNullOrWhitespace(securitySchemeName, nameof(securitySchemeName), "Requires a name for the Shared Access Key security scheme");
            Guard.For <ArgumentException>(
                () => !Enum.IsDefined(typeof(SecuritySchemeType), securitySchemeType),
                "Requires a security scheme type for the Shared Access Key authentication that is within the bounds of the enumeration");

            _securitySchemeName = securitySchemeName;
            _securitySchemeType = securitySchemeType;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CertificateAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"certificate"</c>.</param>
        /// <param name="securitySchemeType">The type of the security scheme. Default value is <c>ApiKey</c>.</param>
#else
        /// <summary>
        /// Initializes a new instance of the <see cref="CertificateAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"certificate"</c>.</param>
#endif
        public CertificateAuthenticationOperationFilter(
#if !NETSTANDARD2_1
            string securitySchemeName             = DefaultSecuritySchemeName,
            SecuritySchemeType securitySchemeType = SecuritySchemeType.ApiKey
Пример #5
0
 public SecurityScheme(SecuritySchemeType type)
 {
     Type = type;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecurityDefinition"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 public SecurityDefinition(string name, SecuritySchemeType type)
 {
     Name = name;
     Type = type;
 }
Пример #7
0
        private static void GetAuthDefinitionValues(ApiAuthenticationType type, out string authName, out string scheme, out string description, out ParameterLocation loc, out SecuritySchemeType securitySchemeType)
        {
            authName           = string.Empty;
            scheme             = string.Empty;
            description        = string.Empty;
            loc                = ParameterLocation.Header;
            securitySchemeType = SecuritySchemeType.ApiKey;
            switch (type)
            {
            case ApiAuthenticationType.Basic:
                scheme             = nameof(ApiAuthenticationType.Basic);
                authName           = $"{scheme} Authentication";
                description        = $"{scheme} Authentication with user and password.";
                securitySchemeType = SecuritySchemeType.Http;
                break;

            case ApiAuthenticationType.Bearer:
                scheme             = nameof(ApiAuthenticationType.Bearer);
                authName           = $"Jwt {scheme} Authentication";
                description        = $"{scheme} Authentication with jwt token.";
                securitySchemeType = SecuritySchemeType.ApiKey;
                break;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenApiSecurityAttribute"/> class.
 /// </summary>
 /// <param name="schemeName">Open API security scheme name.</param>
 /// <param name="schemeType">Open API security scheme type.</param>
 public OpenApiSecurityAttribute(string schemeName, SecuritySchemeType schemeType)
 {
     this.SchemeName = schemeName ?? throw new ArgumentNullException(nameof(schemeName));
     this.SchemeType = schemeType;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CertificateAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"certificate"</c>.</param>
        /// <param name="securitySchemeType">The type of the security scheme. Default value is <c>ApiKey</c>.</param>
#else
        /// <summary>
        /// Initializes a new instance of the <see cref="CertificateAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"certificate"</c>.</param>
#endif
        public CertificateAuthenticationOperationFilter(
#if NETCOREAPP3_1
            string securitySchemeName             = DefaultSecuritySchemeName,
            SecuritySchemeType securitySchemeType = SecuritySchemeType.ApiKey
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SharedAccessKeyAuthenticationOperationFilter"/> class.
        /// </summary>
        /// <param name="securitySchemeName">The name of the security scheme. Default value is <c>"sharedaccesskey"</c>.</param>
#if NETCOREAPP3_1
        /// <param name="securitySchemeType">The type of the security scheme. Default value is <c>ApiKey</c>.</param>
#endif
        public SharedAccessKeyAuthenticationOperationFilter(
#if NETCOREAPP3_1
            string securitySchemeName             = DefaultSecuritySchemeName,
            SecuritySchemeType securitySchemeType = SecuritySchemeType.ApiKey