Skip to content

Commit b522ae6

Browse files
authored
Merge pull request abpframework#6818 from abpframework/liangshiwei/swagger
Enabled swagger login for HostWithIds project
2 parents 45d694b + e3082f6 commit b522ae6

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private static void ConfigureWithoutUi(ProjectBuildContext context, List<Project
103103
if (context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server"))
104104
{
105105
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
106+
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
106107
}
107108
else
108109
{
@@ -123,6 +124,7 @@ private static void ConfigureWithBlazorUi(ProjectBuildContext context, List<Proj
123124
{
124125
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
125126
steps.Add(new BlazorAppsettingsFilePortChangeForSeparatedIdentityServersStep());
127+
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
126128
}
127129
else
128130
{
@@ -140,6 +142,7 @@ private static void ConfigureWithMvcUi(ProjectBuildContext context, List<Project
140142
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web"));
141143
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests"));
142144
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Host", "MyCompanyName.MyProjectName.Web"));
145+
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
143146
}
144147
else
145148
{
@@ -162,6 +165,7 @@ private static void ConfigureWithAngularUi(ProjectBuildContext context, List<Pro
162165
{
163166
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
164167
steps.Add(new AngularEnvironmentFilePortChangeForSeparatedIdentityServersStep());
168+
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
165169

166170
if (context.BuildArgs.MobileApp == MobileApp.ReactNative)
167171
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Volo.Abp.Cli.ProjectBuilding.Building;
2+
using Volo.Abp.Cli.ProjectBuilding.Files;
3+
4+
namespace Volo.Abp.Cli.ProjectBuilding.Templates.App
5+
{
6+
public class AppTemplateChangeDbMigratorPortSettingsStep : ProjectBuildPipelineStep
7+
{
8+
public string IdentityServerPort { get; }
9+
10+
/// <param name="identityServerPort"></param>
11+
public AppTemplateChangeDbMigratorPortSettingsStep(
12+
string identityServerPort)
13+
{
14+
IdentityServerPort = identityServerPort;
15+
}
16+
17+
public override void Execute(ProjectBuildContext context)
18+
{
19+
context
20+
.GetFile("/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json")
21+
.ReplaceText("44305", IdentityServerPort);
22+
}
23+
}
24+
}

templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"MyProjectName_Swagger": {
2222
"ClientId": "MyProjectName_Swagger",
2323
"ClientSecret": "1q2w3e*",
24-
"RootUrl": "https://localhost:44300"
24+
"RootUrl": "https://localhost:44305"
2525
}
2626
}
2727
}

templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/MyProjectNameHttpApiHostModule.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
5858
ConfigureLocalization();
5959
ConfigureVirtualFileSystem(context);
6060
ConfigureCors(context, configuration);
61-
ConfigureSwaggerServices(context);
61+
ConfigureSwaggerServices(context, configuration);
6262
}
6363

6464
private void ConfigureBundles()
@@ -129,9 +129,14 @@ private void ConfigureAuthentication(ServiceConfigurationContext context, IConfi
129129
});
130130
}
131131

132-
private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
132+
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
133133
{
134-
context.Services.AddSwaggerGen(
134+
context.Services.AddAbpSwaggerGenWithOAuth(
135+
configuration["AuthServer:Authority"],
136+
new Dictionary<string, string>
137+
{
138+
{"MyProjectName", "MyProjectName API"}
139+
},
135140
options =>
136141
{
137142
options.SwaggerDoc("v1", new OpenApiInfo {Title = "MyProjectName API", Version = "v1"});
@@ -216,6 +221,10 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
216221
app.UseAbpSwaggerUI(c =>
217222
{
218223
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
224+
225+
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
226+
c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
227+
c.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
219228
});
220229

221230
app.UseAuditing();

templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/appsettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
},
1010
"AuthServer": {
1111
"Authority": "https://localhost:44305",
12-
"RequireHttpsMetadata": "false"
12+
"RequireHttpsMetadata": "false",
13+
"SwaggerClientId": "MyProjectName_Swagger",
14+
"SwaggerClientSecret": "1q2w3e*"
1315
},
1416
"StringEncryption": {
1517
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"

0 commit comments

Comments
 (0)