A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: fix 2fa codes not being sent
Abdullah Atta400aa574cded
diff --git a/packages/core/src/api/mfa-manager.ts b/packages/core/src/api/mfa-manager.tsindex cb8bfda73..5069c4590 100644--- a/packages/core/src/api/mfa-manager.ts+++ b/packages/core/src/api/mfa-manager.ts@@ -92,7 +92,10 @@ class MFAManager {}async sendCode(method: "sms" | "email") {- const token = await this.tokenManager.getAccessToken();+ const token = await this.tokenManager.getAccessToken([+ "IdentityServerApi",+ "auth:grant_types:mfa"+ ]);if (!token) throw new Error("Unauthorized.");return await http.post(diff --git a/packages/core/src/api/token-manager.ts b/packages/core/src/api/token-manager.tsindex daf544359..812c3d1a5 100644--- a/packages/core/src/api/token-manager.ts+++ b/packages/core/src/api/token-manager.ts@@ -32,6 +32,15 @@ export type Token = {refresh_token: string;};+type Scope = (typeof SCOPES)[number];++const SCOPES = [+ "notesnook.sync",+ "offline_access",+ "IdentityServerApi",+ "auth:grant_types:mfa",+ "auth:grant_types:mfa_password"+] as const;const ENDPOINTS = {token: "/connect/token",revoke: "/connect/revocation",@@ -79,10 +88,14 @@ class TokenManager {return scopes.includes("offline_access") && Boolean(refresh_token);}- async getAccessToken(forceRenew = false) {+ async getAccessToken(+ scopes: Scope[] = ["notesnook.sync", "IdentityServerApi"],+ forceRenew = false+ ) {return await getSafeToken(async () => {const token = await this.getToken(true, forceRenew);- if (!token || token.scope.includes("auth:grant_types")) return;+ if (!token) return;+ if (!scopes.some((s) => token.scope.includes(s))) return;return token.access_token;}, "Error getting access token:");}diff --git a/packages/core/src/api/user-manager.ts b/packages/core/src/api/user-manager.tsindex dc93155b7..734cefed6 100644--- a/packages/core/src/api/user-manager.ts+++ b/packages/core/src/api/user-manager.ts@@ -191,7 +191,7 @@ class UserManager {username: email,password: hashedPassword,grant_type: code ? "mfa" : "password",- scope: "notesnook.sync offline_access openid IdentityServerApi",+ scope: "notesnook.sync offline_access IdentityServerApi",client_id: "notesnook","mfa:code": code,"mfa:method": method