mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
update libs, aspnet core 20, & id server 2.0
This commit is contained in:
@ -5,9 +5,7 @@ using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using System.Security.Claims;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using IdentityModel;
|
||||
|
||||
@ -19,20 +17,17 @@ namespace Bit.Core.IdentityServer
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly ILicensingService _licensingService;
|
||||
private IdentityOptions _identityOptions;
|
||||
|
||||
public ProfileService(
|
||||
IUserRepository userRepository,
|
||||
IUserService userService,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ILicensingService licensingService,
|
||||
IOptions<IdentityOptions> identityOptionsAccessor)
|
||||
ILicensingService licensingService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_userService = userService;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_licensingService = licensingService;
|
||||
_identityOptions = identityOptionsAccessor?.Value ?? new IdentityOptions();
|
||||
}
|
||||
|
||||
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
|
||||
@ -49,7 +44,7 @@ namespace Bit.Core.IdentityServer
|
||||
new Claim("premium", isPremium ? "true" : "false", ClaimValueTypes.Boolean),
|
||||
new Claim(JwtClaimTypes.Email, user.Email),
|
||||
new Claim(JwtClaimTypes.EmailVerified, user.EmailVerified ? "true" : "false", ClaimValueTypes.Boolean),
|
||||
new Claim(_identityOptions.ClaimsIdentity.SecurityStampClaimType, user.SecurityStamp)
|
||||
new Claim("sstamp", user.SecurityStamp)
|
||||
});
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(user.Name))
|
||||
@ -101,14 +96,13 @@ namespace Bit.Core.IdentityServer
|
||||
newClaims.AddRange(existingClaimsToKeep);
|
||||
if(newClaims.Any())
|
||||
{
|
||||
context.AddFilteredClaims(newClaims);
|
||||
context.AddRequestedClaims(newClaims);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task IsActiveAsync(IsActiveContext context)
|
||||
{
|
||||
var securityTokenClaim = context.Subject?.Claims.FirstOrDefault(c =>
|
||||
c.Type == _identityOptions.ClaimsIdentity.SecurityStampClaimType);
|
||||
var securityTokenClaim = context.Subject?.Claims.FirstOrDefault(c => c.Type == "sstamp");
|
||||
var user = await _userService.GetUserByPrincipalAsync(context.Subject);
|
||||
|
||||
if(user != null && securityTokenClaim != null)
|
||||
|
Reference in New Issue
Block a user