Skip to content

Commit 399ad7f

Browse files
Fix latest issues
1 parent 8a13b01 commit 399ad7f

File tree

12 files changed

+73
-18
lines changed

12 files changed

+73
-18
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>5.0.3</VersionPrefix>
3+
<VersionPrefix>5.0.4-rc1</VersionPrefix>
44
<Authors>SimpleIdServer</Authors>
55
<Owners>SimpleIdServer</Owners>
66
</PropertyGroup>

src/IdServer/SimpleIdServer.IdServer.Startup/Resources/LayoutResource.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/IdServer/SimpleIdServer.IdServer.Startup/Resources/LayoutResource.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<data name="selected_language" xml:space="preserve">
157157
<value>Language is {0}</value>
158158
</data>
159+
<data name="Sessions" xml:space="preserve">
160+
<value>Sessions</value>
161+
</data>
159162
<data name="UnexpectedError" xml:space="preserve">
160163
<value>Unexpected error</value>
161164
</data>

src/IdServer/SimpleIdServer.IdServer.Startup/Views/Shared/_AuthenticateLayout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
@AuthenticatePasswordResource.maximum_number_active_sessions
7676
</p>
7777
<p>
78-
@AuthenticatePasswordResource.reject_sessions : <a href="@Url.Action("Index", "Accounts", new { area = "" })">@AuthenticatePasswordResource.sessions</a>
78+
@AuthenticatePasswordResource.reject_sessions : <a href="@Url.Action("Index", "Sessions", new { area = "" })">@AuthenticatePasswordResource.sessions</a>
7979
</p>
8080
</div>
8181
}

src/IdServer/SimpleIdServer.IdServer.Startup/Views/Shared/_Layout.cshtml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
2+
@using SimpleIdServer.IdServer.Options
23
@using SimpleIdServer.IdServer.Startup.Resources
34
@using Microsoft.Extensions.Options
45
@using System.Globalization
6+
@inject IOptions<IdServerHostOptions> options
57

68
@inject IOptions<SimpleIdServer.IdServer.Options.IdServerHostOptions> Options
79

@@ -38,6 +40,15 @@
3840
</a>
3941
</li>
4042
}
43+
44+
@if (options.Value.UseRealm)
45+
{
46+
<li class="nav-item">
47+
<a class="nav-link" href="@Url.Action("Index", "Sessions", new { prefix = string.Empty })">
48+
@LayoutResource.Sessions
49+
</a>
50+
</li>
51+
}
4152
@RenderSection("SubMenu", required: false)
4253
</ul>
4354
<ul class="navbar-nav">

src/IdServer/SimpleIdServer.IdServer/Auth/IdServerCookieAuthenticationHandler.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ private static class AuthenticateResults
6060
/// <param name="encoder">The <see cref="UrlEncoder"/>.</param>
6161
/// <param name="clock">The <see cref="ISystemClock"/>.</param>
6262
public IdServerCookieAuthenticationHandler(
63-
IUserSessionResitory userSessionResitory,
63+
IUserSessionResitory userSessionResitory,
6464
IOptions<IdServerHostOptions> idServerHostOptions,
6565
IRealmStore realmStore,
66-
IOptionsMonitor<CookieAuthenticationOptions> options,
66+
IOptionsMonitor<CookieAuthenticationOptions> options,
6767
ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
6868
: base(options, logger, encoder, clock)
6969
{
@@ -220,7 +220,7 @@ private async Task<AuthenticateResult> ReadCookieTicket()
220220
sessionId = Options.CookieManager.GetRequestCookie(Context, sessionCookieName);
221221
}
222222

223-
if(!string.IsNullOrWhiteSpace(sessionId))
223+
if (!string.IsNullOrWhiteSpace(sessionId))
224224
{
225225
var realm = _realmStore.Realm;
226226
realm = realm ?? Constants.DefaultRealm;
@@ -243,7 +243,7 @@ private async Task<AuthenticateResult> ReadCookieTicket()
243243
Context,
244244
GetCookieName()!,
245245
context.CookieOptions);
246-
if(!string.IsNullOrWhiteSpace(sessionCookieName)) Options.CookieManager.DeleteCookie(Context, sessionCookieName, context.CookieOptions);
246+
if (!string.IsNullOrWhiteSpace(sessionCookieName)) Options.CookieManager.DeleteCookie(Context, sessionCookieName, context.CookieOptions);
247247
return AuthenticateResults.ExpiredTicket;
248248
}
249249
}
@@ -436,9 +436,13 @@ protected override async Task HandleSignInAsync(ClaimsPrincipal user, Authentica
436436
protected override async Task HandleSignOutAsync(AuthenticationProperties properties)
437437
{
438438
properties = properties ?? new AuthenticationProperties();
439+
var realm = _realmStore.Realm;
440+
if (properties.Items?.ContainsKey(Constants.RealmKey) == true)
441+
{
442+
realm = properties.Items[Constants.RealmKey];
443+
}
439444

440445
_signOutCalled = true;
441-
442446
// Process the request cookie to initialize members like _sessionKey.
443447
await EnsureCookieTicket();
444448
var cookieOptions = BuildCookieOptions();
@@ -458,7 +462,7 @@ protected override async Task HandleSignOutAsync(AuthenticationProperties proper
458462

459463
Options.CookieManager.DeleteCookie(
460464
Context,
461-
GetCookieName()!,
465+
GetCookieName(realm, Options.Cookie.Name)!,
462466
context.CookieOptions);
463467

464468
// Only honor the ReturnUrl query string parameter on the logout path
@@ -562,4 +566,4 @@ public static string GetCookieName(string realm, string cookieName)
562566
return $"{cookieName}.{realm}";
563567
}
564568
}
565-
}
569+
}

