Skip to content

Commit 27e479d

Browse files
committed
LeptonXLiteTheme and auth issues fixed
1 parent ec433e7 commit 27e479d

File tree

17 files changed

+286
-283
lines changed

17 files changed

+286
-283
lines changed

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.AuthServer/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"App": {
33
"SelfUrl": "https://localhost:44301/",
4-
"CorsOrigins": "https://*.quartzadmin.com,http://localhost:4200,http://localhost:44307,https://localhost:44307,https://localhost:44300,https://localhost:44305/",
5-
"RedirectAllowedUrls": "https://quartzadmin.com,http://localhost:4200,http://localhost:44307,https://localhost:44307,https://localhost:44300,https://localhost:44305/"
4+
"CorsOrigins": "https://*.quartzadmin.com,http://localhost:4200,http://localhost:44307,https://localhost:44307,https://localhost:44300,https://localhost:44301,https://localhost:44305/",
5+
"RedirectAllowedUrls": "https://quartzadmin.com,http://localhost:4200,http://localhost:44307,https://localhost:44307,https://localhost:44300,https://localhost:44301,https://localhost:44305/"
66
},
77
"AppSelfUrl": "https://localhost:44301/",
88
"ConnectionStrings": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@using Volo.Abp.AspNetCore.Components.Web.LeptonXLiteTheme.Themes.LeptonXLite;
2+
@using Volo.Abp.DependencyInjection
3+
4+
@inherits Branding
5+
@attribute [ExposeServices(typeof(Branding))]
6+
@attribute [Dependency(ReplaceServices = true)]
7+
8+
@Name
9+
10+
@code {
11+
string Name = "Quartz Admin";
12+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@using Microsoft.Extensions.Localization
2+
@using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme.Themes.LeptonXLite.Toolbar
3+
@using Volo.Abp.DependencyInjection
4+
5+
@inherits UserMenuComponent
6+
@attribute [ExposeServices(typeof(UserMenuComponent))]
7+
@attribute [Dependency(ReplaceServices = true)]
8+
9+
<AuthorizeView>
10+
<Authorized>
11+
<Dropdown>
12+
<DropdownToggle Color="Color.Default" aria-label="@CurrentUser.Name">
13+
@if (CurrentTenant.Name != null)
14+
{
15+
<span><i>@CurrentTenant.Name</i>\@CurrentUser.UserName</span>
16+
}
17+
else
18+
{
19+
<span>@CurrentUser.UserName</span>
20+
}
21+
</DropdownToggle>
22+
<DropdownMenu>
23+
@if (Menu != null)
24+
{
25+
@foreach (var menuItem in Menu.Items)
26+
{
27+
<DropdownItem Disabled="@menuItem.IsDisabled" Clicked="@(() => NavigateToAsync(menuItem.Url, menuItem.Target))">
28+
<Icon Name="@menuItem.Icon" aria-label="@menuItem.DisplayName"
29+
IconSize="IconSize.Default" />@menuItem.DisplayName
30+
</DropdownItem>
31+
}
32+
}
33+
<DropdownItem Clicked="@BeginSignOut">
34+
@L["Logout"]
35+
</DropdownItem>
36+
</DropdownMenu>
37+
</Dropdown>
38+
</Authorized>
39+
<NotAuthorized>
40+
<Button Color="Color.Link" Clicked="@(() => NavigateToAsync(AuthenticationOptions.Value.LoginUrl))">@L["Login"]</Button>
41+
</NotAuthorized>
42+
</AuthorizeView>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.Extensions.Options;
3+
using System.Threading.Tasks;
4+
using Volo.Abp.AspNetCore.Components.Web.Security;
5+
using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme;
6+
using Volo.Abp.UI.Navigation;
7+
8+
namespace Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client.Components
9+
{
10+
public partial class CustomUserMenu
11+
{
12+
[Inject]
13+
protected IOptions<AuthenticationOptions> AuthenticationOptions { get; set; }
14+
15+
protected ApplicationMenu Menu { get; set; }
16+
17+
protected override async Task OnInitializedAsync()
18+
{
19+
Menu = await MenuManager.GetAsync(StandardMenus.User);
20+
21+
Navigation.LocationChanged += OnLocationChanged;
22+
23+
ApplicationConfigurationChangedService.Changed += ApplicationConfigurationChanged;
24+
}
25+
26+
private async void ApplicationConfigurationChanged()
27+
{
28+
Menu = await MenuManager.GetAsync(StandardMenus.User);
29+
await InvokeAsync(StateHasChanged);
30+
}
31+
}
32+
}

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client/MainDemoBlazorHostClientModule.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using Autofac.Core;
2-
using Blazorise.Bootstrap5;
1+
using Blazorise.Bootstrap5;
32
using Blazorise.Icons.FontAwesome;
3+
using IdentityModel;
44
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
7+
using OpenIddict.Abstractions;
78
using Syrna.QuartzAdmin.Blazor.Components;
89
using Syrna.QuartzAdmin.Blazor.Services;
910
using Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client.Menus;
@@ -13,7 +14,6 @@
1314
using Volo.Abp.Account;
1415
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
1516
using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme;
16-
using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme.Bundling;
1717
using Volo.Abp.Autofac.WebAssembly;
1818
using Volo.Abp.AutoMapper;
1919
using Volo.Abp.Identity.Blazor.WebAssembly;
@@ -31,8 +31,8 @@ namespace Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client;
3131
[DependsOn(typeof(AbpIdentityBlazorWebAssemblyModule))]
3232
[DependsOn(typeof(AbpTenantManagementBlazorWebAssemblyModule))]
3333
[DependsOn(typeof(AbpSettingManagementBlazorWebAssemblyModule))]
34-
[DependsOn(typeof(MainDemoBlazorWebAssemblyModule)
35-
)]
34+
//
35+
[DependsOn(typeof(MainDemoBlazorWebAssemblyModule))]
3636
public class MainDemoBlazorHostClientModule : AbpModule
3737
{
3838
public override void ConfigureServices(ServiceConfigurationContext context)
@@ -83,6 +83,13 @@ private static void ConfigureAuthentication(WebAssemblyHostBuilder builder)
8383
builder.Services.AddOidcAuthentication(options =>
8484
{
8585
builder.Configuration.Bind("AuthServer", options.ProviderOptions);
86+
options.UserOptions.RoleClaim = JwtClaimTypes.Role;
87+
//options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.OfflineAccess);
88+
options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.OpenId);
89+
options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.Profile);
90+
options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.Roles);
91+
options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.Email);
92+
options.ProviderOptions.DefaultScopes.Add(OpenIddictConstants.Scopes.Phone);
8693
options.ProviderOptions.DefaultScopes.Add("QuartzAdmin");
8794
});
8895
}

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client/Menus/MainDemoBlazorHostClientMenuContributor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private Task ConfigureUserMenuAsync(MenuConfigurationContext context)
5050
"Account.Manage",
5151
accountStringLocalizer["MyAccount"]??"My Account",
5252
$"{identityServerUrl.EnsureEndsWith('/')}Account/Manage?returnUrl={configuration["App:SelfUrl"]}",
53-
icon: "fa-cog",
53+
icon: "fa fa-cog",
5454
order: 1000,
5555
null).RequireAuthenticated());
5656

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client/Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<Compile Remove="Components\CustomUserMenu.razor.cs" />
1314
<Compile Remove="RemoteExternalLocalizationStore.cs" />
1415
<Compile Remove="UserExceptionInformer.cs" />
1516
</ItemGroup>
1617

