mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-10 05:13:17 +00:00
settings fixes
This commit is contained in:
@@ -21,9 +21,6 @@ namespace Bit.Console
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
|
||||
//SetDebugDirectory();
|
||||
|
||||
MainAsync(args).Wait();
|
||||
}
|
||||
|
||||
@@ -184,6 +181,8 @@ namespace Bit.Console
|
||||
return;
|
||||
}
|
||||
|
||||
Con.WriteLine();
|
||||
Con.WriteLine("Logging in...");
|
||||
LoginResult result = null;
|
||||
if(string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
@@ -895,13 +894,5 @@ namespace Bit.Console
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private static void SetDebugDirectory()
|
||||
{
|
||||
Directory.SetCurrentDirectory(string.Concat(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"\\bitwarden\\DirectoryConnector"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,21 +16,7 @@ namespace Bit.Core.Services
|
||||
|
||||
private ApiService()
|
||||
{
|
||||
ApiClient = new HttpClient();
|
||||
var apiUrl = "https://api.bitwarden.com";
|
||||
if(!string.IsNullOrWhiteSpace(SettingsService.Instance.ApiBaseUrl))
|
||||
{
|
||||
apiUrl = SettingsService.Instance.ApiBaseUrl;
|
||||
}
|
||||
ApiClient.BaseAddress = new Uri(apiUrl);
|
||||
|
||||
IdentityClient = new HttpClient();
|
||||
var identityUrl = "https://identity.bitwarden.com";
|
||||
if(!string.IsNullOrWhiteSpace(SettingsService.Instance.IdentityBaseUrl))
|
||||
{
|
||||
identityUrl = SettingsService.Instance.IdentityBaseUrl;
|
||||
}
|
||||
IdentityClient.BaseAddress = new Uri(identityUrl);
|
||||
Client = new HttpClient();
|
||||
}
|
||||
|
||||
public static ApiService Instance
|
||||
@@ -46,21 +32,20 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
protected HttpClient ApiClient { get; private set; }
|
||||
protected HttpClient IdentityClient { get; private set; }
|
||||
protected HttpClient Client { get; private set; }
|
||||
|
||||
public virtual async Task<ApiResult<TokenResponse>> PostTokenAsync(TokenRequest requestObj)
|
||||
{
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(IdentityClient.BaseAddress, "connect/token"),
|
||||
RequestUri = new Uri(string.Concat(SettingsService.Instance.IdentityBaseUrl, "/connect/token")),
|
||||
Content = new FormUrlEncodedContent(requestObj.ToIdentityTokenRequest())
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = await IdentityClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
var response = await Client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
if(!response.IsSuccessStatusCode)
|
||||
@@ -98,7 +83,8 @@ namespace Bit.Core.Services
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(ApiClient.BaseAddress, $"organizations/{SettingsService.Instance.Organization.Id}/import"),
|
||||
RequestUri = new Uri(string.Concat(SettingsService.Instance.ApiBaseUrl, "/organizations/",
|
||||
SettingsService.Instance.Organization.Id, "/import")),
|
||||
Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
|
||||
};
|
||||
|
||||
@@ -106,7 +92,7 @@ namespace Bit.Core.Services
|
||||
|
||||
try
|
||||
{
|
||||
var response = await ApiClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
var response = await Client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync(response).ConfigureAwait(false);
|
||||
@@ -131,14 +117,14 @@ namespace Bit.Core.Services
|
||||
var requestMessage = new HttpRequestMessage()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(ApiClient.BaseAddress, "accounts/profile"),
|
||||
RequestUri = new Uri(string.Concat(SettingsService.Instance.ApiBaseUrl, "/accounts/profile")),
|
||||
};
|
||||
|
||||
requestMessage.Headers.Add("Authorization", $"Bearer3 {TokenService.Instance.AccessToken}");
|
||||
|
||||
try
|
||||
{
|
||||
var response = await ApiClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
var response = await Client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<ProfileResponse>(response).ConfigureAwait(false);
|
||||
@@ -190,8 +176,9 @@ namespace Bit.Core.Services
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(IdentityClient.BaseAddress, "connect/token"),
|
||||
Content = new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
RequestUri = new Uri(string.Concat(SettingsService.Instance.IdentityBaseUrl, "/connect/token")),
|
||||
Content = new FormUrlEncodedContent(
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "grant_type", "refresh_token" },
|
||||
{ "client_id", "mobile" },
|
||||
@@ -201,7 +188,7 @@ namespace Bit.Core.Services
|
||||
|
||||
try
|
||||
{
|
||||
var response = await IdentityClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
var response = await Client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
if(response.StatusCode == HttpStatusCode.BadRequest)
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace Bit.Core.Services
|
||||
{
|
||||
private static SettingsService _instance;
|
||||
private static object _locker = new object();
|
||||
private static string _baseStoragePath = Directory.GetCurrentDirectory();
|
||||
private static string _baseStoragePath = string.Concat(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
|
||||
"\\bitwarden\\Directory Connector");
|
||||
|
||||
private SettingsModel _settings;
|
||||
|
||||
@@ -222,9 +224,9 @@ namespace Bit.Core.Services
|
||||
public string IdentityBaseUrl { get; set; } = "https://identity.bitwarden.com";
|
||||
public EncryptedData AccessToken { get; set; }
|
||||
public EncryptedData RefreshToken { get; set; }
|
||||
public ServerConfiguration Server { get; set; }
|
||||
public SyncConfiguration Sync { get; set; }
|
||||
public Organization Organization { get; set; }
|
||||
public ServerConfiguration Server { get; set; } = new ServerConfiguration();
|
||||
public SyncConfiguration Sync { get; set; } = new SyncConfiguration(Enums.DirectoryType.ActiveDirectory);
|
||||
public Organization Organization { get; set; } = new Organization();
|
||||
public DateTime? LastGroupSyncDate { get; set; }
|
||||
public DateTime? LastUserSyncDate { get; set; }
|
||||
public string GroupDeltaToken { get; set; }
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Service
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
DebugMode();
|
||||
//DebugMode();
|
||||
|
||||
ServiceBase.Run(new ServiceBase[]
|
||||
{
|
||||
@@ -23,7 +23,7 @@ namespace Service
|
||||
[Conditional("DEBUG")]
|
||||
private static void DebugMode()
|
||||
{
|
||||
//Debugger.Launch();
|
||||
Debugger.Launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ namespace Service
|
||||
|
||||
public Service()
|
||||
{
|
||||
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
|
||||
|
||||
ServiceName = "bitwarden Directory Connector";
|
||||
|
||||
_components = new Container();
|
||||
|
||||
Reference in New Issue
Block a user