mirror of
https://github.com/bitwarden/mobile.git
synced 2024-09-27 03:52:57 +02:00
PM-7258 Updated Android Credential creation details on description to be localized and passed the user email for further details. (#3162)
This commit is contained in:
parent
350a22d20e
commit
c88287ec64
@ -25,20 +25,26 @@ namespace Bit.Droid.Autofill
|
||||
public const int UniqueCreateRequestCode = 94556024;
|
||||
|
||||
private readonly LazyResolve<IVaultTimeoutService> _vaultTimeoutService = new LazyResolve<IVaultTimeoutService>();
|
||||
private readonly LazyResolve<IStateService> _stateService = new LazyResolve<IStateService>();
|
||||
private readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>();
|
||||
|
||||
public override void OnBeginCreateCredentialRequest(BeginCreateCredentialRequest request,
|
||||
public override async void OnBeginCreateCredentialRequest(BeginCreateCredentialRequest request,
|
||||
CancellationSignal cancellationSignal, IOutcomeReceiver callback)
|
||||
{
|
||||
var response = ProcessCreateCredentialsRequestAsync(request);
|
||||
if (response != null)
|
||||
try
|
||||
{
|
||||
callback.OnResult(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.OnError("Error creating credential");
|
||||
var response = await ProcessCreateCredentialsRequestAsync(request);
|
||||
if (response != null)
|
||||
{
|
||||
await MainThread.InvokeOnMainThreadAsync(() => callback.OnResult(response));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Value.Exception(ex);
|
||||
}
|
||||
MainThread.BeginInvokeOnMainThread(() => callback.OnError(AppResources.ErrorCreatingPasskey));
|
||||
}
|
||||
|
||||
public override async void OnBeginGetCredentialRequest(BeginGetCredentialRequest request,
|
||||
@ -70,16 +76,16 @@ namespace Bit.Droid.Autofill
|
||||
catch (GetCredentialException e)
|
||||
{
|
||||
_logger.Value.Exception(e);
|
||||
callback.OnError(e.ErrorMessage ?? "Error getting credentials");
|
||||
callback.OnError(e.ErrorMessage ?? AppResources.ErrorReadingPasskey);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Value.Exception(e);
|
||||
throw;
|
||||
_logger.Value.Exception(e);
|
||||
callback.OnError(AppResources.ErrorReadingPasskey);
|
||||
}
|
||||
}
|
||||
|
||||
private BeginCreateCredentialResponse ProcessCreateCredentialsRequestAsync(
|
||||
private async Task<BeginCreateCredentialResponse> ProcessCreateCredentialsRequestAsync(
|
||||
BeginCreateCredentialRequest request)
|
||||
{
|
||||
if (request == null) { return null; }
|
||||
@ -92,22 +98,25 @@ namespace Bit.Droid.Autofill
|
||||
}
|
||||
else if (request is BeginCreatePublicKeyCredentialRequest beginCreatePublicKeyCredentialRequest)
|
||||
{
|
||||
return HandleCreatePasskeyQuery(beginCreatePublicKeyCredentialRequest);
|
||||
return await HandleCreatePasskeyQueryAsync(beginCreatePublicKeyCredentialRequest);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private BeginCreateCredentialResponse HandleCreatePasskeyQuery(BeginCreatePublicKeyCredentialRequest optionRequest)
|
||||
private async Task<BeginCreateCredentialResponse> HandleCreatePasskeyQueryAsync(BeginCreatePublicKeyCredentialRequest optionRequest)
|
||||
{
|
||||
var intent = new Intent(ApplicationContext, typeof(MainActivity));
|
||||
intent.PutExtra(CredentialProviderConstants.Fido2CredentialAction, CredentialProviderConstants.Fido2CredentialCreate);
|
||||
var pendingIntent = PendingIntent.GetActivity(ApplicationContext, UniqueCreateRequestCode, intent,
|
||||
AndroidHelpers.AddPendingIntentMutabilityFlag(PendingIntentFlags.UpdateCurrent, true));
|
||||
|
||||
//TODO: i81n needs to be done
|
||||
var createEntryBuilder = new CreateEntry.Builder("Bitwarden Vault", pendingIntent)
|
||||
.SetDescription("Your passkey will be saved securely to the Bitwarden Vault. You can use it from any other device for sign-in in the future.")
|
||||
var userEmail = await GetSafeActiveAccountEmailAsync();
|
||||
|
||||
var createEntryBuilder = new CreateEntry.Builder(userEmail ?? AppResources.Bitwarden, pendingIntent)
|
||||
.SetDescription(userEmail != null
|
||||
? string.Format(AppResources.YourPasskeyWillBeSavedToYourBitwardenVaultForX, userEmail)
|
||||
: AppResources.YourPasskeyWillBeSavedToYourBitwardenVault)
|
||||
.Build();
|
||||
|
||||
var createCredentialResponse = new BeginCreateCredentialResponse.Builder()
|
||||
@ -141,5 +150,19 @@ namespace Bit.Droid.Autofill
|
||||
{
|
||||
callback.OnResult(null);
|
||||
}
|
||||
|
||||
private async Task<string> GetSafeActiveAccountEmailAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _stateService.Value.GetEmailAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// if it throws to get the user's email then we log and continue showing a more generic message
|
||||
_logger.Value.Exception(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@ -14,12 +13,10 @@ namespace Bit.Core.Resources.Localization {
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// This class was generated by MSBuild using the GenerateResource task.
|
||||
/// To add or remove a member, edit your .resx file then rerun MSBuild.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class AppResources {
|
||||
@ -8084,6 +8081,24 @@ namespace Bit.Core.Resources.Localization {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Your passkey will be saved to your Bitwarden vault.
|
||||
/// </summary>
|
||||
public static string YourPasskeyWillBeSavedToYourBitwardenVault {
|
||||
get {
|
||||
return ResourceManager.GetString("YourPasskeyWillBeSavedToYourBitwardenVault", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Your passkey will be saved to your Bitwarden vault for {0}.
|
||||
/// </summary>
|
||||
public static string YourPasskeyWillBeSavedToYourBitwardenVaultForX {
|
||||
get {
|
||||
return ResourceManager.GetString("YourPasskeyWillBeSavedToYourBitwardenVaultForX", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Your request has been sent to your admin..
|
||||
/// </summary>
|
||||
|
@ -2969,4 +2969,10 @@ Do you want to switch to this account?</value>
|
||||
<data name="ThirdDotSelectBitwardenToUseForPasswordsAndPasskeys" xml:space="preserve">
|
||||
<value>3. Select "Bitwarden" to use for passwords and passkeys</value>
|
||||
</data>
|
||||
<data name="YourPasskeyWillBeSavedToYourBitwardenVault" xml:space="preserve">
|
||||
<value>Your passkey will be saved to your Bitwarden vault</value>
|
||||
</data>
|
||||
<data name="YourPasskeyWillBeSavedToYourBitwardenVaultForX" xml:space="preserve">
|
||||
<value>Your passkey will be saved to your Bitwarden vault for {0}</value>
|
||||
</data>
|
||||
</root>
|
||||
|
Loading…
Reference in New Issue
Block a user