diff --git a/.gitignore b/.gitignore index 7c1b4951fa..440d5e7ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -287,3 +287,4 @@ modules/blogging/app/Volo\.BloggingTestApp/package-lock\.json templates/mvc/src/MyCompanyName\.MyProjectName\.Web/package-lock\.json samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Logs/logs.txt samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Logs/logs.txt +samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Logs/logs.txt diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj index 423afacffc..6dda5d4f19 100644 --- a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminApp.Host.csproj @@ -1,13 +1,32 @@ - + netcoreapp2.2 - InProcess + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + true + true + true + true + false + true + + + + + + + + + + + + + diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminAppHostModule.cs b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminAppHostModule.cs new file mode 100644 index 0000000000..bc550e26a0 --- /dev/null +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/BackendAdminAppHostModule.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Authentication.OAuth.Claims; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Protocols.OpenIdConnect; +using Swashbuckle.AspNetCore.Swagger; +using Volo.Abp; +using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.AspNetCore.Modularity; +using Volo.Abp.AspNetCore.Mvc.Client; +using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; +using Volo.Abp.Autofac; +using Volo.Abp.Http.Client.IdentityModel; +using Volo.Abp.Identity; +using Volo.Abp.Identity.Web; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; + +namespace BackendAdminApp.Host +{ + [DependsOn( + typeof(AbpAutofacModule), + typeof(AbpAspNetCoreMvcClientModule), + typeof(AbpAspNetCoreAuthenticationOAuthModule), + typeof(AbpHttpClientIdentityModelModule), + typeof(AbpIdentityHttpApiClientModule), + typeof(AbpIdentityWebModule), + typeof(AbpAspNetCoreMvcUiBasicThemeModule) + )] + public class BackendAdminAppHostModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.Languages.Add(new LanguageInfo("en", "en", "English")); + }); + + context.Services.AddAuthentication(options => + { + options.DefaultScheme = "Cookies"; + options.DefaultChallengeScheme = "oidc"; + }) + .AddCookie("Cookies") + .AddOpenIdConnect("oidc", options => + { + options.Authority = "http://localhost:64999"; + options.RequireHttpsMetadata = false; + options.ResponseType = OpenIdConnectResponseType.CodeIdToken; + + options.ClientId = "backend-admin-app-client"; + options.ClientSecret = "1q2w3e*"; + + options.SaveTokens = true; + options.GetClaimsFromUserInfoEndpoint = true; + + options.Scope.Add("role"); + options.Scope.Add("email"); + options.Scope.Add("phone"); + options.Scope.Add("IdentityService"); + //options.Scope.Add("ProductService"); //TODO: Enable once available + + options.ClaimActions.MapAbpClaimTypes(); + }); + + context.Services.AddSwaggerGen( + options => + { + options.SwaggerDoc("v1", new Info { Title = "Backend Admin Application API", Version = "v1" }); + options.DocInclusionPredicate((docName, description) => true); + }); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + + app.UseVirtualFiles(); + app.UseAuthentication(); + app.UseAbpRequestLocalization(); + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "Backend Admin Application API"); + }); + app.UseMvcWithDefaultRouteAndArea(); + } + } +} diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Controllers/HomeController.cs b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Controllers/HomeController.cs new file mode 100644 index 0000000000..8d90d42517 --- /dev/null +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Controllers/HomeController.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace BackendAdminApp.Host.Controllers +{ + public class HomeController : AbpController + { + public ActionResult Index() + { + return Redirect("/Identity/Users"); + } + } +} diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Program.cs b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Program.cs index cda4c7b6cf..88423094cf 100644 --- a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Program.cs +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Program.cs @@ -1,24 +1,46 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Events; namespace BackendAdminApp.Host { public class Program { - public static void Main(string[] args) + public static int Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.File("Logs/logs.txt") + .CreateLogger(); + + try + { + Log.Information("Starting BackendAdminApp.Host."); + BuildWebHostInternal(args).Run(); + return 0; + } + catch (Exception ex) + { + Log.Fatal(ex, "BackendAdminApp.Host terminated unexpectedly!"); + return 1; + } + finally + { + Log.CloseAndFlush(); + } } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IWebHost BuildWebHostInternal(string[] args) => + new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .UseSerilog() + .Build(); } } diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Startup.cs b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Startup.cs index 6cd026549d..15edcb704c 100644 --- a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Startup.cs +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/Startup.cs @@ -1,34 +1,27 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Volo.Abp; namespace BackendAdminApp.Host { public class Startup { - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) + public IServiceProvider ConfigureServices(IServiceCollection services) { + services.AddApplication(options => + { + options.UseAutofac(); + }); + + return services.BuildServiceProviderFromFactory(); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.Run(async (context) => - { - await context.Response.WriteAsync("Hello World!"); - }); + app.InitializeApplication(); } } } diff --git a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json index def9159a7d..f591f70860 100644 --- a/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json +++ b/samples/MicroserviceDemo/applications/backend/BackendAdminApp.Host/appsettings.json @@ -1,4 +1,12 @@ { + "RemoteServices": { + "Default": { + "BaseUrl": "http://localhost:63568/" + }, + "AbpMvcClient": { + "BaseUrl": "http://localhost:63568/" + } + }, "Logging": { "LogLevel": { "Default": "Warning"