예제 #1
0
 public virtual async Task <bool> IsLinkedAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser)
 {
     using (CurrentTenant.Change(null))
     {
         return(await IdentityLinkUserRepository.FindAsync(sourceLinkUser, targetLinkUser) != null);
     }
 }
예제 #2
0
        public IdentityLinkUser(Guid id, IdentityLinkUserInfo sourceUser, IdentityLinkUserInfo targetUser)
            : base(id)
        {
            SourceUserId   = sourceUser.UserId;
            SourceTenantId = sourceUser.TenantId;

            TargetUserId   = targetUser.UserId;
            TargetTenantId = targetUser.TenantId;
        }
예제 #3
0
        public virtual async Task <string> GenerateLinkTokenAsync(IdentityLinkUserInfo targetLinkUser)
        {
            using (CurrentTenant.Change(targetLinkUser.TenantId))
            {
                var user = await UserManager.GetByIdAsync(targetLinkUser.UserId);

                return(await UserManager.GenerateUserTokenAsync(
                           user,
                           LinkUserTokenProvider.LinkUserTokenProviderName,
                           LinkUserTokenProvider.LinkUserTokenPurpose));
            }
        }
예제 #4
0
        public virtual async Task <bool> VerifyLinkTokenAsync(IdentityLinkUserInfo targetLinkUser, string token)
        {
            using (CurrentTenant.Change(targetLinkUser.TenantId))
            {
                var user = await UserManager.GetByIdAsync(targetLinkUser.UserId);

                return(await UserManager.VerifyUserTokenAsync(
                           user,
                           LinkUserTokenProvider.LinkUserTokenProviderName,
                           LinkUserTokenProvider.LinkUserTokenPurpose,
                           token));
            }
        }
예제 #5
0
 public virtual async Task <bool> IsLinkedAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser, bool includeIndirect = false, CancellationToken cancellationToken = default)
 {
     using (CurrentTenant.Change(null))
     {
         if (includeIndirect)
         {
             return((await GetListAsync(sourceLinkUser, true, cancellationToken: cancellationToken))
                    .Any(x => x.SourceTenantId == targetLinkUser.TenantId && x.SourceUserId == targetLinkUser.UserId ||
                         x.TargetTenantId == targetLinkUser.TenantId && x.TargetUserId == targetLinkUser.UserId));
         }
         return(await IdentityLinkUserRepository.FindAsync(sourceLinkUser, targetLinkUser, cancellationToken) != null);
     }
 }
예제 #6
0
        public virtual async Task UnlinkAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser)
        {
            if (!await IsLinkedAsync(sourceLinkUser, targetLinkUser))
            {
                return;
            }

            var linkedUser = await IdentityLinkUserRepository.FindAsync(sourceLinkUser, targetLinkUser);

            if (linkedUser != null)
            {
                await IdentityLinkUserRepository.DeleteAsync(linkedUser);
            }
        }
예제 #7
0
        public async Task <List <IdentityLinkUser> > GetListAsync(IdentityLinkUserInfo linkUserInfo, bool includeIndirect = false, CancellationToken cancellationToken = default)
        {
            using (CurrentTenant.Change(null))
            {
                var users = await IdentityLinkUserRepository.GetListAsync(linkUserInfo, cancellationToken : cancellationToken);

                if (includeIndirect == false)
                {
                    return(users);
                }

                var userInfos = new List <IdentityLinkUserInfo>()
                {
                    linkUserInfo
                };

                var allUsers = new List <IdentityLinkUser>();
                allUsers.AddRange(users);

                do
                {
                    var nextUsers = new List <IdentityLinkUserInfo>();
                    foreach (var user in users)
                    {
                        if (userInfos.Any(x => x.TenantId != user.SourceTenantId || x.UserId != user.SourceUserId))
                        {
                            nextUsers.Add(new IdentityLinkUserInfo(user.SourceUserId, user.SourceTenantId));
                        }

                        if (userInfos.Any(x => x.TenantId != user.TargetTenantId || x.UserId != user.TargetUserId))
                        {
                            nextUsers.Add(new IdentityLinkUserInfo(user.TargetUserId, user.TargetTenantId));
                        }
                    }

                    users = new List <IdentityLinkUser>();
                    foreach (var next in nextUsers)
                    {
                        users.AddRange(await IdentityLinkUserRepository.GetListAsync(next, userInfos, cancellationToken));
                    }

                    userInfos.AddRange(nextUsers);
                    allUsers.AddRange(users);
                } while (users.Any());

                return(allUsers);
            }
        }
예제 #8
0
        public virtual async Task UnlinkAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser, CancellationToken cancellationToken = default)
        {
            using (CurrentTenant.Change(null))
            {
                if (!await IsLinkedAsync(sourceLinkUser, targetLinkUser, cancellationToken: cancellationToken))
                {
                    return;
                }

                var linkedUser = await IdentityLinkUserRepository.FindAsync(sourceLinkUser, targetLinkUser, cancellationToken);

                if (linkedUser != null)
                {
                    await IdentityLinkUserRepository.DeleteAsync(linkedUser, cancellationToken : cancellationToken);
                }
            }
        }
예제 #9
0
        public virtual async Task LinkAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser)
        {
            if (sourceLinkUser.UserId == targetLinkUser.UserId && sourceLinkUser.TenantId == targetLinkUser.TenantId)
            {
                return;
            }

            if (await IsLinkedAsync(sourceLinkUser, targetLinkUser))
            {
                return;
            }

            var userLink = new IdentityLinkUser(
                GuidGenerator.Create(),
                sourceLinkUser,
                targetLinkUser);
            await IdentityLinkUserRepository.InsertAsync(userLink, true);
        }
예제 #10
0
        public virtual async Task LinkAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser, CancellationToken cancellationToken = default)
        {
            using (CurrentTenant.Change(null))
            {
                if (sourceLinkUser.UserId == targetLinkUser.UserId && sourceLinkUser.TenantId == targetLinkUser.TenantId)
                {
                    return;
                }

                if (await IsLinkedAsync(sourceLinkUser, targetLinkUser, cancellationToken: cancellationToken))
                {
                    return;
                }

                var userLink = new IdentityLinkUser(
                    GuidGenerator.Create(),
                    sourceLinkUser,
                    targetLinkUser);
                await IdentityLinkUserRepository.InsertAsync(userLink, true, cancellationToken);
            }
        }
예제 #11
0
 public virtual async Task <bool> IsLinkedAsync(IdentityLinkUserInfo sourceLinkUser, IdentityLinkUserInfo targetLinkUser)
 {
     return(await IdentityLinkUserRepository.FindAsync(sourceLinkUser, targetLinkUser) != null);
 }