Skip to content

Commit b314ca8

Browse files
committed
Initial .NET Core 3 hack
1 parent a7e96f6 commit b314ca8

29 files changed

Lines changed: 89 additions & 267 deletions

src/Host/Host.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.App" />
9-
<PackageReference Include="IdentityServer4" Version="2.4.0" />
8+
<!--<PackageReference Include="IdentityServer4" Version="2.4.0" />-->
109
</ItemGroup>
1110

1211
<ItemGroup>

src/Host/Program.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
using Microsoft.AspNetCore;
22
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Hosting;
34

45
namespace Host
56
{
67
public class Program
78
{
89
public static void Main(string[] args)
910
{
10-
BuildWebHost(args).Run();
11+
CreateHostBuilder(args).Build().Run();
1112
}
1213

13-
public static IWebHost BuildWebHost(string[] args) =>
14-
WebHost.CreateDefaultBuilder(args)
15-
.UseStartup<Startup>()
16-
//.UseStartup<StartupWithIdentityServer>()
17-
.Build();
14+
public static IHostBuilder CreateHostBuilder(string[] args) =>
15+
Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
16+
.ConfigureWebHostDefaults(webBuilder =>
17+
{
18+
webBuilder.UseStartup<Startup>();
19+
// webBuilder.UseStartup<StartupWithIdentityServer>()
20+
});
1821
}
1922
}

src/Host/Properties/launchSettings.json

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "http://localhost:5000/",
7-
"sslPort": 0
8-
}
9-
},
102
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"launchBrowser": true,
14-
"environmentVariables": {
15-
"ASPNETCORE_ENVIRONMENT": "Development"
16-
}
17-
},
183
"Host": {
194
"commandName": "Project",
20-
"launchBrowser": true,
5+
/*"launchBrowser": true,*/
216
"environmentVariables": {
227
"ASPNETCORE_ENVIRONMENT": "Development"
238
},

src/Host/Startup.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using System;
44
using Host.InMemory;
5-
using IdentityManager2.Configuration;
5+
using IdentityManager2.Assets;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Extensions.FileProviders;
68

79
namespace Host
810
{
@@ -23,9 +25,24 @@ public void Configure(IApplicationBuilder app)
2325
{
2426
app.UseDeveloperExceptionPage();
2527

26-
app.UseIdentityManager();
28+
app.UseRouting();
2729

28-
app.UseMvcWithDefaultRoute();
30+
app.UseStaticFiles();
31+
32+
app.UseAuthentication();
33+
app.UseAuthorization();
34+
35+
app.UseFileServer(new FileServerOptions
36+
{
37+
RequestPath = new PathString("/assets"),
38+
FileProvider = new EmbeddedFileProvider(typeof(EmbeddedHtmlResult).Assembly, "IdentityManager2.Assets")
39+
});
40+
41+
app.UseEndpoints(x =>
42+
{
43+
//x.MapIdentityManager("/idm");
44+
x.MapDefaultControllerRoute();
45+
});
2946
}
3047
}
3148
}

src/Host/StartupWithIdentityServer.cs

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/IdentityManager2/Api/Controllers/PageController.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public PageController(IdentityManagerOptions config)
2020
}
2121

2222
[HttpGet]
23-
[Authorize(IdentityManagerConstants.IdMgrAuthPolicy)]
2423
[Route("", Name = IdentityManagerConstants.RouteNames.Home)]
2524
public IActionResult Index()
2625
{
@@ -30,12 +29,7 @@ public IActionResult Index()
3029
Model = JsonConvert.SerializeObject(new
3130
{
3231
PathBase = Request.PathBase,
33-
ShowLoginButton = config.SecurityConfiguration.ShowLoginButton,
34-
oauthSettings = new
35-
{
36-
authorization_endpoint = Request.PathBase + Constants.AuthorizePath,
37-
client_id = Constants.IdMgrClientId
38-
}
32+
ShowLoginButton = User.Identity.IsAuthenticated
3933
})
4034
});
4135
}
@@ -60,7 +54,10 @@ public async Task<IActionResult> Login(string returnUrl)
6054
[Route("logout", Name = IdentityManagerConstants.RouteNames.Logout)]
6155
public async Task<IActionResult> Logout()
6256
{
57+
await HttpContext.SignOutAsync(IdentityManagerConstants.LocalApiScheme);
58+
6359
await config.SecurityConfiguration.SignOut(HttpContext);
60+
6461
return RedirectToRoute(IdentityManagerConstants.RouteNames.Home, null);
6562
}
6663
}

src/IdentityManager2/Api/Controllers/RolesController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public RolesController(IIdentityManagerService service)
2424
{
2525
this.service = service ?? throw new ArgumentNullException(nameof(service));
2626
}
27-
28-
public IActionResult MethodNotAllowed()
29-
{
30-
return StatusCode(405);
31-
}
3227

3328
private IdentityManagerMetadata metadata;
3429

@@ -232,5 +227,10 @@ private void ValidateUpdateProperty(RoleMetadata roleMetadata, string type, stri
232227
}
233228
}
234229
}
230+
231+
private IActionResult MethodNotAllowed()
232+
{
233+
return StatusCode(405);
234+
}
235235
}
236236
}

src/IdentityManager2/Api/Controllers/UsersController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
@@ -32,11 +32,6 @@ public UsersController(IIdentityManagerService service, IUrlHelperFactory urlHel
3232
this.actionContextAccessor = actionContextAccessor ?? throw new ArgumentNullException(nameof(actionContextAccessor));
3333
}
3434

35-
public IActionResult MethodNotAllowed()
36-
{
37-
return StatusCode(405);
38-
}
39-
4035
public async Task<IdentityManagerMetadata> GetMetadataAsync()
4136
{
4237
if (metadata == null)
@@ -351,5 +346,10 @@ private void ValidateUpdateProperty(UserMetadata userMetadata, string type, stri
351346
}
352347
}
353348
}
349+
350+
private IActionResult MethodNotAllowed()
351+
{
352+
return StatusCode(405);
353+
}
354354
}
355355
}

src/IdentityManager2/Assets/AssetManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,4 @@ private static IDictionary<string, object> Map(object values)
5858
return dictionary;
5959
}
6060
}
61-
}
62-
61+
}

src/IdentityManager2/Assets/EmbeddedHtmlResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace IdentityManager2.Assets
99
{
10-
internal class EmbeddedHtmlResult : IActionResult
10+
// TODO: internal
11+
public class EmbeddedHtmlResult : IActionResult
1112
{
1213
private readonly string path;
1314
private readonly string file;

0 commit comments

Comments
 (0)