Browse Source

Added new authentication feature by api key (#3)

authored-by: barhen <barhen@outlook.com>
Reviewed-on: #3
Co-authored-by: Benjamin Arhen <barhen@outlook.com>
Co-committed-by: Benjamin Arhen <barhen@outlook.com>
dev
Benjamin Arhen 1 year ago
parent
commit
126b495aaa
  1. 2
      ServerManager/ServiceRepo/CompanyService.cs
  2. 22
      ServerManager/SyncMethods/CompanySync.cs
  3. 20
      ServerManager/SyncMethods/ProductSync.cs
  4. 20
      ServerManager/SyncMethods/SalesSync.cs
  5. 5
      ServerManager/Worker.cs
  6. 4
      ServerManager/appsettings.json

2
ServerManager/ServiceRepo/CompanyService.cs

@ -74,7 +74,7 @@ namespace ServerManager.ServiceRepo
// Using Dapper to call a stored procedure with parameters
var parameters = new
{
a_tableName = "tblbranch",
a_tableName = "tblbranches",
a_branchId = a_branch,
lastModified = a_dateTime
};

22
ServerManager/SyncMethods/CompanySync.cs

@ -66,7 +66,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblcompanydetails", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -85,7 +85,7 @@ namespace ServerManager.SyncMethods
IEnumerable<TblBranch> modifiedCart = await m_companyService.FetchBranch(date, "BRID0");
SyncTimestamp syncTimestamp = new SyncTimestamp
{
TableName = "tblbranch",
TableName = "tblbranches",
Timestamp = DateTime.Now.AddSeconds(-10),
};
int batchSize = 200;
@ -99,7 +99,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblbranch", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -132,7 +132,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblCustomers", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -161,7 +161,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbldriver", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -190,7 +190,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/SystemRoles", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -219,7 +219,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblTruckAssignment", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -248,7 +248,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbldrivermappings", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -277,7 +277,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbltruckinventory", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -306,7 +306,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbltrucks", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -335,7 +335,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblusers", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}

20
ServerManager/SyncMethods/ProductSync.cs

@ -56,7 +56,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblproducts", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -85,7 +85,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblInventory", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -114,7 +114,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblInventoryentry", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -143,7 +143,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblRestock", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -172,7 +172,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tlpricechanges", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -201,7 +201,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -229,7 +229,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblStock", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -258,7 +258,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblbrands", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -287,7 +287,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblCategories", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -316,7 +316,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblunitofmeasure", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}

20
ServerManager/SyncMethods/SalesSync.cs

@ -61,7 +61,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCart", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -94,7 +94,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblcancelledtransaction", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -127,7 +127,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCreditpurchase", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -156,7 +156,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCustomerAccount", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -185,7 +185,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/CustomerPurchase", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -214,7 +214,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/DiscountLogs", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -243,7 +243,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliverydetails", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -272,7 +272,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliveryhead", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -301,7 +301,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliveryrecipient", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
@ -330,7 +330,7 @@ namespace ServerManager.SyncMethods
var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblinvoice", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}");
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}

5
ServerManager/Worker.cs

@ -24,9 +24,8 @@ namespace ServerManager
string baseurl = m_configuration.GetValue("BaseUrl", "")!;
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(baseurl);
string token = m_configuration.GetValue("Token", "")!;
var authHeader = new AuthenticationHeaderValue("Bearer", token);
httpClient.DefaultRequestHeaders.Authorization = authHeader;
string token = m_configuration.GetValue("APIKEY", "")!;
httpClient.DefaultRequestHeaders.Add("BISK-API-KEY", token);
using var scope = _serviceProvider.CreateScope();
var salesSync = scope.ServiceProvider.GetRequiredService<SalesSync>();

4
ServerManager/appsettings.json

@ -8,8 +8,8 @@
"ConnectionStrings": {
"Connection": "Server=BarhenVM\\SqlExpress;Database=BISK_POS;Integrated Security=True;TrustServerCertificate=true"
},
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMWM3MWE0Ni0xZmY2LTRkMGMtYmYzMS1iMTExMzJlMGM5ODQiLCJpYXQiOiIxNC8wOC8yMDIzIDY6MjI6MzIgcG0iLCJDb250cmFjdFN0YXJ0IjoiMTgvMDUvMjAyMyA4OjQ3OjI3IHBtIiwiQ29udHJhY3RFbmQiOiIxOC8wNS8yMDI0IDg6NDc6MjkgcG0iLCJVc2VySWQiOiIxIiwiVXNlcm5hbWUiOiJ0ZXN0IiwiRGJJZCI6IjEiLCJDb21wYXJpc29uTW9kZSI6IkZhbHNlIiwiQnJhbmNoSWQiOiJCUklEMCIsIkJyYW5jaEFjY2VzcyI6IkJSSUQwIiwiQ2xpZW50SWQiOiIxIiwiZXhwIjoxNjkzMjQ2OTUyLCJpc3MiOiJBVVRIIFNFUlZFUiIsImF1ZCI6IkJJU0tJTE9HIn0.W3kxw5kEj13TDSs96doR20IW96k3aO8uR5SKGiSaSX4",
"BaseUrl": "https://localhost:7247/",
"APIKEY": "AI1@h1BBmaU4d9LqU4W6UKGh7kWFNB9V",
"BaseUrl": "https://localhost:7122/",
"AllowedHosts": "*",
"JWT": {
"Key": "@@BISKILOGACCOUNTING2023DEV??//##$",

Loading…
Cancel
Save