diff --git a/apps/web/webpack.config.js b/apps/web/webpack.config.js
index 8b56f9bb12..df02691664 100644
--- a/apps/web/webpack.config.js
+++ b/apps/web/webpack.config.js
@@ -265,6 +265,7 @@ const devServer =
https://*.braintree-api.com
https://*.blob.core.windows.net
https://app.simplelogin.io/api/alias/random/new
+ https://quack.duckduckgo.com/api/email/addresses
https://app.anonaddy.com/api/v1/aliases;
object-src
'self'
diff --git a/libs/angular/src/components/generator.component.ts b/libs/angular/src/components/generator.component.ts
index be4040799b..3d819b333b 100644
--- a/libs/angular/src/components/generator.component.ts
+++ b/libs/angular/src/components/generator.component.ts
@@ -74,6 +74,7 @@ export class GeneratorComponent implements OnInit {
{ name: "SimpleLogin", value: "simplelogin" },
{ name: "AnonAddy", value: "anonaddy" },
{ name: "Firefox Relay", value: "firefoxrelay" },
+ { name: "DuckDuckGo", value: "duckduckgo" },
// { name: "FastMail", value: "fastmail" },
];
}
diff --git a/libs/common/src/services/usernameGeneration.service.ts b/libs/common/src/services/usernameGeneration.service.ts
index cde3365292..217505f25b 100644
--- a/libs/common/src/services/usernameGeneration.service.ts
+++ b/libs/common/src/services/usernameGeneration.service.ts
@@ -132,6 +132,11 @@ export class UsernameGenerationService implements BaseUsernameGenerationService
return null;
}
return this.generateFirefoxRelayAlias(o.forwardedFirefoxApiToken, o.website);
+ } else if (o.forwardedService === "duckduckgo") {
+ if (o.forwardedDuckDuckGoToken == null || o.forwardedDuckDuckGoToken === "") {
+ return null;
+ }
+ return this.generateDuckDuckGoAlias(o.forwardedDuckDuckGoToken);
}
return null;
@@ -274,4 +279,31 @@ export class UsernameGenerationService implements BaseUsernameGenerationService
}
throw "Unknown Firefox Relay error occurred.";
}
+
+ private async generateDuckDuckGoAlias(apiToken: string): Promise {
+ if (apiToken == null || apiToken === "") {
+ throw "Invalid DuckDuckGo API token.";
+ }
+ const requestInit: RequestInit = {
+ redirect: "manual",
+ cache: "no-store",
+ method: "POST",
+ headers: new Headers({
+ Authorization: "Bearer " + apiToken,
+ "Content-Type": "application/json",
+ }),
+ };
+ const url = "https://quack.duckduckgo.com/api/email/addresses";
+ const request = new Request(url, requestInit);
+ const response = await this.apiService.nativeFetch(request);
+ if (response.status === 200 || response.status === 201) {
+ const json = await response.json();
+ if (json.address) {
+ return `${json.address}@duck.com`;
+ }
+ } else if (response.status === 401) {
+ throw "Invalid DuckDuckGo API token.";
+ }
+ throw "Unknown DuckDuckGo error occurred.";
+ }
}