Configure the blazor server tiered project

pull/8137/head
Halil İbrahim Kalkan 5 years ago
parent fbcd163683
commit 93ab2eef3f

@ -0,0 +1,4 @@
@using Microsoft.AspNetCore.Mvc.Localization
@using MyCompanyName.MyProjectName.Localization
@inject IHtmlLocalizer<MyProjectNameResource> L
<a class="nav-link" role="button" href="~/Account/Login">@L["Login"]</a>

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered.Components.Toolbar.LoginLink
{
public class LoginLinkViewComponent : AbpViewComponent
{
public virtual IViewComponentResult Invoke()
{
return View("~/Components/Toolbar/LoginLink/Default.cshtml");
}
}
}

@ -0,0 +1,4 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling

@ -0,0 +1,9 @@
using Volo.Abp.AspNetCore.Mvc.Authentication;
namespace MyCompanyName.MyProjectName.Web.Controllers
{
public class AccountController : ChallengeAccountController
{
}
}

@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using MyCompanyName.MyProjectName.Blazor.Server.Tiered.Components.Toolbar.LoginLink;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.Users;
namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered.Menus
{
public class MyProjectNameToolbarContributor : IToolbarContributor
{
public virtual Task ConfigureToolbarAsync(IToolbarConfigurationContext context)
{
if (context.Toolbar.Name != StandardToolbars.Main)
{
return Task.CompletedTask;
}
if (!context.ServiceProvider.GetRequiredService<ICurrentUser>().IsAuthenticated)
{
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginLinkViewComponent)));
}
return Task.CompletedTask;
}
}
}

@ -4,14 +4,17 @@ using System.Net.Http;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.OpenApi.Models;
using MyCompanyName.MyProjectName.Blazor.Server.Tiered.Menus;
using MyCompanyName.MyProjectName.Localization;
using MyCompanyName.MyProjectName.MultiTenancy;
using StackExchange.Redis;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.OpenIdConnect;
using Volo.Abp.AspNetCore.Components.Server.BasicTheme;
@ -26,14 +29,17 @@ using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Http.Client.IdentityModel.Web;
using Volo.Abp.Identity.Blazor.Server;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.SettingManagement.Blazor.Server;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement.Blazor.Server;
@ -81,7 +87,9 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
var configuration = context.Services.GetConfiguration();
ConfigureUrls(configuration);
ConfigureCache();
ConfigureBundles();
ConfigureMultiTenancy();
ConfigureAuthentication(context, configuration);
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
@ -90,6 +98,8 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
ConfigureBlazorise(context);
ConfigureRouter(context);
ConfigureMenu(context);
ConfigureRedis(context, configuration, hostingEnvironment);
ConfigureSwaggerServices(context.Services);
}
private void ConfigureUrls(IConfiguration configuration)
@ -99,6 +109,14 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
});
}
private void ConfigureCache()
{
Configure<AbpDistributedCacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
}
private void ConfigureBundles()
{
@ -123,6 +141,14 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
);
});
}
private void ConfigureMultiTenancy()
{
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = MultiTenancyConsts.IsEnabled;
});
}
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
{
@ -220,6 +246,11 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
{
options.MenuContributors.Add(new MyProjectNameMenuContributor());
});
Configure<AbpToolbarOptions>(options =>
{
options.Contributors.Add(new MyProjectNameToolbarContributor());
});
}
private void ConfigureRouter(ServiceConfigurationContext context)
@ -237,6 +268,32 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
options.AddMaps<MyProjectNameBlazorModule>();
});
}
private void ConfigureSwaggerServices(IServiceCollection services)
{
services.AddSwaggerGen(
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
);
}
private void ConfigureRedis(
ServiceConfigurationContext context,
IConfiguration configuration,
IWebHostEnvironment hostingEnvironment)
{
if (!hostingEnvironment.IsDevelopment())
{
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
context.Services
.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis, "MyProjectName-Protection-Keys");
}
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
@ -253,10 +310,8 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
if (!env.IsDevelopment())
{
app.UseErrorPage();
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseCorrelationId();
app.UseStaticFiles();
app.UseRouting();
@ -267,8 +322,13 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered
app.UseMultiTenancy();
}
app.UseUnitOfWork();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
});
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}
}

