mirror of
https://github.com/bitwarden/server
synced 2026-01-03 00:53:37 +00:00
[PM-22740] Update current context to jive with Send Access Tokens (#6307)
* feat: modify current context to not include user information * fix: circular dependency for feature check in current context. Successfully tested client isn't affected with feature flag off. * test: whole bunch of tests for current context
This commit is contained in:
@@ -18,10 +18,10 @@ using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Bit.Core.Context;
|
||||
|
||||
public class CurrentContext : ICurrentContext
|
||||
public class CurrentContext(
|
||||
IProviderOrganizationRepository _providerOrganizationRepository,
|
||||
IProviderUserRepository _providerUserRepository) : ICurrentContext
|
||||
{
|
||||
private readonly IProviderOrganizationRepository _providerOrganizationRepository;
|
||||
private readonly IProviderUserRepository _providerUserRepository;
|
||||
private bool _builtHttpContext;
|
||||
private bool _builtClaimsPrincipal;
|
||||
private IEnumerable<ProviderOrganizationProviderDetails> _providerOrganizationProviderDetails;
|
||||
@@ -48,14 +48,6 @@ public class CurrentContext : ICurrentContext
|
||||
public virtual IdentityClientType IdentityClientType { get; set; }
|
||||
public virtual Guid? ServiceAccountOrganizationId { get; set; }
|
||||
|
||||
public CurrentContext(
|
||||
IProviderOrganizationRepository providerOrganizationRepository,
|
||||
IProviderUserRepository providerUserRepository)
|
||||
{
|
||||
_providerOrganizationRepository = providerOrganizationRepository;
|
||||
_providerUserRepository = providerUserRepository;
|
||||
}
|
||||
|
||||
public async virtual Task BuildAsync(HttpContext httpContext, GlobalSettings globalSettings)
|
||||
{
|
||||
if (_builtHttpContext)
|
||||
@@ -137,6 +129,24 @@ public class CurrentContext : ICurrentContext
|
||||
|
||||
var claimsDict = user.Claims.GroupBy(c => c.Type).ToDictionary(c => c.Key, c => c.Select(v => v));
|
||||
|
||||
ClientId = GetClaimValue(claimsDict, "client_id");
|
||||
|
||||
var clientType = GetClaimValue(claimsDict, Claims.Type);
|
||||
if (clientType != null)
|
||||
{
|
||||
if (Enum.TryParse(clientType, out IdentityClientType c))
|
||||
{
|
||||
IdentityClientType = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (IdentityClientType == IdentityClientType.Send)
|
||||
{
|
||||
// For the Send client, we don't need to set any User specific properties on the context
|
||||
// so just short circuit and return here.
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
var subject = GetClaimValue(claimsDict, "sub");
|
||||
if (Guid.TryParse(subject, out var subIdGuid))
|
||||
{
|
||||
@@ -165,13 +175,6 @@ public class CurrentContext : ICurrentContext
|
||||
}
|
||||
}
|
||||
|
||||
var clientType = GetClaimValue(claimsDict, Claims.Type);
|
||||
if (clientType != null)
|
||||
{
|
||||
Enum.TryParse(clientType, out IdentityClientType c);
|
||||
IdentityClientType = c;
|
||||
}
|
||||
|
||||
if (IdentityClientType == IdentityClientType.ServiceAccount)
|
||||
{
|
||||
ServiceAccountOrganizationId = new Guid(GetClaimValue(claimsDict, Claims.Organization));
|
||||
|
||||
Reference in New Issue
Block a user