18+
<ItemGroup>
19+
<Content Remove="Components\CustomUserMenu.razor" />
20+
</ItemGroup>
21+
1722
<ItemGroup>
1823
<PackageReference Include="Blazorise.Bootstrap5" />
1924
<PackageReference Include="Blazorise.Icons.FontAwesome" />

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.Blazor.Host.Client/wwwroot/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"SelfUrl": "https://localhost:44307"
44
},
55
"AuthServer": {
6-
"Authority": "https://localhost:44301",
6+
"Authority": "https://localhost:44358",
77
"ClientId": "QuartzAdmin_Blazor",
88
"ResponseType": "code"
99
},

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.HttpApi.Host/MainDemoHttpApiHostModule.cs

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,30 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
8181
{
8282
builder.AddValidation(options =>
8383
{
84-
//options.SetIssuer("https://syrnaids.syrna.net/");
85-
options.SetIssuer(configuration["AuthServer:Authority"]);
86-
options.AddAudiences("QuartzAdmin");
84+
//options.SetIssuer("https://csbsids.saglik.gov.tr/");
85+
options.SetIssuer(configuration["AuthServer:Authority"]!);
86+
options.AddAudiences("QuartzAdmin", "QuartzAdmin API");
8787
//options.UseLocalServer();
8888
options.UseAspNetCore();
8989
options.UseSystemNetHttp();
9090
});
9191
});
9292

