Skip to content

Commit

Permalink
Fixed simultaneous signing from multiple browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
realmerx authored and mrts committed Apr 26, 2024
1 parent e03dddf commit 3717807
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);

// Assign a unique ID within the session to enable the use of a unique temporary container name across successive requests.
// A unique temporary container name is required to facilitate simultaneous signing from multiple browsers.
SetUniqueIdInSession();
}

[HttpGet]
Expand Down
20 changes: 15 additions & 5 deletions src/WebEid.AspNetCore.Example/Controllers/Api/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@

namespace WebEid.AspNetCore.Example.Controllers.Api
{
using System.Security;
using System.Security.Claims;
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

public abstract class BaseController : ControllerBase
{
const string uniqueIdKey = "UniqueId";

protected void RemoveUserContainerFile()
{
System.IO.File.Delete(GetUserContainerName());
}

protected void SetUniqueIdInSession()
{
HttpContext.Session.SetString(uniqueIdKey, Guid.NewGuid().ToString());
}

private string GetUniqueIdFromSession()
{
return HttpContext.Session.GetString(uniqueIdKey);
}

protected string GetUserContainerName()
{
var identity = (ClaimsIdentity)this.HttpContext.User?.Identity ??
throw new SecurityException("User is not logged in");
return identity.GetIdCode();
return $"container_{GetUniqueIdFromSession()}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Services;
Expand Down

0 comments on commit 3717807

Please sign in to comment.