Skip to content

Commit 5079f70

Browse files
committed
[Fixes #1583] Add authorization to the default Identity UI
1 parent d968fdd commit 5079f70

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

samples/IdentitySample.Mvc/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:28248/",
6+
"applicationUrl": "http://localhost:51567/",
77
"sslPort": 0
88
}
99
},

src/UI/IdentityDefaultUIConfigureOptions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Hosting;
88
using Microsoft.AspNetCore.Mvc.RazorPages;
99
using Microsoft.AspNetCore.StaticFiles;
10+
using Microsoft.Extensions.DependencyInjection;
1011
using Microsoft.Extensions.FileProviders;
1112
using Microsoft.Extensions.Options;
1213

@@ -17,6 +18,8 @@ internal class IdentityDefaultUIConfigureOptions :
1718
IPostConfigureOptions<StaticFileOptions>,
1819
IPostConfigureOptions<CookieAuthenticationOptions>
1920
{
21+
private const string IdentityUIDefaultAreaName = "Identity";
22+
2023
public IdentityDefaultUIConfigureOptions(IHostingEnvironment environment)
2124
{
2225
Environment = environment;
@@ -30,6 +33,8 @@ public void PostConfigure(string name, RazorPagesOptions options)
3033
options = options ?? throw new ArgumentNullException(nameof(options));
3134

3235
options.AllowAreas = true;
36+
options.Conventions.AuthorizeAreaFolder(IdentityUIDefaultAreaName, "/Account/Manage");
37+
options.Conventions.AuthorizeAreaPage(IdentityUIDefaultAreaName, "/Account/Logout");
3338
}
3439

3540
public void PostConfigure(string name, StaticFileOptions options)
@@ -58,9 +63,9 @@ public void PostConfigure(string name, CookieAuthenticationOptions options)
5863

5964
if (string.Equals(IdentityConstants.ApplicationScheme, name, StringComparison.Ordinal))
6065
{
61-
options.LoginPath = "/Identity/Account/Login";
62-
options.LogoutPath = "/Identity/Account/Logout";
63-
options.AccessDeniedPath = "/Identity/Account/AccessDenied";
66+
options.LoginPath = $"/{IdentityUIDefaultAreaName}/Account/Login";
67+
options.LogoutPath = $"/{IdentityUIDefaultAreaName}/Account/Logout";
68+
options.AccessDeniedPath = $"/{IdentityUIDefaultAreaName}/Account/AccessDenied";
6469
}
6570
}
6671
}

0 commit comments

Comments
 (0)