93+
PreConfigure<OpenIddictServerBuilder>(x =>
94+
{
95+
//scope: 'offline_access openid profile role email phone QuartzAdmin',
96+
x.RegisterScopes(
97+
OpenIddictConstants.Scopes.OfflineAccess,
98+
OpenIddictConstants.Scopes.OpenId,
99+
OpenIddictConstants.Scopes.Profile,
100+
OpenIddictConstants.Scopes.Roles,
101+
OpenIddictConstants.Scopes.Email,
102+
OpenIddictConstants.Scopes.Phone,
103+
"QuartzAdmin"
104+
);
105+
x.AllowAuthorizationCodeFlow().AllowRefreshTokenFlow().AllowPasswordFlow();
106+
});
107+
93108
if (!hostingEnvironment.IsDevelopment())
94109
{
95110
PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
@@ -99,20 +114,11 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
99114

100115
PreConfigure<OpenIddictServerBuilder>(x =>
101116
{
102-
x.AddSigningCertificate(GetSigningCertificate(hostingEnvironment, configuration));
103-
x.AddEncryptionCertificate(GetSigningCertificate(hostingEnvironment, configuration));
104-
105-
//scope: 'offline_access openid profile role email phone QuartzAdmin',
106-
x.RegisterScopes(
107-
OpenIddictConstants.Scopes.OfflineAccess,
108-
OpenIddictConstants.Scopes.OpenId,
109-
OpenIddictConstants.Scopes.Profile,
110-
OpenIddictConstants.Scopes.Roles,
111-
OpenIddictConstants.Scopes.Email,
112-
OpenIddictConstants.Scopes.Phone,
113-
"QuartzAdmin"
114-
);
115-
x.AllowAuthorizationCodeFlow().AllowRefreshTokenFlow();
117+
//var pfxFile = Path.Combine(hostingEnvironment.ContentRootPath, "openiddict.pfx");
118+
//x.AddProductionEncryptionAndSigningCertificate($"{pfxFile}", "266657b3-2d03-4888-b9ee-b3f0939e9e24");
119+
x.AddSigningCertificate(GetSigningCertificate(hostingEnvironment));
120+
x.AddEncryptionCertificate(GetSigningCertificate(hostingEnvironment));
121+
//x.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "266657b3-2d03-4888-b9ee-b3f0939e9e24");
116122
});
117123
}
118124

@@ -179,10 +185,10 @@ private static void AutoLocalizationResourceContributors(IServiceCollection serv
179185
});
180186
}
181187

182-
private static X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostingEnv, IConfiguration configuration)
188+
private static X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostingEnv)
183189
{
184-
var fileName = "openiddict.pfx";
185-
var passPhrase = "ceae6457-5634-4e9f-8ea2-0be3ad54001a";
190+
const string fileName = "openiddict.pfx";
191+
const string passPhrase = "ceae6457-5634-4e9f-8ea2-0be3ad54001a";
186192
var file = Path.Combine(hostingEnv.ContentRootPath, fileName);
187193

188194
if (!File.Exists(file))
@@ -192,7 +198,7 @@ private static X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostin
192198

193199
try
194200
{
195-
var c = new X509Certificate2(file, passPhrase, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
201+
var c = new X509Certificate2(file, passPhrase);
196202
return c;
197203
}
198204
catch (Exception e)
@@ -219,7 +225,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
219225
});
220226

221227
ConfigureAuthentication(context);
222-
//ConfigureAuthentication(context, configuration);
228+
ConfigureAuthentication(context, configuration);
223229
//ConfigureBundles();
224230
ConfigureUrls(configuration);
225231
ConfigureConventionalControllers();
@@ -249,6 +255,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
249255
private void ConfigureAuthentication(ServiceConfigurationContext context)
250256
{
251257
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
258+
//context.Services.AddAuthentication(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
252259
context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options =>
253260
{
254261
options.IsDynamicClaimsEnabled = true;
@@ -263,17 +270,24 @@ private static void ConfigureAuthentication(ServiceConfigurationContext context,
263270
//options.TokenValidationParameters.ValidateIssuer = false;
264271
options.TokenValidationParameters = new TokenValidationParameters
265272
{
273+
//NameClaimType = "sub",
274+
//RoleClaimType = System.Security.Claims.ClaimTypes.Role,
266275
ValidateIssuer = true,
267276
ValidateAudience = true,
268-
ValidateIssuerSigningKey = true,
277+
ValidateLifetime = true,
278+
//ValidateIssuerSigningKey = true,
269279
ValidAudience = "QuartzAdmin",
270-
ValidIssuer = configuration["AuthServer:Authority"],
271-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["AuthServer:SwaggerClientSecret"]))
280+
ValidAudiences = new[] { "QuartzAdmin", "QuartzAdmin API" },
281+
ValidIssuer = configuration["AuthServer:Authority"]
282+
//ValidTypes = ["at+jwt"],
283+
//ValidAlgorithms = ["RS256"]
284+
//IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["AuthServer:SwaggerClientSecret"]))
272285
};
273286
options.UseSecurityTokenValidators = true;
274287
options.Authority = configuration["AuthServer:Authority"];
275288
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
276289
options.Audience = "QuartzAdmin";
290+
options.MapInboundClaims = false;
277291
#if DEBUG
278292
options.IncludeErrorDetails = true;
279293
#endif

demos/MainDemo/host/Syrna.QuartzAdmin.MainDemo.HttpApi.Host/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
}
1313
},
1414
"AuthServer": {
15-
"Authority": "https://localhost:44358",
16-
"SwaggerAuthority": "https://localhost:44358",
15+
"Authority": "https://localhost:44301",
16+
"SwaggerAuthority": "https://localhost:44301",
1717
"RequireHttpsMetadata": "true",
1818
"SwaggerClientId": "QuartzAdmin_Swagger",
1919
"SwaggerClientSecret": "1q2w3e*"

0 commit comments

Comments
 (0)