From dead022e83c902239c8c9247b9456a55af2620a3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 16 Apr 2018 20:35:53 -0400 Subject: [PATCH] admin base uri setting, applied to login emails --- src/Admin/Controllers/LoginController.cs | 3 +-- src/Admin/appsettings.Production.json | 2 ++ src/Admin/appsettings.json | 2 ++ src/Api/appsettings.Preview.json | 12 ------------ src/Api/appsettings.Production.json | 2 ++ src/Api/appsettings.Staging.json | 12 ------------ src/Api/appsettings.json | 2 ++ src/Billing/appsettings.Production.json | 2 ++ src/Billing/appsettings.json | 2 ++ src/Core/GlobalSettings.cs | 2 ++ src/Core/Identity/PasswordlessSignInManager.cs | 4 ++-- src/Core/Services/IMailService.cs | 2 +- .../Implementations/BackupMailService.cs | 6 +++--- .../Implementations/MarkdownMailService.cs | 16 +++++++++------- .../Services/Implementations/RazorMailService.cs | 16 +++++++++------- .../NoopImplementations/NoopMailService.cs | 2 +- src/Events/appsettings.Preview.json | 12 ------------ src/Events/appsettings.Production.json | 2 ++ src/Events/appsettings.Staging.json | 12 ------------ src/Events/appsettings.json | 2 ++ src/Identity/appsettings.Preview.json | 12 ------------ src/Identity/appsettings.Production.json | 2 ++ src/Identity/appsettings.Staging.json | 12 ------------ src/Identity/appsettings.json | 2 ++ src/Jobs/appsettings.Preview.json | 12 ------------ src/Jobs/appsettings.Production.json | 2 ++ src/Jobs/appsettings.Staging.json | 12 ------------ src/Jobs/appsettings.json | 2 ++ src/Scim/appsettings.Production.json | 2 ++ src/Scim/appsettings.json | 2 ++ util/Setup/EnvironmentFileBuilder.cs | 3 +++ 31 files changed, 59 insertions(+), 119 deletions(-) delete mode 100644 src/Api/appsettings.Preview.json delete mode 100644 src/Api/appsettings.Staging.json delete mode 100644 src/Events/appsettings.Preview.json delete mode 100644 src/Events/appsettings.Staging.json delete mode 100644 src/Identity/appsettings.Preview.json delete mode 100644 src/Identity/appsettings.Staging.json delete mode 100644 src/Jobs/appsettings.Preview.json delete mode 100644 src/Jobs/appsettings.Staging.json diff --git a/src/Admin/Controllers/LoginController.cs b/src/Admin/Controllers/LoginController.cs index 68f486342..c2bb47ddd 100644 --- a/src/Admin/Controllers/LoginController.cs +++ b/src/Admin/Controllers/LoginController.cs @@ -38,8 +38,7 @@ namespace Bit.Admin.Controllers { if(ModelState.IsValid) { - await _signInManager.PasswordlessSignInAsync(model.Email, - Url.Action("Confirm", "Login", new { returnUrl = model.ReturnUrl }, Request.Scheme)); + await _signInManager.PasswordlessSignInAsync(model.Email, model.ReturnUrl); return RedirectToAction("Index", new { success = "If a valid admin user with this email address exists, " + diff --git a/src/Admin/appsettings.Production.json b/src/Admin/appsettings.Production.json index 6ca845bcd..9501db8ac 100644 --- a/src/Admin/appsettings.Production.json +++ b/src/Admin/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Admin/appsettings.json b/src/Admin/appsettings.json index 10a0a9115..febc7f8bc 100644 --- a/src/Admin/appsettings.json +++ b/src/Admin/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Api/appsettings.Preview.json b/src/Api/appsettings.Preview.json deleted file mode 100644 index 3206644db..000000000 --- a/src/Api/appsettings.Preview.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://preview-vault.bitwarden.com", - "api": "https://preview-api.bitwarden.com", - "identity": "https://preview-identity.bitwarden.com", - "internalIdentity": "https://preview-identity.bitwarden.com", - "internalApi": "https://preview-api.bitwarden.com", - "internalVault": "https://preview-vault.bitwarden.com" - } - } -} diff --git a/src/Api/appsettings.Production.json b/src/Api/appsettings.Production.json index 6ca845bcd..9501db8ac 100644 --- a/src/Api/appsettings.Production.json +++ b/src/Api/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Api/appsettings.Staging.json b/src/Api/appsettings.Staging.json deleted file mode 100644 index b70143c2c..000000000 --- a/src/Api/appsettings.Staging.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://vault.bitwarden.com", - "api": "https://api.bitwarden.com", - "identity": "https://identity.bitwarden.com", - "internalIdentity": "https://identity.bitwarden.com", - "internalApi": "https://api.bitwarden.com", - "internalVault": "https://vault.bitwarden.com" - } - } -} diff --git a/src/Api/appsettings.json b/src/Api/appsettings.json index b74a3306f..22f2d34b9 100644 --- a/src/Api/appsettings.json +++ b/src/Api/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Billing/appsettings.Production.json b/src/Billing/appsettings.Production.json index e0dbff6b0..24da86e99 100644 --- a/src/Billing/appsettings.Production.json +++ b/src/Billing/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com" }, "braintree": { diff --git a/src/Billing/appsettings.json b/src/Billing/appsettings.json index 1b64f9051..abdb1a767 100644 --- a/src/Billing/appsettings.json +++ b/src/Billing/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Core/GlobalSettings.cs b/src/Core/GlobalSettings.cs index 8b27c9c96..3e6844ed4 100644 --- a/src/Core/GlobalSettings.cs +++ b/src/Core/GlobalSettings.cs @@ -34,6 +34,8 @@ namespace Bit.Core public string VaultWithHash => $"{Vault}/#"; public string Api { get; set; } public string Identity { get; set; } + public string Admin { get; set; } + public string InternalAdmin { get; set; } public string InternalIdentity { get; set; } public string InternalApi { get; set; } public string InternalVault { get; set; } diff --git a/src/Core/Identity/PasswordlessSignInManager.cs b/src/Core/Identity/PasswordlessSignInManager.cs index 67957aaf2..c54a3ddf5 100644 --- a/src/Core/Identity/PasswordlessSignInManager.cs +++ b/src/Core/Identity/PasswordlessSignInManager.cs @@ -28,7 +28,7 @@ namespace Bit.Core.Identity _mailService = mailService; } - public async Task PasswordlessSignInAsync(string email, string loginConfirmUrl) + public async Task PasswordlessSignInAsync(string email, string returnUrl) { var user = await UserManager.FindByEmailAsync(email); if(user == null) @@ -38,7 +38,7 @@ namespace Bit.Core.Identity var token = await UserManager.GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, PasswordlessSignInPurpose); - await _mailService.SendPasswordlessSignInAsync(loginConfirmUrl, token, email); + await _mailService.SendPasswordlessSignInAsync(returnUrl, token, email); return SignInResult.Success; } diff --git a/src/Core/Services/IMailService.cs b/src/Core/Services/IMailService.cs index a1925f658..c2086082f 100644 --- a/src/Core/Services/IMailService.cs +++ b/src/Core/Services/IMailService.cs @@ -18,6 +18,6 @@ namespace Bit.Core.Services Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, string token); Task SendOrganizationAcceptedEmailAsync(string organizationName, string userEmail, IEnumerable adminEmails); Task SendOrganizationConfirmedEmailAsync(string organizationName, string email); - Task SendPasswordlessSignInAsync(string baseUrl, string token, string email); + Task SendPasswordlessSignInAsync(string returnUrl, string token, string email); } } diff --git a/src/Core/Services/Implementations/BackupMailService.cs b/src/Core/Services/Implementations/BackupMailService.cs index 08d00bd40..b4359c44a 100644 --- a/src/Core/Services/Implementations/BackupMailService.cs +++ b/src/Core/Services/Implementations/BackupMailService.cs @@ -153,16 +153,16 @@ namespace Bit.Core.Services } } - public async Task SendPasswordlessSignInAsync(string baseUrl, string token, string email) + public async Task SendPasswordlessSignInAsync(string returnUrl, string token, string email) { try { - await _primaryMailService.SendPasswordlessSignInAsync(baseUrl, token, email); + await _primaryMailService.SendPasswordlessSignInAsync(returnUrl, token, email); } catch(Exception e) { LogError(e); - await _backupMailService.SendPasswordlessSignInAsync(baseUrl, token, email); + await _backupMailService.SendPasswordlessSignInAsync(returnUrl, token, email); } } diff --git a/src/Core/Services/Implementations/MarkdownMailService.cs b/src/Core/Services/Implementations/MarkdownMailService.cs index 9aaee2f96..e8db1a7dc 100644 --- a/src/Core/Services/Implementations/MarkdownMailService.cs +++ b/src/Core/Services/Implementations/MarkdownMailService.cs @@ -171,19 +171,21 @@ namespace Bit.Core.Services await _mailDeliveryService.SendEmailAsync(message); } - public async Task SendPasswordlessSignInAsync(string baseUrl, string token, string email) + public async Task SendPasswordlessSignInAsync(string returnUrl, string token, string email) { - var url = CoreHelpers.ExtendQuery(new Uri(baseUrl), new Dictionary - { - ["email"] = email, - ["token"] = token, - }); + var url = CoreHelpers.ExtendQuery(new Uri($"{_globalSettings.BaseServiceUri.Admin}/login/confirm"), + new Dictionary + { + ["returnUrl"] = returnUrl, + ["email"] = email, + ["token"] = token, + }); var model = new Dictionary { ["url"] = url.ToString() }; - var message = await CreateMessageAsync("Continue Logging In", email, "PasswordlessSignIn", model); + var message = await CreateMessageAsync("[Admin] Continue Logging In", email, "PasswordlessSignIn", model); message.MetaData.Add("SendGridBypassListManagement", true); await _mailDeliveryService.SendEmailAsync(message); } diff --git a/src/Core/Services/Implementations/RazorMailService.cs b/src/Core/Services/Implementations/RazorMailService.cs index bd2c2bfbc..2cb198c14 100644 --- a/src/Core/Services/Implementations/RazorMailService.cs +++ b/src/Core/Services/Implementations/RazorMailService.cs @@ -203,15 +203,17 @@ namespace Bit.Core.Services await _mailDeliveryService.SendEmailAsync(message); } - public async Task SendPasswordlessSignInAsync(string baseUrl, string token, string email) + public async Task SendPasswordlessSignInAsync(string returnUrl, string token, string email) { - var message = CreateDefaultMessage("Continue Logging In", email); + var message = CreateDefaultMessage("[Admin] Continue Logging In", email); - var url = CoreHelpers.ExtendQuery(new Uri(baseUrl), new Dictionary - { - ["email"] = email, - ["token"] = token, - }); + var url = CoreHelpers.ExtendQuery(new Uri($"{_globalSettings.BaseServiceUri.Admin}/login/confirm"), + new Dictionary + { + ["returnUrl"] = returnUrl, + ["email"] = email, + ["token"] = token, + }); var model = new PasswordlessSignInModel { Url = url.ToString() diff --git a/src/Core/Services/NoopImplementations/NoopMailService.cs b/src/Core/Services/NoopImplementations/NoopMailService.cs index 871c30f34..eba42fcea 100644 --- a/src/Core/Services/NoopImplementations/NoopMailService.cs +++ b/src/Core/Services/NoopImplementations/NoopMailService.cs @@ -62,7 +62,7 @@ namespace Bit.Core.Services return Task.FromResult(0); } - public Task SendPasswordlessSignInAsync(string baseUrl, string token, string email) + public Task SendPasswordlessSignInAsync(string returnUrl, string token, string email) { return Task.FromResult(0); } diff --git a/src/Events/appsettings.Preview.json b/src/Events/appsettings.Preview.json deleted file mode 100644 index 3206644db..000000000 --- a/src/Events/appsettings.Preview.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://preview-vault.bitwarden.com", - "api": "https://preview-api.bitwarden.com", - "identity": "https://preview-identity.bitwarden.com", - "internalIdentity": "https://preview-identity.bitwarden.com", - "internalApi": "https://preview-api.bitwarden.com", - "internalVault": "https://preview-vault.bitwarden.com" - } - } -} diff --git a/src/Events/appsettings.Production.json b/src/Events/appsettings.Production.json index b70143c2c..8bca868fc 100644 --- a/src/Events/appsettings.Production.json +++ b/src/Events/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Events/appsettings.Staging.json b/src/Events/appsettings.Staging.json deleted file mode 100644 index b70143c2c..000000000 --- a/src/Events/appsettings.Staging.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://vault.bitwarden.com", - "api": "https://api.bitwarden.com", - "identity": "https://identity.bitwarden.com", - "internalIdentity": "https://identity.bitwarden.com", - "internalApi": "https://api.bitwarden.com", - "internalVault": "https://vault.bitwarden.com" - } - } -} diff --git a/src/Events/appsettings.json b/src/Events/appsettings.json index 266ad50c4..50edfba83 100644 --- a/src/Events/appsettings.json +++ b/src/Events/appsettings.json @@ -6,6 +6,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Identity/appsettings.Preview.json b/src/Identity/appsettings.Preview.json deleted file mode 100644 index 3206644db..000000000 --- a/src/Identity/appsettings.Preview.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://preview-vault.bitwarden.com", - "api": "https://preview-api.bitwarden.com", - "identity": "https://preview-identity.bitwarden.com", - "internalIdentity": "https://preview-identity.bitwarden.com", - "internalApi": "https://preview-api.bitwarden.com", - "internalVault": "https://preview-vault.bitwarden.com" - } - } -} diff --git a/src/Identity/appsettings.Production.json b/src/Identity/appsettings.Production.json index 6ca845bcd..9501db8ac 100644 --- a/src/Identity/appsettings.Production.json +++ b/src/Identity/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Identity/appsettings.Staging.json b/src/Identity/appsettings.Staging.json deleted file mode 100644 index b70143c2c..000000000 --- a/src/Identity/appsettings.Staging.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://vault.bitwarden.com", - "api": "https://api.bitwarden.com", - "identity": "https://identity.bitwarden.com", - "internalIdentity": "https://identity.bitwarden.com", - "internalApi": "https://api.bitwarden.com", - "internalVault": "https://vault.bitwarden.com" - } - } -} diff --git a/src/Identity/appsettings.json b/src/Identity/appsettings.json index 330da6e60..1246e35f4 100644 --- a/src/Identity/appsettings.json +++ b/src/Identity/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Jobs/appsettings.Preview.json b/src/Jobs/appsettings.Preview.json deleted file mode 100644 index 3206644db..000000000 --- a/src/Jobs/appsettings.Preview.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://preview-vault.bitwarden.com", - "api": "https://preview-api.bitwarden.com", - "identity": "https://preview-identity.bitwarden.com", - "internalIdentity": "https://preview-identity.bitwarden.com", - "internalApi": "https://preview-api.bitwarden.com", - "internalVault": "https://preview-vault.bitwarden.com" - } - } -} diff --git a/src/Jobs/appsettings.Production.json b/src/Jobs/appsettings.Production.json index 6ca845bcd..9501db8ac 100644 --- a/src/Jobs/appsettings.Production.json +++ b/src/Jobs/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Jobs/appsettings.Staging.json b/src/Jobs/appsettings.Staging.json deleted file mode 100644 index b70143c2c..000000000 --- a/src/Jobs/appsettings.Staging.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globalSettings": { - "baseServiceUri": { - "vault": "https://vault.bitwarden.com", - "api": "https://api.bitwarden.com", - "identity": "https://identity.bitwarden.com", - "internalIdentity": "https://identity.bitwarden.com", - "internalApi": "https://api.bitwarden.com", - "internalVault": "https://vault.bitwarden.com" - } - } -} diff --git a/src/Jobs/appsettings.json b/src/Jobs/appsettings.json index addf0cc9f..1c83856c5 100644 --- a/src/Jobs/appsettings.json +++ b/src/Jobs/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/src/Scim/appsettings.Production.json b/src/Scim/appsettings.Production.json index 6ca845bcd..9501db8ac 100644 --- a/src/Scim/appsettings.Production.json +++ b/src/Scim/appsettings.Production.json @@ -4,6 +4,8 @@ "vault": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", + "admin": "https://admin.bitwarden.com", + "internalAdmin": "https://admin.bitwarden.com", "internalIdentity": "https://identity.bitwarden.com", "internalApi": "https://api.bitwarden.com", "internalVault": "https://vault.bitwarden.com" diff --git a/src/Scim/appsettings.json b/src/Scim/appsettings.json index 1b64f9051..abdb1a767 100644 --- a/src/Scim/appsettings.json +++ b/src/Scim/appsettings.json @@ -8,6 +8,8 @@ "vault": "http://localhost:4001", "api": "http://localhost:4000", "identity": "http://localhost:33656", + "admin": "http://localhost:62911", + "internalAdmin": "http://localhost:62911", "internalIdentity": "http://localhost:33656", "internalApi": "http://localhost:4000", "internalVault": "http://localhost:4001" diff --git a/util/Setup/EnvironmentFileBuilder.cs b/util/Setup/EnvironmentFileBuilder.cs index 7d076504f..1c15c1342 100644 --- a/util/Setup/EnvironmentFileBuilder.cs +++ b/util/Setup/EnvironmentFileBuilder.cs @@ -41,6 +41,7 @@ namespace Bit.Setup ["globalSettings__baseServiceUri__vault"] = Url, ["globalSettings__baseServiceUri__api"] = $"{Url}/api", ["globalSettings__baseServiceUri__identity"] = $"{Url}/identity", + ["globalSettings__baseServiceUri__admin"] = $"{Url}/admin", ["globalSettings__sqlServer__connectionString"] = $"\"{ dbConnectionString }\"", ["globalSettings__identityServer__certificatePassword"] = IdentityCertPassword, ["globalSettings__attachment__baseDirectory"] = $"{OutputDirectory}/core/attachments", @@ -126,6 +127,8 @@ globalSettings__selfHosted=true globalSettings__baseServiceUri__vault=http://localhost globalSettings__baseServiceUri__api=http://localhost/api globalSettings__baseServiceUri__identity=http://localhost/identity +globalSettings__baseServiceUri__admin=http://localhost/admin +globalSettings__baseServiceUri__internalAdmin=http://admin:5000 globalSettings__baseServiceUri__internalIdentity=http://identity:5000 globalSettings__baseServiceUri__internalApi=http://api:5000 globalSettings__baseServiceUri__internalVault=http://web:5000