Skip to content

Commit

Permalink
Revert "Implement OIDC session management"
Browse files Browse the repository at this point in the history
This reverts commit a1e4248.
  • Loading branch information
GREsau committed Jun 10, 2024
1 parent a1e4248 commit 206a97a
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 150 deletions.
50 changes: 1 addition & 49 deletions samples/Contruum/Contruum.Server/Handlers.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Globalization;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Configuration;
using OpenIddict.Abstractions;
using OpenIddict.Server;
using static OpenIddict.Abstractions.OpenIddictConstants;
Expand Down Expand Up @@ -61,46 +55,4 @@ public ValueTask HandleAsync(HandleUserinfoRequestContext context)
return default;
}
}

public class AttachCheckSessionIframeEndpoint : IOpenIddictServerHandler<HandleConfigurationRequestContext>
{
private readonly IConfiguration _configuration;

public AttachCheckSessionIframeEndpoint(IConfiguration configuration)
{
_configuration = configuration;
}

public ValueTask HandleAsync(HandleConfigurationRequestContext context)
{
var baseUri = context.BaseUri ?? throw new InvalidOperationException("Missing BaseUri");
var relativePath = _configuration["OpenIddict:Endpoints:CheckSession"]!;

context.Metadata["check_session_iframe"] = baseUri.ToString().TrimEnd('/') + "/" + relativePath.TrimStart('/');

return default;
}
}

public class AttachSessionState : IOpenIddictServerHandler<ApplyAuthorizationResponseContext>
{
public ValueTask HandleAsync(ApplyAuthorizationResponseContext context)
{
if (context.Request?.ClientId is string clientId
&& Uri.TryCreate(context.Request.RedirectUri, UriKind.Absolute, out var redirectUri)
&& context.Transaction.GetHttpRequest()?.GetSessionId() is string sessionId)
{
var origin = redirectUri.GetLeftPart(UriPartial.Authority);
var salt = RandomNumberGenerator.GetHexString(8);

var utf8Bytes = Encoding.UTF8.GetBytes(clientId + origin + sessionId + salt);
var hashBytes = SHA256.HashData(utf8Bytes);
var hashBase64Url = Base64UrlTextEncoder.Encode(hashBytes);

context.Response.SetParameter("session_state", hashBase64Url + "." + salt);
}

return default;
}
}
}
49 changes: 0 additions & 49 deletions samples/Contruum/Contruum.Server/Pages/Connect/CheckSession.cshtml

This file was deleted.

33 changes: 0 additions & 33 deletions samples/Contruum/Contruum.Server/SessionIdExtensions.cs

This file was deleted.

17 changes: 0 additions & 17 deletions samples/Contruum/Contruum.Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Threading.Tasks;
using Contruum.Server.Models;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -38,16 +37,6 @@ public void ConfigureServices(IServiceCollection services)
options.AccessDeniedPath = "/connect/signin";
options.LoginPath = "/connect/signin";
options.LogoutPath = "/connect/signout";
options.Events.OnSignedIn = (context) =>
{
context.Response.IssueSessionCookie();
return Task.CompletedTask;
};
options.Events.OnSigningOut = (context) =>
{
context.Response.DeleteSessionCookie();
return Task.CompletedTask;
};
});

// OpenIddict offers native integration with Quartz.NET to perform scheduled tasks
Expand Down Expand Up @@ -112,12 +101,6 @@ public void ConfigureServices(IServiceCollection services)
// Register the event handler responsible for populating userinfo responses.
options.AddEventHandler<HandleUserinfoRequestContext>(options =>
options.UseSingletonHandler<Handlers.PopulateUserinfo>());
options.AddEventHandler<HandleConfigurationRequestContext>(options =>
options.UseSingletonHandler<Handlers.AttachCheckSessionIframeEndpoint>());
options.AddEventHandler<ApplyAuthorizationResponseContext>(options =>
options.UseSingletonHandler<Handlers.AttachSessionState>());
})

.AddValidation(options =>
Expand Down
3 changes: 1 addition & 2 deletions samples/Contruum/Contruum.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@
"Introspection": "connect/introspect",
"Token": "connect/token",
"Userinfo": "connect/userinfo",
"Logout": "connect/endsession",
"CheckSession": "connect/checksession"
"Logout": "connect/endsession"
},

"Scopes": [
Expand Down

0 comments on commit 206a97a

Please sign in to comment.