Skip to content

Commit

Permalink
Merge pull request abpframework#6818 from abpframework/liangshiwei/sw…
Browse files Browse the repository at this point in the history
…agger

Enabled swagger login for HostWithIds project
  • Loading branch information
ebicoglu authored Dec 25, 2020
2 parents 45d694b + e3082f6 commit b522ae6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private static void ConfigureWithoutUi(ProjectBuildContext context, List<Project
if (context.BuildArgs.ExtraProperties.ContainsKey("separate-identity-server"))
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
}
else
{
Expand All @@ -123,6 +124,7 @@ private static void ConfigureWithBlazorUi(ProjectBuildContext context, List<Proj
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
steps.Add(new BlazorAppsettingsFilePortChangeForSeparatedIdentityServersStep());
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
}
else
{
Expand All @@ -140,6 +142,7 @@ private static void ConfigureWithMvcUi(ProjectBuildContext context, List<Project
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests"));
steps.Add(new AppTemplateProjectRenameStep("MyCompanyName.MyProjectName.Web.Host", "MyCompanyName.MyProjectName.Web"));
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));
}
else
{
Expand All @@ -162,6 +165,7 @@ private static void ConfigureWithAngularUi(ProjectBuildContext context, List<Pro
{
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.HttpApi.HostWithIds"));
steps.Add(new AngularEnvironmentFilePortChangeForSeparatedIdentityServersStep());
steps.Add(new AppTemplateChangeDbMigratorPortSettingsStep("44300"));

if (context.BuildArgs.MobileApp == MobileApp.ReactNative)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Files;

namespace Volo.Abp.Cli.ProjectBuilding.Templates.App
{
public class AppTemplateChangeDbMigratorPortSettingsStep : ProjectBuildPipelineStep
{
public string IdentityServerPort { get; }

/// <param name="identityServerPort"></param>
public AppTemplateChangeDbMigratorPortSettingsStep(
string identityServerPort)
{
IdentityServerPort = identityServerPort;
}

public override void Execute(ProjectBuildContext context)
{
context
.GetFile("/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json")
.ReplaceText("44305", IdentityServerPort);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"MyProjectName_Swagger": {
"ClientId": "MyProjectName_Swagger",
"ClientSecret": "1q2w3e*",
"RootUrl": "https://localhost:44300"
"RootUrl": "https://localhost:44305"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
ConfigureLocalization();
ConfigureVirtualFileSystem(context);
ConfigureCors(context, configuration);
ConfigureSwaggerServices(context);
ConfigureSwaggerServices(context, configuration);
}

private void ConfigureBundles()
Expand Down Expand Up @@ -129,9 +129,14 @@ private void ConfigureAuthentication(ServiceConfigurationContext context, IConfi
});
}

private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddSwaggerGen(
context.Services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"MyProjectName", "MyProjectName API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo {Title = "MyProjectName API", Version = "v1"});
Expand Down Expand Up @@ -216,6 +221,10 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");

var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
c.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
});

app.UseAuditing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"AuthServer": {
"Authority": "https://localhost:44305",
"RequireHttpsMetadata": "false"
"RequireHttpsMetadata": "false",
"SwaggerClientId": "MyProjectName_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"
Expand Down

0 comments on commit b522ae6

Please sign in to comment.