src/IdServer/SimpleIdServer.IdServer/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace SimpleIdServer.IdServer
1515
public static class Constants
1616
{
1717
public const string LogoutUserKey = "otherUser";
18+
public const string RealmKey = "realm";
1819

1920
public static class JWKUsages
2021
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Routing;
5+
using System;
6+
7+
namespace SimpleIdServer.IdServer.Infastructures;
8+
9+
public class NotEqualConstraint : IRouteConstraint
10+
{
11+
private readonly string _excludedValue;
12+
13+
public NotEqualConstraint(string excludedValue)
14+
{
15+
_excludedValue = excludedValue;
16+
}
17+
18+
public bool Match(HttpContext httpContext, IRouter route, string routeKey,
19+
RouteValueDictionary values, RouteDirection routeDirection)
20+
{
21+
return !string.Equals(values[routeKey]?.ToString(),
22+
_excludedValue,
23+
StringComparison.OrdinalIgnoreCase);
24+
}
25+
}

src/IdServer/SimpleIdServer.IdServer/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ public static IdServerStoreChooser AddSIDIdentityServer(
145145
if (!string.IsNullOrWhiteSpace(nameIdentifier))
146146
{
147147
var realmStore = ctx.HttpContext.RequestServices.GetRequiredService<IRealmStore>();
148+
var realm = realmStore.Realm;
149+
if (ctx.Properties != null && ctx.Properties.Items.ContainsKey(Constants.RealmKey)) realm = ctx.Properties.Items[Constants.RealmKey];
148150
ctx.Options.CookieManager.DeleteCookie(
149-
ctx.HttpContext,
150-
$"{IdServerCookieAuthenticationHandler.GetCookieName(realmStore.Realm, ctx.Options.Cookie.Name)}-{nameIdentifier.SanitizeNameIdentifier()}",
151-
ctx.CookieOptions);
151+
ctx.HttpContext,
152+
$"{IdServerCookieAuthenticationHandler.GetCookieName(realm, ctx.Options.Cookie.Name)}-{nameIdentifier.SanitizeNameIdentifier()}",
153+
ctx.CookieOptions);
152154
}
153155

154156
return Task.CompletedTask;

src/IdServer/SimpleIdServer.IdServer/UI/CheckSessionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public async Task<IActionResult> EndSession([FromRoute] string prefix, Cancellat
109109
var state = jObjBody.GetStateFromRpInitiatedLogoutRequest();
110110
try
111111
{
112-
var subject = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
112+
var subject = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
113113
if (string.IsNullOrWhiteSpace(postLogoutRedirectUri))
114114
{
115115
Response.Cookies.Delete(_options.GetSessionCookieName(_realmStore.Realm, subject));

0 commit comments

Comments
 (0)