Преглед на файлове

Ente Auth: Add support for Steam domain (steampowered.com) as an issuer (#1809)

## Description
I don't think I'm the only one using website domains as issuers of TOTP
codes. This change will add support for the Steam domain
(steampowered.com) as an issuer.
Prateek Sunal преди 1 година
родител
ревизия
b00bffd785
променени са 3 файла, в които са добавени 6 реда и са изтрити 6 реда
  1. 3 3
      auth/lib/models/code.dart
  2. 1 1
      auth/lib/onboarding/view/setup_enter_secret_key_page.dart
  3. 2 2
      auth/lib/utils/totp_util.dart

+ 3 - 3
auth/lib/models/code.dart

@@ -128,7 +128,7 @@ class Code {
       final code = Code(
         _getAccount(uri),
         issuer,
-        _getDigits(uri, issuer),
+        _getDigits(uri),
         _getPeriod(uri),
         getSanitizedSecret(uri.queryParameters['secret']!),
         _getAlgorithm(uri),
@@ -201,11 +201,11 @@ class Code {
     }
   }
 
-  static int _getDigits(Uri uri, String issuer) {
+  static int _getDigits(Uri uri) {
     try {
       return int.parse(uri.queryParameters['digits']!);
     } catch (e) {
-      if (issuer.toLowerCase() == "steam") {
+      if (uri.host == "steam") {
         return steamDigits;
       }
       return defaultDigits;

+ 1 - 1
auth/lib/onboarding/view/setup_enter_secret_key_page.dart

@@ -240,7 +240,7 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
       final account = _accountController.text.trim();
       final issuer = _issuerController.text.trim();
       final secret = _secretController.text.trim().replaceAll(' ', '');
-      final isStreamCode = issuer.toLowerCase() == "steam";
+      final isStreamCode = issuer.toLowerCase() == "steam" || issuer.toLowerCase().contains('steampowered.com');
       if (widget.code != null && widget.code!.secret != secret) {
         ButtonResult? result = await showChoiceActionSheet(
           context,

+ 2 - 2
auth/lib/utils/totp_util.dart

@@ -4,7 +4,7 @@ import 'package:otp/otp.dart' as otp;
 import 'package:steam_totp/steam_totp.dart';
 
 String getOTP(Code code) {
-  if (code.issuer.toLowerCase() == 'steam') {
+  if (code.type == Type.steam) {
     return _getSteamCode(code);
   }
   if (code.type == Type.hotp) {
@@ -39,7 +39,7 @@ String _getSteamCode(Code code, [bool isNext = false]) {
 }
 
 String getNextTotp(Code code) {
-  if (code.issuer.toLowerCase() == 'steam') {
+  if (code.type == Type.steam) {
     return _getSteamCode(code, true);
   }
   return otp.OTP.generateTOTPCodeString(