feedback from fastmail (#3375)

* feedback from fastmail

* follow redirects for getting account id api
This commit is contained in:
Kyle Spearrin 2022-08-25 10:54:02 -04:00 committed by GitHub
parent bd88b5b365
commit bb70113279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 32 additions and 55 deletions

View File

@ -1965,13 +1965,9 @@
"apiKey": {
"message": "API Key"
},
"accountId": {
"message": "Account ID",
"description": "ID is short for 'Identifier'"
},
"ssoKeyConnectorError": {
"message": "Key Connector error: make sure Key Connector is available and working correctly."
},
},
"premiumSubcriptionRequired": {
"message": "Premium subscription required"
},

View File

@ -401,21 +401,11 @@
<input
id="fastmail-apiToken"
type="password"
name="FastMailApiToken"
name="FastmailApiToken"
[(ngModel)]="usernameOptions.forwardedFastmailApiToken"
(blur)="saveUsernameOptions()"
/>
</div>
<div class="box-content-row" appBoxRow>
<label for="fastmail-accountId">{{ "accountId" | i18n }}</label>
<input
id="fastmail-accountId"
type="text"
name="FastmailAccountId"
[(ngModel)]="usernameOptions.forwardedFastmailAccountId"
(blur)="saveUsernameOptions()"
/>
</div>
</ng-container>
</div>
</div>

View File

@ -434,21 +434,11 @@
<input
id="fastmail-apiToken"
type="password"
name="FastMailApiToken"
name="FastmailApiToken"
[(ngModel)]="usernameOptions.forwardedFastmailApiToken"
(blur)="saveUsernameOptions()"
/>
</div>
<div class="box-content-row" appBoxRow>
<label for="fastmail-accountId">{{ "accountId" | i18n }}</label>
<input
id="fastmail-accountId"
type="text"
name="FastmailAccountId"
[(ngModel)]="usernameOptions.forwardedFastmailAccountId"
(blur)="saveUsernameOptions()"
/>
</div>
</ng-container>
</div>
</div>

View File

@ -1982,10 +1982,6 @@
"premiumSubcriptionRequired": {
"message": "Premium subscription required"
},
"accountId": {
"message": "Account ID",
"description": "ID is short for 'Identifier'"
},
"organizationIsDisabled": {
"message": "Organization is disabled."
},

View File

@ -354,16 +354,6 @@
(blur)="saveUsernameOptions()"
/>
</div>
<div class="form-group col-4">
<label for="fastmail-accountId">{{ "accountId" | i18n }}</label>
<input
id="fastmail-accountId"
class="form-control"
type="text"
[(ngModel)]="usernameOptions.forwardedFastmailAccountId"
(blur)="saveUsernameOptions()"
/>
</div>
</div>
</ng-container>
<div class="row" *ngIf="usernameOptions.type === 'subaddress'">

View File

@ -5312,9 +5312,5 @@
},
"numberOfUsers": {
"message": "Number of users"
},
"accountId": {
"message": "Account ID",
"description": "ID is short for 'Identifier'"
}
}

View File

@ -74,7 +74,7 @@ export class GeneratorComponent implements OnInit {
{ name: "SimpleLogin", value: "simplelogin" },
{ name: "AnonAddy", value: "anonaddy" },
{ name: "Firefox Relay", value: "firefoxrelay" },
{ name: "FastMail", value: "fastmail" },
{ name: "Fastmail", value: "fastmail" },
{ name: "DuckDuckGo", value: "duckduckgo" },
];
}

View File

@ -8,9 +8,12 @@ export class FastmailForwarder implements Forwarder {
if (options.apiKey == null || options.apiKey === "") {
throw "Invalid Fastmail API token.";
}
if (options?.fastmail.accountId == null || options.fastmail.accountId === "") {
throw "Invalid Fastmail account ID.";
const accountId = await this.getAccountId(apiService, options);
if (accountId == null || accountId === "") {
throw "Unable to obtain Fastmail masked email account ID.";
}
const requestInit: RequestInit = {
redirect: "manual",
cache: "no-store",
@ -27,13 +30,11 @@ export class FastmailForwarder implements Forwarder {
[
"MaskedEmail/set",
{
accountId: "u" + options.fastmail.accountId,
accountId: accountId,
create: {
"new-masked-email": {
state: "enabled",
description:
(options.website != null ? options.website + " - " : "") +
"Generated by Bitwarden",
description: "",
url: options.website,
emailPrefix: options.fastmail.prefix,
},
@ -59,9 +60,29 @@ export class FastmailForwarder implements Forwarder {
}
}
}
if (response.status === 401) {
if (response.status === 401 || response.status === 403) {
throw "Invalid Fastmail API token.";
}
throw "Unknown Fastmail error occurred.";
}
private async getAccountId(apiService: ApiService, options: ForwarderOptions): Promise<string> {
const requestInit: RequestInit = {
cache: "no-store",
method: "GET",
headers: new Headers({
Authorization: "Bearer " + options.apiKey,
}),
};
const url = "https://api.fastmail.com/.well-known/jmap";
const request = new Request(url, requestInit);
const response = await apiService.nativeFetch(request);
if (response.status === 200) {
const json = await response.json();
if (json.primaryAccounts != null) {
return json.primaryAccounts["https://www.fastmail.com/dev/maskedemail"];
}
}
return null;
}
}

View File

@ -6,7 +6,6 @@ export class ForwarderOptions {
}
export class FastmailForwarderOptions {
accountId: string;
prefix: string;
}

View File

@ -131,7 +131,6 @@ export class UsernameGenerationService implements BaseUsernameGenerationService
} else if (o.forwardedService === "fastmail") {
forwarder = new FastmailForwarder();
forwarderOptions.apiKey = o.forwardedFastmailApiToken;
forwarderOptions.fastmail.accountId = o.forwardedFastmailAccountId;
} else if (o.forwardedService === "duckduckgo") {
forwarder = new DuckDuckGoForwarder();
forwarderOptions.apiKey = o.forwardedDuckDuckGoToken;