Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Enable fallback to TOTP if both passkey & totp are enabled

Neeraj Gupta1b9f6de6bdde
diff --git a/mobile/lib/generated/intl/messages_en.dart b/mobile/lib/generated/intl/messages_en.dart
index 5ea496bc88..9cef546a84 100644
--- a/mobile/lib/generated/intl/messages_en.dart
+++ b/mobile/lib/generated/intl/messages_en.dart
@@ -1070,6 +1070,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Your session has expired. Please login again."),
"loginTerms": MessageLookupByLibrary.simpleMessage(
"By clicking log in, I agree to the <u-terms>terms of service</u-terms> and <u-policy>privacy policy</u-policy>"),
+ "loginWithTOTP":
+ MessageLookupByLibrary.simpleMessage("Login with TOTP"),
"logout": MessageLookupByLibrary.simpleMessage("Logout"),
"logsDialogBody": MessageLookupByLibrary.simpleMessage(
"This will send across logs to help us debug your issue. Please note that file names will be included to help track issues with specific files."),
diff --git a/mobile/lib/generated/l10n.dart b/mobile/lib/generated/l10n.dart
index 103bcf57f7..a4b58b7919 100644
--- a/mobile/lib/generated/l10n.dart
+++ b/mobile/lib/generated/l10n.dart
@@ -8719,6 +8719,16 @@ class S {
);
}
+ /// `Login with TOTP`
+ String get loginWithTOTP {
+ return Intl.message(
+ 'Login with TOTP',
+ name: 'loginWithTOTP',
+ desc: '',
+ args: [],
+ );
+ }
+
/// `Verification is still pending`
String get passKeyPendingVerification {
return Intl.message(
diff --git a/mobile/lib/l10n/intl_en.arb b/mobile/lib/l10n/intl_en.arb
index 0c06aa2bd8..ca09f20599 100644
--- a/mobile/lib/l10n/intl_en.arb
+++ b/mobile/lib/l10n/intl_en.arb
@@ -1233,6 +1233,7 @@
"waitingForVerification": "Waiting for verification...",
"passkey": "Passkey",
"passkeyAuthTitle": "Passkey verification",
+ "loginWithTOTP": "Login with TOTP",
"passKeyPendingVerification": "Verification is still pending",
"loginSessionExpired": "Session expired",
"loginSessionExpiredDetails": "Your session has expired. Please login again.",
diff --git a/mobile/lib/services/passkey_service.dart b/mobile/lib/services/passkey_service.dart
index 37d7aa5392..ed94af884a 100644
--- a/mobile/lib/services/passkey_service.dart
+++ b/mobile/lib/services/passkey_service.dart
@@ -1,4 +1,5 @@
import "package:flutter/cupertino.dart";
+import "package:flutter/foundation.dart";
import "package:logging/logging.dart";
import "package:photos/core/network/network.dart";
import "package:photos/utils/dialog_util.dart";
@@ -24,6 +25,10 @@ class PasskeyService {
return response.data!["isPasskeyRecoveryEnabled"] as bool;
}
+ String get accountsUrl {
+ return kDebugMode ? "http://localhost:3001" : "https://accounts.ente.io";
+ }
+
Future<void> configurePasskeyRecovery(
String secret,
String userEncryptedSecret,
@@ -42,7 +47,7 @@ class PasskeyService {
Future<void> openPasskeyPage(BuildContext context) async {
try {
final jwtToken = await getJwtToken();
- final url = "https://accounts.ente.io/passkeys?token=$jwtToken";
+ final url = "$accountsUrl/passkeys?token=$jwtToken";
await launchUrlString(
url,
mode: LaunchMode.externalApplication,
diff --git a/mobile/lib/services/user_service.dart b/mobile/lib/services/user_service.dart
index 367dd980c4..027cd66736 100644
--- a/mobile/lib/services/user_service.dart
+++ b/mobile/lib/services/user_service.dart
@@ -399,13 +399,18 @@ class UserService {
if (response.statusCode == 200) {
Widget page;
final String passkeySessionID = response.data["passkeySessionID"];
- final String twoFASessionID = response.data["twoFactorSessionID"];
-
- if (twoFASessionID.isNotEmpty) {
+ String twoFASessionID = response.data["twoFactorSessionID"];
+ if (twoFASessionID.isEmpty) {
+ twoFASessionID = response.data["twoFactorSessionIDV2"];
+ }
+ if (passkeySessionID.isNotEmpty) {
+ page = PasskeyPage(
+ passkeySessionID,
+ totp2FASessionID: twoFASessionID,
+ );
+ } else if (twoFASessionID.isNotEmpty) {
await setTwoFactor(value: true);
page = TwoFactorAuthenticationPage(twoFASessionID);
- } else if (passkeySessionID.isNotEmpty) {
- page = PasskeyPage(passkeySessionID);
} else {
await _saveConfiguration(response);
if (Configuration.instance.getEncryptedToken() != null) {
@@ -614,7 +619,7 @@ class UserService {
SetupSRPResponse.fromJson(response.data);
final serverB =
SRP6Util.decodeBigInt(base64Decode(setupSRPResponse.srpB));
- // ignore: unused_local_variable, need to calculate secret to get M1
+ // ignore: unused_local_variable, need to calculate secret to get M1
final clientS = client.calculateSecret(serverB);
final clientM = client.calculateClientEvidenceMessage();
// ignore: unused_local_variable
@@ -713,15 +718,18 @@ class UserService {
);
if (response.statusCode == 200) {
Widget page;
- final String twoFASessionID = response.data["twoFactorSessionID"];
+ String twoFASessionID = response.data["twoFactorSessionID"];
+ if (twoFASessionID.isEmpty) {
+ twoFASessionID = response.data["twoFactorSessionIDV2"];
+ }
final String passkeySessionID = response.data["passkeySessionID"];
Configuration.instance.setVolatilePassword(userPassword);
- if (twoFASessionID.isNotEmpty) {
+ if (passkeySessionID.isNotEmpty) {
+ page = PasskeyPage(passkeySessionID, totp2FASessionID: twoFASessionID);
+ } else if (twoFASessionID.isNotEmpty) {
await setTwoFactor(value: true);
page = TwoFactorAuthenticationPage(twoFASessionID);
- } else if (passkeySessionID.isNotEmpty) {
- page = PasskeyPage(passkeySessionID);
} else {
await _saveConfiguration(response);
if (Configuration.instance.getEncryptedToken() != null) {
diff --git a/mobile/lib/ui/account/passkey_page.dart b/mobile/lib/ui/account/passkey_page.dart
index e1986b8652..3d8d088bea 100644
--- a/mobile/lib/ui/account/passkey_page.dart
+++ b/mobile/lib/ui/account/passkey_page.dart
@@ -1,6 +1,7 @@
import "dart:async";
import 'dart:convert';
+import "package:flutter/foundation.dart";
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
@@ -8,19 +9,24 @@ import "package:photos/core/errors.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/models/account/two_factor.dart";
+import "package:photos/services/passkey_service.dart";
import 'package:photos/services/user_service.dart';
+import "package:photos/ui/account/two_factor_authentication_page.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/utils/dialog_util.dart";
+import "package:photos/utils/navigation_util.dart";
import "package:photos/utils/toast_util.dart";
import "package:uni_links/uni_links.dart";
import 'package:url_launcher/url_launcher_string.dart';
class PasskeyPage extends StatefulWidget {
final String sessionID;
+ final String totp2FASessionID;
const PasskeyPage(
this.sessionID, {
+ required this.totp2FASessionID,
super.key,
});
@@ -46,8 +52,9 @@ class _PasskeyPageState extends State<PasskeyPage> {
}
Future<void> launchPasskey() async {
+ final String accountsUrl = PasskeyService.instance.accountsUrl;
await launchUrlString(
- "https://accounts.ente.io/passkeys/verify?"
+ "$accountsUrl/passkeys/verify?"
"passkeySessionID=${widget.sessionID}"
"&redirect=ente://passkey"
"&clientPackage=io.ente.photos",
@@ -178,6 +185,30 @@ class _PasskeyPageState extends State<PasskeyPage> {
shouldSurfaceExecutionStates: true,
),
const Padding(padding: EdgeInsets.all(30)),
+ if (widget.totp2FASessionID.isNotEmpty)
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ routeToPage(
+ context,
+ TwoFactorAuthenticationPage(
+ widget.totp2FASessionID,
+ ),
+ );
+ },
+ child: Container(
+ padding: const EdgeInsets.all(10),
+ child: Center(
+ child: Text(
+ context.l10n.loginWithTOTP,
+ style: const TextStyle(
+ decoration: TextDecoration.underline,
+ fontSize: 12,
+ ),
+ ),
+ ),
+ ),
+ ),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {