/// <summary> /// Updates the expiration time on the given session record /// </summary> /// <returns>An awaitable task.</returns> /// <param name="record">The record to update.</param> public async Task UpdateSessionExpirationAsync(SessionRecord record) { var txt = PrimitiveSerializer.Serialize(record); using (await m_lock.LockAsync()) { if (!string.IsNullOrWhiteSpace(record.XSRFToken)) { m_xsrf_storage[record.XSRFToken] = txt; } if (!string.IsNullOrWhiteSpace(record.Cookie)) { m_cookie_storage[record.Cookie] = txt; } } }
/// <summary> /// Adds a new session record /// </summary> /// <returns>An awaitable task.</returns> /// <param name="record">The record to add.</param> public async Task AddSessionAsync(SessionRecord record) { var txt = PrimitiveSerializer.Serialize(record); using (await m_lock.LockAsync()) { if (!string.IsNullOrWhiteSpace(record.XSRFToken)) { if (m_xsrf_storage.ContainsKey(record.XSRFToken)) { throw new ArgumentException("Attempted to re-insert an entry into the XSRF token table"); } if (!string.IsNullOrWhiteSpace(record.Cookie) && m_cookie_storage.ContainsKey(record.Cookie)) { throw new ArgumentException("Attempted to re-insert an entry into the cookie token table"); } m_xsrf_storage[record.XSRFToken] = txt; m_cookie_storage[record.Cookie] = txt; } else { if (string.IsNullOrWhiteSpace(record.Cookie)) { throw new ArgumentException("Attempted to inser a record that has neither XSRF nor a cookie"); } if (m_cookie_storage.ContainsKey(record.Cookie)) { throw new ArgumentException("Attempted to re-insert an entry into the cookie token table"); } m_cookie_storage[record.Cookie] = txt; } } }