Example #1
0
        public override async Task <RemoveAuthenticatorReply> RemoveAuthenticator(RemoveAuthenticatorRequest request, ServerCallContext context)
        {
            Guid    id   = new Guid(request.Id);
            AppUser user = await _userManager.GetUserAsync(context.GetHttpContext().User);

            UserTotpDevice device = await _authDbContext.UserTotpDevices
                                    .Where(d => d.User == user)
                                    .Where(d => d.Id == id)
                                    .SingleAsync();

            int deviceCount = await _authDbContext.UserTotpDevices
                              .Where(d => d.User == user)
                              .CountAsync();

            _authDbContext.Remove(device);
            await _authDbContext.SaveChangesAsync();

            // FIXME: Should really not be in here
            if (deviceCount == 1)
            {
                await _userManager.SetTwoFactorEnabledAsync(user, false);
            }

            return(new RemoveAuthenticatorReply
            {
                Success = true,
            });
        }
Example #2
0
        public override async Task <RemoveAuthenticatorReply> RemoveAuthenticator(RemoveAuthenticatorRequest request, ServerCallContext context)
        {
            Guid    id   = new Guid(request.Id);
            AppUser user = await _userManager.GetUserAsync(context.GetHttpContext().User);

            UserTotpDevice device = await _authDbContext.UserTotpDevices
                                    .Where(d => d.User == user)
                                    .Where(d => d.Id == id)
                                    .SingleAsync();

            _authDbContext.Remove(device);
            await _authDbContext.SaveChangesAsync();

            return(new RemoveAuthenticatorReply
            {
                Success = true,
            });
        }
Example #3
0
        public override async Task <AddNewAuthenticatorAppReply> AddNewAuthenticatorApp(AddNewAuthenticatorAppRequest request, ServerCallContext context)
        {
            AppUser?user = await _userManager.GetUserAsync(context.GetHttpContext().User);

            UserTotpDevice device = new UserTotpDevice
            {
                CreationTime = SystemClock.Instance.GetCurrentInstant(),
                Name         = request.Name,
                SharedSecret = request.SharedSecret,
                User         = user,
            };

            _authDbContext.Add(device);
            await _authDbContext.SaveChangesAsync();

            // FIXME: This should really not be in here
            await _userManager.SetTwoFactorEnabledAsync(user, true);

            return(new AddNewAuthenticatorAppReply
            {
                Success = true,
            });
        }