allow setting vault url for environment

This commit is contained in:
Kyle Spearrin 2017-08-28 17:50:17 -04:00
parent 32a8676572
commit 910f0083cd
7 changed files with 67 additions and 2 deletions

View file

@ -11,6 +11,7 @@ namespace Bit.App.Abstractions
bool AutofillPasswordField { get; set; }
string SecurityStamp { get; set; }
string BaseUrl { get; set; }
string VaultUrl { get; set; }
string ApiUrl { get; set; }
string IdentityUrl { get; set; }
}

View file

@ -35,6 +35,7 @@
public const string LastSync = "other:lastSync";
public const string LastBuildKey = "LastBuild";
public const string BaseUrl = "other:baseUrl";
public const string VaultUrl = "other:vaultUrl";
public const string ApiUrl = "other:apiUrl";
public const string IdentityUrl = "other:identityUrl";

View file

@ -26,6 +26,7 @@ namespace Bit.App.Pages
}
public FormEntryCell BaseUrlCell { get; set; }
public FormEntryCell VaultUrlCell { get; set; }
public FormEntryCell ApiUrlCell { get; set; }
public FormEntryCell IdentityUrlCell { get; set; }
public StackLayout StackLayout { get; set; }
@ -40,7 +41,9 @@ namespace Bit.App.Pages
IdentityUrlCell.Entry.Text = _appSettings.IdentityUrl;
ApiUrlCell = new FormEntryCell(AppResources.ApiUrl, nextElement: IdentityUrlCell.Entry, entryKeyboard: Keyboard.Url);
ApiUrlCell.Entry.Text = _appSettings.ApiUrl;
BaseUrlCell = new FormEntryCell(AppResources.ServerUrl, nextElement: ApiUrlCell.Entry, entryKeyboard: Keyboard.Url);
VaultUrlCell = new FormEntryCell(AppResources.VaultUrl, nextElement: ApiUrlCell.Entry, entryKeyboard: Keyboard.Url);
VaultUrlCell.Entry.Text = _appSettings.VaultUrl;
BaseUrlCell = new FormEntryCell(AppResources.ServerUrl, nextElement: VaultUrlCell.Entry, entryKeyboard: Keyboard.Url);
BaseUrlCell.Entry.Text = _appSettings.BaseUrl;
var table = new FormTableView
@ -69,6 +72,7 @@ namespace Bit.App.Pages
{
new TableSection(AppResources.CustomEnvironment)
{
VaultUrlCell,
ApiUrlCell,
IdentityUrlCell
}
@ -120,6 +124,7 @@ namespace Bit.App.Pages
BaseUrlCell.InitEvents();
IdentityUrlCell.InitEvents();
ApiUrlCell.InitEvents();
VaultUrlCell.InitEvents();
StackLayout.LayoutChanged += Layout_LayoutChanged;
BaseUrlCell.Entry.FocusWithDelay();
}
@ -129,6 +134,7 @@ namespace Bit.App.Pages
BaseUrlCell.Dispose();
IdentityUrlCell.Dispose();
ApiUrlCell.Dispose();
VaultUrlCell.Dispose();
StackLayout.LayoutChanged -= Layout_LayoutChanged;
}
@ -156,6 +162,20 @@ namespace Bit.App.Pages
BaseUrlCell.Entry.Text = null;
}
if(!string.IsNullOrWhiteSpace(VaultUrlCell.Entry.Text))
{
VaultUrlCell.Entry.Text = FixUrl(VaultUrlCell.Entry.Text);
if(!Uri.TryCreate(VaultUrlCell.Entry.Text, UriKind.Absolute, out result))
{
_userDialogs.Alert(string.Format(AppResources.FormattedIncorrectly, AppResources.VaultUrl));
return;
}
}
else
{
VaultUrlCell.Entry.Text = null;
}
if(!string.IsNullOrWhiteSpace(ApiUrlCell.Entry.Text))
{
ApiUrlCell.Entry.Text = FixUrl(ApiUrlCell.Entry.Text);
@ -187,6 +207,7 @@ namespace Bit.App.Pages
_appSettings.BaseUrl = BaseUrlCell.Entry.Text;
_appSettings.IdentityUrl = IdentityUrlCell.Entry.Text;
_appSettings.ApiUrl = ApiUrlCell.Entry.Text;
_appSettings.VaultUrl = VaultUrlCell.Entry.Text;
_userDialogs.Toast(AppResources.EnvironmentSaved);
_googleAnalyticsService.TrackAppEvent("SetEnvironmentUrls");
await Navigation.PopForDeviceAsync();

View file

@ -26,6 +26,7 @@ namespace Bit.App.Pages
private IGoogleAnalyticsService _googleAnalyticsService;
private ITwoFactorApiRepository _twoFactorApiRepository;
private IPushNotification _pushNotification;
private IAppSettingsService _appSettingsService;
private readonly string _email;
private readonly string _masterPasswordHash;
private readonly SymmetricCryptoKey _key;
@ -48,6 +49,7 @@ namespace Bit.App.Pages
_authService = Resolver.Resolve<IAuthService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_syncService = Resolver.Resolve<ISyncService>();
_appSettingsService = Resolver.Resolve<IAppSettingsService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_twoFactorApiRepository = Resolver.Resolve<ITwoFactorApiRepository>();
_pushNotification = Resolver.Resolve<IPushNotification>();
@ -185,9 +187,19 @@ namespace Bit.App.Pages
var host = WebUtility.UrlEncode(duoParams["Host"].ToString());
var req = WebUtility.UrlEncode(duoParams["Signature"].ToString());
var vaultUrl = "https://vault.bitwarden.com";
if(!string.IsNullOrWhiteSpace(_appSettingsService.BaseUrl))
{
vaultUrl = _appSettingsService.BaseUrl;
}
else if(!string.IsNullOrWhiteSpace(_appSettingsService.VaultUrl))
{
vaultUrl = _appSettingsService.VaultUrl;
}
var webView = new HybridWebView
{
Uri = $"https://vault.bitwarden.com/duo-connector.html?host={host}&request={req}",
Uri = $"{vaultUrl}/duo-connector.html?host={host}&request={req}",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
MinimumHeightRequest = 400

View file

@ -2392,6 +2392,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Vault Server URL.
/// </summary>
public static string VaultUrl {
get {
return ResourceManager.GetString("VaultUrl", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Verification Code.
/// </summary>

View file

@ -1024,4 +1024,7 @@
<data name="ServerUrl" xml:space="preserve">
<value>Server URL</value>
</data>
<data name="VaultUrl" xml:space="preserve">
<value>Vault Server URL</value>
</data>
</root>

View file

@ -104,6 +104,24 @@ namespace Bit.App.Services
}
}
public string VaultUrl
{
get
{
return _settings.GetValueOrDefault<string>(Constants.VaultUrl);
}
set
{
if(value == null)
{
_settings.Remove(Constants.VaultUrl);
return;
}
_settings.AddOrUpdateValue(Constants.VaultUrl, value);
}
}
public string ApiUrl
{
get