@ -15,7 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyCompanyName.MyProjectName.Blazor.Server": {
"MyCompanyName.MyProjectName.Blazor.Server.Tiered": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,

@ -2,12 +2,19 @@
"App": {
"SelfUrl": "https://localhost:44314"
},
"ConnectionStrings": {
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=MyProjectName;Trusted_Connection=True"
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44300/"
}
},
"Redis": {
"Configuration": "127.0.0.1"
},
"AuthServer": {
"Authority": "https://localhost:44314",
"RequireHttpsMetadata": "false"
"Authority": "https://localhost:44301",
"RequireHttpsMetadata": "true",
"ClientId": "MyProjectName_BlazorServerTiered",
"ClientSecret": "1q2w3e*"
},
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"

@ -18,6 +18,11 @@
"ClientId": "MyProjectName_Blazor",
"RootUrl": "https://localhost:44307"
},
"MyProjectName_BlazorServerTiered": {
"ClientId": "MyProjectName_BlazorServerTiered",
"ClientSecret": "1q2w3e*",
"RootUrl": "https://localhost:44314"
},
"MyProjectName_Swagger": {
"ClientId": "MyProjectName_Swagger",
"ClientSecret": "1q2w3e*",

@ -198,6 +198,27 @@ namespace MyCompanyName.MyProjectName.IdentityServer
corsOrigins: new[] { blazorRootUrl.RemovePostFix("/") }
);
}
//Blazor Server Tiered Client
var blazorServerTieredClientId = configurationSection["MyProjectName_BlazorServerTiered:ClientId"];
if (!blazorServerTieredClientId.IsNullOrWhiteSpace())
{
var blazorServerTieredClientRootUrl = configurationSection["MyProjectName_BlazorServerTiered:RootUrl"].EnsureEndsWith('/');
/* MyProjectName_BlazorServerTiered client is only needed if you created a tiered blazor server
* solution. Otherwise, you can delete this client. */
await CreateClientAsync(
name: webClientId,
scopes: commonScopes,
grantTypes: new[] { "hybrid" },
secret: (configurationSection["MyProjectName_BlazorServerTiered:ClientSecret"] ?? "1q2w3e*").Sha256(),
redirectUri: $"{blazorServerTieredClientRootUrl}signin-oidc",
postLogoutRedirectUri: $"{blazorServerTieredClientRootUrl}signout-callback-oidc",
frontChannelLogoutUri: $"{blazorServerTieredClientRootUrl}Account/FrontChannelLogout",
corsOrigins: new[] { blazorServerTieredClientRootUrl.RemovePostFix("/") }
);
}
// Swagger Client
var swaggerClientId = configurationSection["MyProjectName_Swagger:ClientId"];

@ -15,7 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyCompanyName.MyProjectName.HttpApi.Host": {
"MyCompanyName.MyProjectName.HttpApi.HostWithIds": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:44305",

@ -79,7 +79,7 @@ namespace MyCompanyName.MyProjectName.Web
var configuration = context.Services.GetConfiguration();
ConfigureBundles();
ConfigureCache(configuration);
ConfigureCache();
ConfigureRedis(context, configuration, hostingEnvironment);
ConfigureUrls(configuration);
ConfigureAuthentication(context, configuration);
@ -104,7 +104,7 @@ namespace MyCompanyName.MyProjectName.Web
});
}
private void ConfigureCache(IConfiguration configuration)
private void ConfigureCache()
{
Configure<AbpDistributedCacheOptions>(options =>
{
@ -260,7 +260,6 @@ namespace MyCompanyName.MyProjectName.Web
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
});
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}

Loading…
Cancel
Save