11using Bit . Api . AdminConsole . Authorization ;
22using Bit . Api . Tools . Authorization ;
3- using Bit . Core . Auth . IdentityServer ;
43using Bit . Core . PhishingDomainFeatures ;
54using Bit . Core . PhishingDomainFeatures . Interfaces ;
65using Bit . Core . Repositories ;
109using Bit . Core . Vault . Authorization . SecurityTasks ;
1110using Bit . SharedWeb . Health ;
1211using Bit . SharedWeb . Swagger ;
12+ using Bit . SharedWeb . Utilities ;
1313using Microsoft . AspNetCore . Authorization ;
1414using Microsoft . OpenApi . Models ;
1515
1616namespace Bit . Api . Utilities ;
1717
1818public static class ServiceCollectionExtensions
1919{
20- public static void AddSwagger ( this IServiceCollection services , GlobalSettings globalSettings , IWebHostEnvironment environment )
20+ /// <summary>
21+ /// Configures the generation of swagger.json OpenAPI spec.
22+ /// </summary>
23+ public static void AddSwaggerGen ( this IServiceCollection services , GlobalSettings globalSettings , IWebHostEnvironment environment )
2124 {
2225 services . AddSwaggerGen ( config =>
2326 {
@@ -36,6 +39,8 @@ public static void AddSwagger(this IServiceCollection services, GlobalSettings g
3639 organizations tools for managing members, collections, groups, event logs, and policies.
3740 If you are looking for the Vault Management API, refer instead to
3841 [this document](https://bitwarden.com/help/vault-management-api/).
42+
43+ **Note:** your authorization must match the server you have selected.
3944 """ ,
4045 License = new OpenApiLicense
4146 {
@@ -46,36 +51,20 @@ [this document](https://bitwarden.com/help/vault-management-api/).
4651
4752 config . SwaggerDoc ( "internal" , new OpenApiInfo { Title = "Bitwarden Internal API" , Version = "latest" } ) ;
4853
49- config . AddSecurityDefinition ( "oauth2-client-credentials" , new OpenApiSecurityScheme
50- {
51- Type = SecuritySchemeType . OAuth2 ,
52- Flows = new OpenApiOAuthFlows
53- {
54- ClientCredentials = new OpenApiOAuthFlow
55- {
56- TokenUrl = new Uri ( $ "{ globalSettings . BaseServiceUri . Identity } /connect/token") ,
57- Scopes = new Dictionary < string , string >
58- {
59- { ApiScopes . ApiOrganization , "Organization APIs" } ,
60- } ,
61- }
62- } ,
63- } ) ;
64-
65- config . AddSecurityRequirement ( new OpenApiSecurityRequirement
66- {
67- {
68- new OpenApiSecurityScheme
69- {
70- Reference = new OpenApiReference
71- {
72- Type = ReferenceType . SecurityScheme ,
73- Id = "oauth2-client-credentials"
74- } ,
75- } ,
76- new [ ] { ApiScopes . ApiOrganization }
77- }
78- } ) ;
54+ // Configure Bitwarden cloud US and EU servers. These will appear in the swagger.json build artifact
55+ // used for our help center. These are overwritten with the local server when running in self-hosted
56+ // or dev mode (see Api Startup.cs).
57+ config . AddSwaggerServerWithSecurity (
58+ serverId : "US_server" ,
59+ serverUrl : "https://api.bitwarden.com" ,
60+ identityTokenUrl : "https://identity.bitwarden.com/connect/token" ,
61+ serverDescription : "US server" ) ;
62+
63+ config . AddSwaggerServerWithSecurity (
64+ serverId : "EU_server" ,
65+ serverUrl : "https://api.bitwarden.eu" ,
66+ identityTokenUrl : "https://identity.bitwarden.eu/connect/token" ,
67+ serverDescription : "EU server" ) ;
7968
8069 config . DescribeAllParametersInCamelCase ( ) ;
8170 // config.UseReferencedDefinitionsForEnums();
0 commit comments