1 using Microsoft.EntityFrameworkCore;
5 using System.Threading.Tasks;
39 this.systemIdentityFactory = systemIdentityFactory ??
throw new ArgumentNullException(nameof(systemIdentityFactory));
40 this.databaseContext = databaseContext ??
throw new ArgumentNullException(nameof(databaseContext));
41 this.identityCache = identityCache ??
throw new ArgumentNullException(nameof(identityCache));
45 public void Dispose() => CurrentAuthenticationContext?.Dispose();
50 if (CurrentAuthenticationContext != null)
51 throw new InvalidOperationException(
"Authentication context has already been loaded");
53 var userQuery = databaseContext.Users.Where(x => x.Id == userId)
54 .Include(x => x.CreatedBy)
55 .FirstOrDefaultAsync(cancellationToken);
57 var instanceUserQuery = instanceId.HasValue ? databaseContext.InstanceUsers
58 .Where(x => x.UserId == userId && x.InstanceId == instanceId && x.Instance.Online.Value)
59 .Include(x => x.Instance)
60 .FirstOrDefaultAsync(cancellationToken) : Task.FromResult<
InstanceUser>(null);
62 var user = await userQuery.ConfigureAwait(
false);
70 if (user.SystemIdentifier != null)
71 systemIdentity = identityCache.LoadCachedIdentity(user);
74 if (user.LastPasswordUpdate.HasValue && user.LastPasswordUpdate > validAfter)
79 systemIdentity = null;
84 var instanceUser = await instanceUserQuery.ConfigureAwait(
false);
90 systemIdentity?.Dispose();
For creating and accessing authentication contexts
Manages Api.Models.Users for a scope
AuthenticationContextFactory(ISystemIdentityFactory systemIdentityFactory, IDatabaseContext databaseContext, IIdentityCache identityCache)
Construct an AuthenticationContextFactory
Use server authentication
Represents a user on the current System.Runtime.InteropServices.OSPlatform
Represents the currently authenticated Api.Models.User
Factory for ISystemIdentitys
readonly IIdentityCache identityCache
The IIdentityCache for the AuthenticationContextFactory
readonly ISystemIdentityFactory systemIdentityFactory
The ISystemIdentityFactory for the AuthenticationContextFactory
readonly IDatabaseContext databaseContext
The IDatabaseContext for the AuthenticationContextFactory
async Task CreateAuthenticationContext(long userId, long?instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken)
Create an IAuthenticationContext to populate CurrentAuthenticationContext
For caching ISystemIdentitys