mirror of
https://github.com/bitwarden/server.git
synced 2025-04-23 14:05:10 -05:00

* Get limited life attachment download URL This change limits url download to a 1min lifetime. This requires moving to a new container to allow for non-public blob access. Clients will have to call GetAttachmentData api function to receive the download URL. For backwards compatibility, attachment URLs are still present, but will not work for attachments stored in non-public access blobs. * Make GlobalSettings interface for testing * Test LocalAttachmentStorageService equivalence * Remove comment * Add missing globalSettings using * Simplify default attachment container * Default to attachments containe for existing methods A new upload method will be made for uploading to attachments-v2. For compatibility for clients which don't use these new methods, we need to still use the old container. The new container will be used only for new uploads * Remove Default MetaData fixture. * Keep attachments container blob-level security for all instances * Close unclosed FileStream * Favor default value for noop services
55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using System;
|
|
using IdentityServer4.Configuration;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Caching.Redis;
|
|
using Microsoft.Extensions.Options;
|
|
using Bit.Core.Settings;
|
|
|
|
namespace Bit.Core.IdentityServer
|
|
{
|
|
public class ConfigureOpenIdConnectDistributedOptions : IPostConfigureOptions<CookieAuthenticationOptions>
|
|
{
|
|
private readonly IdentityServerOptions _idsrv;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly GlobalSettings _globalSettings;
|
|
|
|
public ConfigureOpenIdConnectDistributedOptions(IHttpContextAccessor httpContextAccessor, GlobalSettings globalSettings,
|
|
IdentityServerOptions idsrv)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
|
|
_globalSettings = globalSettings;
|
|
_idsrv = idsrv;
|
|
}
|
|
|
|
public void PostConfigure(string name, CookieAuthenticationOptions options)
|
|
{
|
|
options.CookieManager = new DistributedCacheCookieManager();
|
|
|
|
if (name != AuthenticationSchemes.BitwardenExternalCookieAuthenticationScheme)
|
|
{
|
|
// Ignore
|
|
return;
|
|
}
|
|
|
|
options.Cookie.Name = AuthenticationSchemes.BitwardenExternalCookieAuthenticationScheme;
|
|
options.Cookie.IsEssential = true;
|
|
options.Cookie.SameSite = _idsrv.Authentication.CookieSameSiteMode;
|
|
options.TicketDataFormat = new DistributedCacheTicketDataFormatter(_httpContextAccessor, name);
|
|
|
|
if (string.IsNullOrWhiteSpace(_globalSettings.IdentityServer?.RedisConnectionString))
|
|
{
|
|
options.SessionStore = new MemoryCacheTicketStore();
|
|
}
|
|
else
|
|
{
|
|
var redisOptions = new RedisCacheOptions
|
|
{
|
|
Configuration = _globalSettings.IdentityServer.RedisConnectionString,
|
|
};
|
|
options.SessionStore = new RedisCacheTicketStore(redisOptions);
|
|
}
|
|
}
|
|
}
|
|
}
|