1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 15:53:59 +00:00
Files
server/src/Api/Utilities/ServiceCollectionExtensions.cs
renovate[bot] b7dc9feb0e [deps] Vault: Update aspnet-health-checks monorepo (major) (#3294)
* [deps] Vault: Update aspnet-health-checks monorepo

* [PM-5249] Add updated Azure Storage Queues health check package that was split from the original Azure Storage health check package

* [PM-5249] Remove Azure Queue Storage health checks and dependencies

* [PM-5249] Remove unused Redis, Service Bus, and SendGrid health checks

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Shane Melton <smelton@bitwarden.com>
2024-02-28 11:42:45 -08:00

106 lines
4.1 KiB
C#

using Bit.Api.Vault.AuthorizationHandlers.Collections;
using Bit.Api.Vault.AuthorizationHandlers.Groups;
using Bit.Api.Vault.AuthorizationHandlers.OrganizationUsers;
using Bit.Core.IdentityServer;
using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.SharedWeb.Health;
using Bit.SharedWeb.Swagger;
using Microsoft.AspNetCore.Authorization;
using Microsoft.OpenApi.Models;
namespace Bit.Api.Utilities;
public static class ServiceCollectionExtensions
{
public static void AddSwagger(this IServiceCollection services, GlobalSettings globalSettings)
{
services.AddSwaggerGen(config =>
{
config.SwaggerDoc("public", new OpenApiInfo
{
Title = "Bitwarden Public API",
Version = "latest",
Contact = new OpenApiContact
{
Name = "Bitwarden Support",
Url = new Uri("https://bitwarden.com"),
Email = "support@bitwarden.com"
},
Description = "The Bitwarden public APIs.",
License = new OpenApiLicense
{
Name = "GNU Affero General Public License v3.0",
Url = new Uri("https://github.com/bitwarden/server/blob/master/LICENSE.txt")
}
});
config.SwaggerDoc("internal", new OpenApiInfo { Title = "Bitwarden Internal API", Version = "latest" });
config.AddSecurityDefinition("oauth2-client-credentials", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
ClientCredentials = new OpenApiOAuthFlow
{
TokenUrl = new Uri($"{globalSettings.BaseServiceUri.Identity}/connect/token"),
Scopes = new Dictionary<string, string>
{
{ ApiScopes.ApiOrganization, "Organization APIs" },
},
}
},
});
config.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2-client-credentials"
},
},
new[] { ApiScopes.ApiOrganization }
}
});
config.DescribeAllParametersInCamelCase();
// config.UseReferencedDefinitionsForEnums();
config.SchemaFilter<EnumSchemaFilter>();
var apiFilePath = Path.Combine(AppContext.BaseDirectory, "Api.xml");
config.IncludeXmlComments(apiFilePath, true);
var coreFilePath = Path.Combine(AppContext.BaseDirectory, "Core.xml");
config.IncludeXmlComments(coreFilePath);
});
}
public static void AddHealthChecks(this IServiceCollection services, GlobalSettings globalSettings)
{
services.AddHealthCheckServices(globalSettings, builder =>
{
var identityUri = new Uri(globalSettings.BaseServiceUri.Identity
+ "/.well-known/openid-configuration");
builder.AddUrlGroup(identityUri, "identity");
if (CoreHelpers.SettingHasValue(globalSettings.SqlServer.ConnectionString))
{
builder.AddSqlServer(globalSettings.SqlServer.ConnectionString);
}
});
}
public static void AddAuthorizationHandlers(this IServiceCollection services)
{
services.AddScoped<IAuthorizationHandler, BulkCollectionAuthorizationHandler>();
services.AddScoped<IAuthorizationHandler, CollectionAuthorizationHandler>();
services.AddScoped<IAuthorizationHandler, GroupAuthorizationHandler>();
services.AddScoped<IAuthorizationHandler, OrganizationUserAuthorizationHandler>();
}
}