Ejemplo n.º 1
0
        private Guid?DecryptCookie(EncryptedDeviceCookie encryptedDeviceCookie)
        {
            string value  = _deviceCookieProtector.Unprotect(encryptedDeviceCookie.EncryptedValue);
            bool   isGuid = Guid.TryParse(value, out var deviceGuid);

            if (isGuid)
            {
                return(deviceGuid);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <bool> IsCookieTrustedForUser(EncryptedDeviceCookie encryptedDeviceCookie, AppUser user)
        {
            Guid?deviceId = DecryptCookie(encryptedDeviceCookie);

            if (deviceId != null)
            {
                int count = await _authDbContext.Users
                            .AsNoTracking()
                            .Where(
                    u => u == user
                    )
                            .Where(
                    u => u.Sessions.Any(
                        s => s.DeviceCookie.Id == deviceId
                        )
                    )
                            .CountAsync();

                return(count == 1);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public async Task <AuthServer.Server.Models.DeviceCookie?> GetDeviceCookieAsync(EncryptedDeviceCookie encryptedDeviceCookie)
        {
            Guid?deviceId = DecryptCookie(encryptedDeviceCookie);

            if (deviceId != null)
            {
                AuthServer.Server.Models.DeviceCookie?deviceCookie = await _authDbContext.DeviceCookies
                                                                     .SingleOrDefaultAsync(d => d.Id == deviceId);

                return(deviceCookie);
            }

            return(null);
        }