1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-15 10:25:20 +01:00

[PM-6655] Add username empty fallback on passkey (#3101)

* PM-6655 Added fallback "Unknown account" to passkey username and moved it so it can be shared with Android

* PM-6655 Improved code lines formatting
This commit is contained in:
Federico Maccaroni 2024-03-21 13:56:37 -03:00 committed by GitHub
parent b931263662
commit ff49d041be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 18 deletions

View File

@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Bit.Core.Enums;
using Bit.Core.Enums;
using Bit.Core.Models.Domain;
using Bit.Core.Resources.Localization;
using Bit.Core.Utilities;
namespace Bit.Core.Models.View
{
@ -40,4 +39,15 @@ namespace Bit.Core.Models.View
};
}
}
public static class LoginViewExtensions
{
public static string GetMainFido2CredentialUsername(this LoginView loginView)
{
return loginView.MainFido2Credential.UserName
.FallbackOnNullOrWhiteSpace(loginView.MainFido2Credential.UserDisplayName)
.FallbackOnNullOrWhiteSpace(loginView.Username)
.FallbackOnNullOrWhiteSpace(AppResources.UnknownAccount);
}
}
}

View File

@ -7208,6 +7208,15 @@ namespace Bit.Core.Resources.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Unknown account.
/// </summary>
public static string UnknownAccount {
get {
return ResourceManager.GetString("UnknownAccount", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unknown {0} error occurred..
/// </summary>

View File

@ -2942,6 +2942,9 @@ Do you want to switch to this account?</value>
<data name="Passwords" xml:space="preserve">
<value>Passwords</value>
</data>
<data name="UnknownAccount" xml:space="preserve">
<value>Unknown account</value>
</data>
<data name="SetUpAutofill" xml:space="preserve">
<value>Set up auto-fill</value>
</data>

View File

@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Globalization;
using System.Text;
namespace Bit.Core.Utilities
@ -30,5 +29,7 @@ namespace Bit.Core.Utilities
.ToString()
.Normalize(NormalizationForm.FormC);
}
public static string FallbackOnNullOrWhiteSpace(this string s, string fallback) => string.IsNullOrWhiteSpace(s) ? fallback : s;
}
}

View File

@ -2,6 +2,7 @@
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Models.View;
using Bit.Core.Resources.Localization;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Foundation;
@ -148,19 +149,8 @@ namespace Bit.iOS.Core.Utilities
return null;
}
var userName = cipher.Login.MainFido2Credential.UserName;
if (string.IsNullOrWhiteSpace(userName))
{
userName = cipher.Login.MainFido2Credential.UserDisplayName;
if (string.IsNullOrWhiteSpace(userName))
{
userName = cipher.Login.Username;
}
}
return new ASPasskeyCredentialIdentity(cipher.Login.MainFido2Credential.RpId,
userName,
cipher.Login.GetMainFido2CredentialUsername(),
NSData.FromArray(cipher.Login.MainFido2Credential.CredentialId.GuidToRawFormat()),
cipher.Login.MainFido2Credential.UserHandle,
cipher.Id);