Files
server/src/Api/Utilities/ServiceCollectionExtensions.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.7 KiB
C#
Raw Normal View History

using Bit.Core.IdentityServer;
using Bit.Core.Settings;
2020-01-10 09:36:12 -05:00
using Microsoft.OpenApi.Models;
2019-02-28 14:20:14 -05:00
namespace Bit.Api.Utilities;
2022-08-29 16:06:55 -04:00
2019-02-28 14:20:14 -05:00
public static class ServiceCollectionExtensions
{
public static void AddSwagger(this IServiceCollection services, GlobalSettings globalSettings)
{
services.AddSwaggerGen(config =>
{
config.SwaggerDoc("public", new OpenApiInfo
{
2020-01-10 09:36:12 -05:00
Title = "Bitwarden Public API",
Version = "latest",
Contact = new OpenApiContact
2019-03-07 14:06:02 -05:00
{
Name = "Bitwarden Support",
2020-01-10 09:36:12 -05:00
Url = new Uri("https://bitwarden.com"),
2019-03-07 14:06:02 -05:00
Email = "support@bitwarden.com"
},
2019-03-07 14:06:02 -05:00
Description = "The Bitwarden public APIs.",
2020-01-10 09:36:12 -05:00
License = new OpenApiLicense
{
2019-03-07 14:06:02 -05:00
Name = "GNU Affero General Public License v3.0",
2020-01-10 09:36:12 -05:00
Url = new Uri("https://github.com/bitwarden/server/blob/master/LICENSE.txt")
2019-03-07 14:06:02 -05:00
}
});
2020-01-10 09:36:12 -05:00
config.SwaggerDoc("internal", new OpenApiInfo { Title = "Bitwarden Internal API", Version = "latest" });
2019-02-28 14:20:14 -05:00
2022-09-15 17:14:35 +02:00
config.AddSecurityDefinition("oauth2-client-credentials", new OpenApiSecurityScheme
2022-08-29 16:06:55 -04:00
{
2020-01-10 09:36:12 -05:00
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
2019-02-28 14:20:14 -05:00
{
2020-01-10 09:36:12 -05:00
ClientCredentials = new OpenApiOAuthFlow
2019-02-28 14:20:14 -05:00
{
2020-01-10 09:36:12 -05:00
TokenUrl = new Uri($"{globalSettings.BaseServiceUri.Identity}/connect/token"),
Scopes = new Dictionary<string, string>
{
{ ApiScopes.ApiOrganization, "Organization APIs" },
2020-01-10 09:36:12 -05:00
},
}
2019-02-28 14:20:14 -05:00
},
});
2020-01-10 09:36:12 -05:00
config.AddSecurityRequirement(new OpenApiSecurityRequirement
2022-08-29 16:06:55 -04:00
{
2019-02-28 14:20:14 -05:00
{
2020-01-10 09:36:12 -05:00
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
2022-09-15 17:14:35 +02:00
Id = "oauth2-client-credentials"
2020-01-10 09:36:12 -05:00
},
2022-08-29 16:06:55 -04:00
},
new[] { ApiScopes.ApiOrganization }
2020-01-10 09:36:12 -05:00
}
2019-02-28 14:20:14 -05:00
});
2019-02-28 20:50:40 -05:00
config.DescribeAllParametersInCamelCase();
// config.UseReferencedDefinitionsForEnums();
2019-03-01 09:34:07 -05:00
2020-01-10 09:36:12 -05:00
var apiFilePath = Path.Combine(AppContext.BaseDirectory, "Api.xml");
2019-03-01 09:34:07 -05:00
config.IncludeXmlComments(apiFilePath, true);
2020-01-10 09:36:12 -05:00
var coreFilePath = Path.Combine(AppContext.BaseDirectory, "Core.xml");
2019-03-01 09:34:07 -05:00
config.IncludeXmlComments(coreFilePath);
2019-02-28 14:20:14 -05:00
});
}
}