mirror of
https://github.com/bitwarden/mobile
synced 2026-01-04 01:23:15 +00:00
[PM-1835] Add ForwardEmail alias to Username Generator (#2803)
* Add ForwardEmail alias to Username Generator * remove unnecessary initializer * Corrected order of alias Generators * PM-4307 - Trigger ForwardEmailDomainName PropertyChanged after initialization
This commit is contained in:
@@ -15,5 +15,7 @@ namespace Bit.Core.Enums
|
||||
DuckDuckGo = 3,
|
||||
[LocalizableEnum("Fastmail")]
|
||||
Fastmail = 4,
|
||||
[LocalizableEnum("ForwardEmail")]
|
||||
ForwardEmail = 5,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Bit.Core.Models.Domain
|
||||
public string FastMailApiKey { get; set; }
|
||||
public string AnonAddyApiAccessToken { get; set; }
|
||||
public string AnonAddyDomainName { get; set; }
|
||||
public string ForwardEmailApiAccessToken { get; set; }
|
||||
public string ForwardEmailDomainName { get; set; }
|
||||
public string EmailWebsite { get; set; }
|
||||
|
||||
public ForwarderOptions GetForwarderOptions()
|
||||
@@ -49,6 +51,12 @@ namespace Bit.Core.Models.Domain
|
||||
return new ForwarderOptions { ApiKey = FirefoxRelayApiAccessToken };
|
||||
case ForwardedEmailServiceType.SimpleLogin:
|
||||
return new ForwarderOptions { ApiKey = SimpleLoginApiKey };
|
||||
case ForwardedEmailServiceType.ForwardEmail:
|
||||
return new ForwardEmailForwarderOptions
|
||||
{
|
||||
ApiKey = ForwardEmailApiAccessToken,
|
||||
DomainName = ForwardEmailDomainName
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
52
src/Core/Services/EmailForwarders/ForwardEmailForwarder.cs
Normal file
52
src/Core/Services/EmailForwarders/ForwardEmailForwarder.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Abstractions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Bit.Core.Services.EmailForwarders
|
||||
{
|
||||
public class ForwardEmailForwarderOptions : ForwarderOptions
|
||||
{
|
||||
public string DomainName { get; set; }
|
||||
}
|
||||
|
||||
public class ForwardEmailForwarder : BaseForwarder<ForwardEmailForwarderOptions>
|
||||
{
|
||||
private readonly string _domain;
|
||||
protected override string RequestUri => $"https://api.forwardemail.net/v1/domains/{_domain}/aliases";
|
||||
|
||||
public ForwardEmailForwarder(string domain)
|
||||
{
|
||||
_domain = domain;
|
||||
}
|
||||
|
||||
protected override bool CanGenerate(ForwardEmailForwarderOptions options)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(options.ApiKey) && !string.IsNullOrWhiteSpace(options.DomainName);
|
||||
}
|
||||
|
||||
protected override void ConfigureHeaders(HttpRequestHeaders headers, ForwardEmailForwarderOptions options)
|
||||
{
|
||||
headers.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(options.ApiKey + ":"))}");
|
||||
}
|
||||
|
||||
protected override Task<HttpContent> GetContentAsync(IApiService apiService, ForwardEmailForwarderOptions options)
|
||||
{
|
||||
return Task.FromResult<HttpContent>(new StringContent(
|
||||
JsonConvert.SerializeObject(
|
||||
new
|
||||
{
|
||||
description = "Generated by Bitwarden."
|
||||
}), Encoding.UTF8, "application/json"));
|
||||
}
|
||||
|
||||
protected override string HandleResponse(JObject result)
|
||||
{
|
||||
return $"{result["name"]}@{result["domain"]?["name"] ?? _domain}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,13 @@ namespace Bit.Core.Services
|
||||
.GenerateAsync(_apiService, (AnonAddyForwarderOptions)options.GetForwarderOptions());
|
||||
}
|
||||
|
||||
if (options.ServiceType == ForwardedEmailServiceType.ForwardEmail)
|
||||
{
|
||||
var forwardedEmailOptions = (ForwardEmailForwarderOptions)options.GetForwarderOptions();
|
||||
return await new ForwardEmailForwarder(forwardedEmailOptions.DomainName)
|
||||
.GenerateAsync(_apiService, forwardedEmailOptions);
|
||||
}
|
||||
|
||||
BaseForwarder<ForwarderOptions> simpleForwarder = null;
|
||||
|
||||
switch (options.ServiceType)
|
||||
|
||||
Reference in New Issue
Block a user