1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-03 14:03:33 +01:00
bitwarden-server/src/Core/Identity/ReadOnlyEnvIdentityUserStore.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2018-03-21 19:26:49 +01:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2018-03-28 16:45:30 +02:00
using Bit.Core.Utilities;
2018-03-21 19:26:49 +01:00
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
namespace Bit.Core.Identity
{
public class ReadOnlyEnvIdentityUserStore : ReadOnlyIdentityUserStore
{
private readonly IConfiguration _configuration;
public ReadOnlyEnvIdentityUserStore(IConfiguration configuration)
{
_configuration = configuration;
}
public override Task<IdentityUser> FindByEmailAsync(string normalizedEmail,
CancellationToken cancellationToken = default(CancellationToken))
{
var usersCsv = _configuration["adminSettings:admins"];
2018-03-28 16:45:30 +02:00
if(!CoreHelpers.SettingHasValue(usersCsv))
2018-03-21 19:26:49 +01:00
{
return Task.FromResult<IdentityUser>(null);
}
var users = usersCsv.ToLowerInvariant().Split(',');
var user = users.Where(a => a.Trim() == normalizedEmail).FirstOrDefault();
if(user == null || !user.Contains("@"))
{
return Task.FromResult<IdentityUser>(null);
}
user = user.Trim();
return Task.FromResult(new IdentityUser
{
Id = user,
Email = user,
NormalizedEmail = user,
EmailConfirmed = true,
UserName = user,
NormalizedUserName = user,
SecurityStamp = user
});
}
public override Task<IdentityUser> FindByIdAsync(string userId,
CancellationToken cancellationToken = default(CancellationToken))
{
return FindByEmailAsync(userId, cancellationToken);
}
}
}