Skip to content

Commit

Permalink
SessionMigration - Update to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdecock committed Jan 19, 2024
1 parent 9f46c8d commit 076aed7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
21 changes: 21 additions & 0 deletions IdentityServer/v7/SessionMigration/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "IdentityServer",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net8.0/SessionMigration.dll",
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"console": "externalTerminal",
}
]
}
17 changes: 17 additions & 0 deletions IdentityServer/v7/SessionMigration/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "process",
"command": "dotnet",
"args": [
"build",
"${workspaceFolder}/SessionMigration.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
17 changes: 8 additions & 9 deletions IdentityServer/v7/SessionMigration/HostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde

// ********************
// *** INSTRUCTIONS ***
// This purpose of this sample is to show how to migrate existing client side session to server
// The purpose of this sample is to show how to migrate existing client side session to server
// side session without the user having to login again. To test it, first run the sample as is
// and log in (user: alice, password: alice) to get a normal cookie based session in your
// browser. Then uncomment the following blocks and run the sample again. The first request
Expand All @@ -43,20 +43,19 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
// Note that if server side sessions have been enabled and then are removed before another
// test run, you have to manually clear the cookie to be able to log in again.

// ** This is the normal template code for activating server side sessions.
// //** This is the normal template code for activating server side sessions.
// isBuilder.AddServerSideSessions();

//isBuilder.AddServerSideSessions();

//builder.Services.AddAuthorization(options =>
// builder.Services.AddAuthorization(options =>
// options.AddPolicy("admin",
// policy => policy.RequireClaim("sub", "1"))
// );
//builder.Services.Configure<RazorPagesOptions>(options =>
// builder.Services.Configure<RazorPagesOptions>(options =>
// options.Conventions.AuthorizeFolder("/ServerSideSessions", "admin"));

// ** This is the code that adds migration of sessions. Enabling server side sessions through the
// ** block above without enabling this will invalidate all existing sessions.
//builder.Services.AddTransient<IPostConfigureOptions<CookieAuthenticationOptions>, SessionMigrationPostConfigureOptions>();
// //** This is the code that adds migration of sessions. Enabling server side sessions through the
// //** block above without enabling this will invalidate all existing sessions.
// builder.Services.AddTransient<IPostConfigureOptions<CookieAuthenticationOptions>, SessionMigrationPostConfigureOptions>();

return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public override void OnResultExecuting(ResultExecutingContext context)
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
if (!context.HttpContext.Response.Headers.ContainsKey("X-Content-Type-Options"))
{
context.HttpContext.Response.Headers.Add("X-Content-Type-Options", "nosniff");
context.HttpContext.Response.Headers.Append("X-Content-Type-Options", "nosniff");
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
if (!context.HttpContext.Response.Headers.ContainsKey("X-Frame-Options"))
{
context.HttpContext.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
context.HttpContext.Response.Headers.Append("X-Frame-Options", "SAMEORIGIN");
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Expand All @@ -36,19 +36,19 @@ public override void OnResultExecuting(ResultExecutingContext context)
// once for standards compliant browsers
if (!context.HttpContext.Response.Headers.ContainsKey("Content-Security-Policy"))
{
context.HttpContext.Response.Headers.Add("Content-Security-Policy", csp);
context.HttpContext.Response.Headers.Append("Content-Security-Policy", csp);
}
// and once again for IE
if (!context.HttpContext.Response.Headers.ContainsKey("X-Content-Security-Policy"))
{
context.HttpContext.Response.Headers.Add("X-Content-Security-Policy", csp);
context.HttpContext.Response.Headers.Append("X-Content-Security-Policy", csp);
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
var referrer_policy = "no-referrer";
if (!context.HttpContext.Response.Headers.ContainsKey("Referrer-Policy"))
{
context.HttpContext.Response.Headers.Add("Referrer-Policy", referrer_policy);
context.HttpContext.Response.Headers.Append("Referrer-Policy", referrer_policy);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions IdentityServer/v7/SessionMigration/SessionMigration.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" Version="6.3.0" />
<PackageReference Include="Duende.IdentityServer" Version="7.0.0-rc.2" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
</ItemGroup>


Expand Down

0 comments on commit 076aed7

Please sign in to comment.