示例#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);
        }
示例#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);
        }
示例#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);
        }