mirror of https://github.com/abpframework/abp
parent
66ebf079f7
commit
3d91733bc1
@ -0,0 +1,8 @@
|
||||
namespace Volo.Abp.Identity;
|
||||
|
||||
public static class IdentitySessionDevices
|
||||
{
|
||||
public const string Web = "Web";
|
||||
|
||||
public const string OAuth = "OAuth";
|
||||
}
|
@ -1,9 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace Volo.Abp.Identity;
|
||||
|
||||
public interface IIdentitySessionRepository : IBasicRepository<IdentitySession, Guid>
|
||||
{
|
||||
Task<IdentitySession> FindAsync(string sessionId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IdentitySession> GetAsync(string sessionId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<List<IdentitySession>> GetListAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
|
||||
Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default);
|
||||
|
||||
Task DeleteAllAsync(Guid userId, string device, Guid? exceptSessionId = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.Users;
|
||||
|
||||
namespace Volo.Abp.Identity;
|
||||
|
||||
public class IdentitySessionManager : DomainService
|
||||
{
|
||||
protected IIdentitySessionRepository IdentitySessionRepository { get; }
|
||||
protected ICurrentUser CurrentUser { get; }
|
||||
|
||||
public IdentitySessionManager(IIdentitySessionRepository identitySessionRepository, ICurrentUser currentUser)
|
||||
{
|
||||
IdentitySessionRepository = identitySessionRepository;
|
||||
CurrentUser = currentUser;
|
||||
}
|
||||
|
||||
public virtual async Task<IdentitySession> CreateAsync(
|
||||
string sessionId,
|
||||
string device,
|
||||
string deviceInfo,
|
||||
Guid userId,
|
||||
Guid? tenantId,
|
||||
string clientId,
|
||||
string ipAddresses)
|
||||
{
|
||||
Check.NotNullOrWhiteSpace(sessionId, nameof(sessionId));
|
||||
Check.NotNullOrWhiteSpace(device, nameof(device));
|
||||
|
||||
var session = new IdentitySession(
|
||||
GuidGenerator.Create(),
|
||||
sessionId,
|
||||
device,
|
||||
deviceInfo,
|
||||
userId,
|
||||
tenantId,
|
||||
clientId,
|
||||
ipAddresses,
|
||||
Clock.Now
|
||||
);
|
||||
|
||||
return await IdentitySessionRepository.InsertAsync(session);
|
||||
}
|
||||
|
||||
public virtual async Task UpdateAsync(IdentitySession session)
|
||||
{
|
||||
await IdentitySessionRepository.UpdateAsync(session);
|
||||
}
|
||||
|
||||
public virtual async Task<List<IdentitySession>> GetListAsync(Guid userId)
|
||||
{
|
||||
return await IdentitySessionRepository.GetListAsync(userId);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentitySession> GetAsync(Guid id)
|
||||
{
|
||||
return await IdentitySessionRepository.GetAsync(id);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentitySession> FindAsync(Guid id)
|
||||
{
|
||||
return await IdentitySessionRepository.FindAsync(id);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentitySession> GetAsync(string sessionId)
|
||||
{
|
||||
return await IdentitySessionRepository.GetAsync(sessionId);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentitySession> FindAsync(string sessionId)
|
||||
{
|
||||
return await IdentitySessionRepository.FindAsync(sessionId);
|
||||
}
|
||||
|
||||
public virtual async Task RevokeAsync(Guid id)
|
||||
{
|
||||
var session = await IdentitySessionRepository.GetAsync(id);
|
||||
await IdentitySessionRepository.DeleteAsync(session);
|
||||
}
|
||||
|
||||
public virtual async Task RevokeAsync(string sessionId)
|
||||
{
|
||||
var session = await IdentitySessionRepository.GetAsync(sessionId);
|
||||
await IdentitySessionRepository.DeleteAsync(session);
|
||||
}
|
||||
|
||||
public virtual async Task RevokeAllAsync(Guid userId, Guid? exceptSessionId = null)
|
||||
{
|
||||
await IdentitySessionRepository.DeleteAllAsync(userId, exceptSessionId);
|
||||
}
|
||||
|
||||
public virtual async Task RevokeAllAsync(Guid userId, string device, Guid? exceptSessionId = null)
|
||||
{
|
||||
await IdentitySessionRepository.DeleteAllAsync(userId, device, exceptSessionId);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue