diff --git a/src/Core/Models/Domain/UsernameGenerationOptions.cs b/src/Core/Models/Domain/UsernameGenerationOptions.cs index 554783b66..2ca57083e 100644 --- a/src/Core/Models/Domain/UsernameGenerationOptions.cs +++ b/src/Core/Models/Domain/UsernameGenerationOptions.cs @@ -46,7 +46,11 @@ namespace Bit.Core.Models.Domain case ForwardedEmailServiceType.DuckDuckGo: return new ForwarderOptions { ApiKey = DuckDuckGoApiKey }; case ForwardedEmailServiceType.Fastmail: - return new ForwarderOptions { ApiKey = FastMailApiKey }; + return new FastmailForwarderOptions + { + ApiKey = FastMailApiKey, + Website = EmailWebsite + }; case ForwardedEmailServiceType.FirefoxRelay: return new ForwarderOptions { ApiKey = FirefoxRelayApiAccessToken }; case ForwardedEmailServiceType.SimpleLogin: diff --git a/src/Core/Services/EmailForwarders/FastmailForwarder.cs b/src/Core/Services/EmailForwarders/FastmailForwarder.cs index a47229861..7380fd0fc 100644 --- a/src/Core/Services/EmailForwarders/FastmailForwarder.cs +++ b/src/Core/Services/EmailForwarders/FastmailForwarder.cs @@ -9,16 +9,21 @@ using Newtonsoft.Json.Linq; namespace Bit.Core.Services.EmailForwarders { - public class FastmailForwarder : BaseForwarder + public class FastmailForwarderOptions : ForwarderOptions + { + public string Website { get; set; } + } + + public class FastmailForwarder : BaseForwarder { protected override string RequestUri => "https://api.fastmail.com/jmap/api/"; - protected override void ConfigureHeaders(HttpRequestHeaders headers, ForwarderOptions options) + protected override void ConfigureHeaders(HttpRequestHeaders headers, FastmailForwarderOptions options) { headers.Add("Authorization", $"Bearer {options.ApiKey}"); } - protected override async Task GetContentAsync(IApiService apiService, ForwarderOptions options) + protected override async Task GetContentAsync(IApiService apiService, FastmailForwarderOptions options) { string accountId = null; try @@ -55,7 +60,8 @@ namespace Bit.Core.Services.EmailForwarders ["state"] = "enabled", ["description"] = "", ["url"] = "", - ["emailPrefix"] = "" + ["emailPrefix"] = "", + ["forDomain"] = options.Website ?? "" } } }, diff --git a/src/Core/Services/UsernameGenerationService.cs b/src/Core/Services/UsernameGenerationService.cs index 5789dac5c..2ed5454fe 100644 --- a/src/Core/Services/UsernameGenerationService.cs +++ b/src/Core/Services/UsernameGenerationService.cs @@ -148,6 +148,13 @@ namespace Bit.Core.Services .GenerateAsync(_apiService, forwardedEmailOptions); } + if (options.ServiceType == ForwardedEmailServiceType.Fastmail) + { + var fastmailEmailOptions = (FastmailForwarderOptions)options.GetForwarderOptions(); + return await new FastmailForwarder() + .GenerateAsync(_apiService, fastmailEmailOptions); + } + BaseForwarder simpleForwarder = null; switch (options.ServiceType) @@ -161,9 +168,6 @@ namespace Bit.Core.Services case ForwardedEmailServiceType.DuckDuckGo: simpleForwarder = new DuckDuckGoForwarder(); break; - case ForwardedEmailServiceType.Fastmail: - simpleForwarder = new FastmailForwarder(); - break; default: _logger.Value.Error($"Error UsernameGenerationService: ForwardedEmailServiceType {options.ServiceType} not implemented."); return Constants.DefaultUsernameGenerated;