예제 #1
0
        private void AddAuth(ReRouteOptions route, OpenApiPathItem operations)
        {
            var req = new OpenApiSecurityRequirement();
            var sch = new OpenApiSecurityScheme();

            sch.Reference = new OpenApiReference()
            {
                Id   = "oauth2",
                Type = ReferenceType.SecurityScheme
            };
            req.TryAdd(sch, new List <string>());
            if (!string.IsNullOrEmpty(route.AuthenticationOptions?.AuthenticationProviderKey))
            {
                foreach (var operation in operations.Operations)
                {
                    operation.Value.Security = new List <OpenApiSecurityRequirement>();
                    operation.Value.Security.Add(req);

                    operation.Value.Responses.TryAdd("401", new OpenApiResponse()
                    {
                        Description = "Unauthorized"
                    });
                }
            }
        }