Add or update the TicketExpiresClaimType claim, to ensure its not added multiple times, now that is can be there after a clone.

This commit is contained in:
Bjarke Berg
2021-02-23 10:07:17 +01:00
parent f1128d7d70
commit bbaba0c542
2 changed files with 19 additions and 3 deletions

View File

@@ -324,5 +324,22 @@ namespace Umbraco.Extensions
/// <returns>Array of roles</returns>
public static string[] GetRoles(this ClaimsIdentity identity) => identity
.FindAll(x => x.Type == ClaimsIdentity.DefaultRoleClaimType).Select(role => role.Value).ToArray();
/// <summary>
/// Adds or updates and existing claim.
/// </summary>
public static void AddOrUpdateClaim(this ClaimsIdentity identity, Claim claim)
{
if (identity == null)
{
throw new ArgumentNullException(nameof(identity));
}
Claim existingClaim = identity.Claims.FirstOrDefault(x => x.Type == claim.Type);
identity.TryRemoveClaim(existingClaim);
identity.AddClaim(claim);
}
}
}

View File

@@ -15,7 +15,6 @@ using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Extensions;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Web.BackOffice.Security
{
@@ -149,8 +148,8 @@ namespace Umbraco.Cms.Web.BackOffice.Security
await securityStampValidator.ValidateAsync(ctx);
EnsureTicketRenewalIfKeepUserLoggedIn(ctx);
// add a claim to track when the cookie expires, we use this to track time remaining
backOfficeIdentity.AddClaim(new Claim(
// add or update a claim to track when the cookie expires, we use this to track time remaining
backOfficeIdentity.AddOrUpdateClaim(new Claim(
Constants.Security.TicketExpiresClaimType,
ctx.Properties.ExpiresUtc.Value.ToString("o"),
ClaimValueTypes.DateTime,