From f0f13754fbecc590078d76a4277e072c3466f2ae Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Mon, 11 Sep 2023 12:56:55 +0200 Subject: [PATCH] update --- AzureAuthStore.cs | 13 ++++++----- AzureConfigStore.cs | 37 ++++++++++++++++++++++++++++++ AzureToken.cs | 39 -------------------------------- AzureTokenDto.cs | 40 -------------------------------- AzureTokenFetcher.cs | 3 +++ AzureTokenHttpRequest.cs | 49 +++++++++++----------------------------- AzureTokenMapper.cs | 1 + FCS.Lib.Azure.csproj | 29 ++++++++++++++---------- IAzureTokenFetcher.cs | 35 ---------------------------- ResponseView.cs | 37 ------------------------------ 10 files changed, 78 insertions(+), 205 deletions(-) create mode 100644 AzureConfigStore.cs delete mode 100644 AzureToken.cs delete mode 100644 AzureTokenDto.cs delete mode 100644 IAzureTokenFetcher.cs delete mode 100644 ResponseView.cs diff --git a/AzureAuthStore.cs b/AzureAuthStore.cs index 2e1c4bc..81edde3 100644 --- a/AzureAuthStore.cs +++ b/AzureAuthStore.cs @@ -6,7 +6,7 @@ // Last Modified By : FH // Last Modified On : 05-10-2022 // *********************************************************************** -// +// // Copyright (C) 2022 FCS Frede's Computer Services. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -29,8 +29,9 @@ namespace FCS.Lib.Azure public class AzureAuthStore { public AzureAuthStore( - string azureLoginUrl, string azureOAuthEndpoint, string azureLoginScope, string azureGrantType, - string azureTenantId, string azureClientId, string azureSecret) + string azureLoginUrl, string azureOAuthEndpoint, string azureTenantId, + string azureClientId, string azureGrantType, string azureSecret, + string azureLoginScope) { AzureLoginUrl = azureLoginUrl; AzureOAuthEndpoint = azureOAuthEndpoint; @@ -43,9 +44,9 @@ namespace FCS.Lib.Azure protected string AzureLoginUrl { get; set; } protected string AzureOAuthEndpoint { get; set; } - protected string AzureTenantId { get;} - public string AzureClientId { get;} - public string AzureGrantType { get;} + protected string AzureTenantId { get; } + public string AzureClientId { get; } + public string AzureGrantType { get; } public string AzureSecret { get; } public string AzureLoginScope { get; } diff --git a/AzureConfigStore.cs b/AzureConfigStore.cs new file mode 100644 index 0000000..1d49b39 --- /dev/null +++ b/AzureConfigStore.cs @@ -0,0 +1,37 @@ +namespace FCS.Lib.Azure; + +public class AzureConfigStore +{ + public AzureConfigStore(string baseUrl, string tenantId, string environment, + string api, string apiGroup, string apiVersion, + string ledgerId, string oDataVersion) + { + BaseUrl = baseUrl; + TenantId = tenantId; + Environment = environment; + Api = api; + ApiGroup = apiGroup; + ApiVersion = apiVersion; + LedgerId = ledgerId; + ODataVersion = oDataVersion; + } + + protected string BaseUrl { get; set; } + protected string TenantId { get; } + protected string Environment { get; set; } + protected string Api { get; set; } + protected string ApiGroup { get; set; } + protected string ApiVersion { get; set; } + protected string LedgerId { get; set; } + protected string ODataVersion { get; set; } + + public string InnoClientApiEndpoint() + { + return $"{BaseUrl}/{TenantId}/{Environment}/api/{Api}/{ApiGroup}/{ApiVersion}/companies({LedgerId})"; + } + + public string InnoClientOAuthEndpoint() + { + return $"{BaseUrl}/{TenantId}/{Environment}/{ODataVersion}/Company('{LedgerId}')"; + } +} \ No newline at end of file diff --git a/AzureToken.cs b/AzureToken.cs deleted file mode 100644 index 53ea0a6..0000000 --- a/AzureToken.cs +++ /dev/null @@ -1,39 +0,0 @@ -// *********************************************************************** -// Assembly : FCS.Lib.Azure -// Author : FH -// Created : 05-10-2022 -// -// Last Modified By : FH -// Last Modified On : 05-10-2022 -// *********************************************************************** -// -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses] -// -// -// *********************************************************************** - -namespace FCS.Lib.Azure -{ - public class AzureToken - { - public string TokenType { get; set; } = ""; - public string AccessToken { get; set; } = ""; - public long Expires { get; set; } - public bool HasExpired(long timestamp) - { - return timestamp > Expires; - } - } -} \ No newline at end of file diff --git a/AzureTokenDto.cs b/AzureTokenDto.cs deleted file mode 100644 index 2a87fc0..0000000 --- a/AzureTokenDto.cs +++ /dev/null @@ -1,40 +0,0 @@ -// *********************************************************************** -// Assembly : FCS.Lib.Azure -// Author : FH -// Created : 05-08-2022 -// -// Last Modified By : FH -// Last Modified On : 05-08-2022 -// *********************************************************************** -// -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses] -// -// -// *********************************************************************** - - -using System.Text.Json.Serialization; - -namespace FCS.Lib.Azure -{ - public class AzureTokenDto - { - [JsonPropertyName("token_type")] public string TokenType { get; set; } - [JsonPropertyName("expires_in")] public long ExpiresIn { get; set; } - [JsonPropertyName("ext_expires_in")] public long ExtExpiresIn { get; set; } - [JsonPropertyName("access_token")] public string AccessToken { get; set; } - - } -} \ No newline at end of file diff --git a/AzureTokenFetcher.cs b/AzureTokenFetcher.cs index 5b7c6f2..8cc10b3 100644 --- a/AzureTokenFetcher.cs +++ b/AzureTokenFetcher.cs @@ -25,6 +25,9 @@ // *********************************************************************** using System.Threading.Tasks; +using FCS.Contracts; +using FCS.Lib.Common; + namespace FCS.Lib.Azure { diff --git a/AzureTokenHttpRequest.cs b/AzureTokenHttpRequest.cs index bbe5088..de8644c 100644 --- a/AzureTokenHttpRequest.cs +++ b/AzureTokenHttpRequest.cs @@ -1,52 +1,29 @@ -// *********************************************************************** -// Assembly : FCS.Lib.Azure -// Author : FH -// Created : 05-10-2022 -// -// Last Modified By : FH -// Last Modified On : 05-10-2022 -// *********************************************************************** -// -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses] -// -// -// *********************************************************************** - -using System.Collections.Generic; +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using Inno.Business.Models.Common; -namespace FCS.Lib.Azure +namespace Inno.Azure { public class AzureTokenHttpRequest { - public static async Task RequestTokenAsync(AzureAuthStore azureAuth) + public static async Task RequestTokenAsync(AzureAuthStore auth) { var credentials = new Dictionary { - { "grant_type", azureAuth.AzureGrantType }, - { "client_id", azureAuth.AzureClientId }, - { "client_secret", azureAuth.AzureSecret }, - { "scope", azureAuth.AzureLoginScope} + { "grant_type", auth.AzureGrantType }, + { "client_id", auth.AzureClientId }, + { "client_secret", auth.AzureSecret }, + { "scope", auth.AzureLoginScope } }; using var client = new HttpClient(); - + //using var azureRequest = new HttpRequestMessage(HttpMethod.Post, auth.AzureTokenEndpoint()); + //azureRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new FormUrlEncodedContent(credentials); - var responseMessage = await client.PostAsync(azureAuth.AzureTokenEndpoint(), content).ConfigureAwait(true); + // todo - check for network connection - mitigate server fail + var responseMessage = await client.PostAsync(auth.AzureTokenEndpoint(), content).ConfigureAwait(true); var azureResponse = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(true); @@ -58,4 +35,4 @@ namespace FCS.Lib.Azure }; } } -} +} \ No newline at end of file diff --git a/AzureTokenMapper.cs b/AzureTokenMapper.cs index 904f200..034417d 100644 --- a/AzureTokenMapper.cs +++ b/AzureTokenMapper.cs @@ -27,6 +27,7 @@ using System; using System.Text.Json; +using FCS.Lib.Common; using FCS.Lib.Utility; namespace FCS.Lib.Azure diff --git a/FCS.Lib.Azure.csproj b/FCS.Lib.Azure.csproj index 6c2eeec..920abb6 100644 --- a/FCS.Lib.Azure.csproj +++ b/FCS.Lib.Azure.csproj @@ -7,7 +7,7 @@ Debug AnyCPU - {63F067FE-925B-4076-86F5-F630F3E5A75B} + {3B0298CC-0ECE-4703-96E2-E12F7BFFAEE0} Library Properties FCS.Lib.Azure @@ -36,26 +36,17 @@ 4 - - - + + - - - - - {1F1FECFD-E07E-4B5C-A7F9-67FB89EE94A3} - FCS.Lib.Utility - - @@ -66,6 +57,20 @@ ..\..\inno\inno.api.v2\packages\System.Text.Json.6.0.4\lib\net461\System.Text.Json.dll + + + {3e5fa1ab-44d2-4cbc-b6d7-80b74ca9b265} + FCS.Lib.Common + + + {8ccdfbd9-80ca-4ddf-9031-3d5d3fb972c2} + FCS.Contracts + + + {1f1fecfd-e07e-4b5c-a7f9-67fb89ee94a3} + FCS.Lib.Utility + + diff --git a/IAzureTokenFetcher.cs b/IAzureTokenFetcher.cs deleted file mode 100644 index f50cc3f..0000000 --- a/IAzureTokenFetcher.cs +++ /dev/null @@ -1,35 +0,0 @@ -// *********************************************************************** -// Assembly : FCS.Lib.Azure -// Author : FH -// Created : 05-10-2022 -// -// Last Modified By : FH -// Last Modified On : 05-10-2022 -// *********************************************************************** -// -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses] -// -// -// *********************************************************************** - -using System.Threading.Tasks; - -namespace FCS.Lib.Azure -{ - public interface IAzureTokenFetcher - { - Task FetchAzureToken(); - } -} \ No newline at end of file diff --git a/ResponseView.cs b/ResponseView.cs deleted file mode 100644 index a558076..0000000 --- a/ResponseView.cs +++ /dev/null @@ -1,37 +0,0 @@ -// *********************************************************************** -// Assembly : Inno.Views -// Author : FH -// Created : 01-01-2022 -// -// Last Modified By : FH -// Last Modified On : 04-18-2022 -// *********************************************************************** -// -// Copyright (C) 2022 FCS Frede's Computer Services. -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see [https://www.gnu.org/licenses] -// -// -// *********************************************************************** - -using System.Net; - -namespace FCS.Lib.Azure -{ - public class ResponseView - { - public HttpStatusCode Code { get; set; } - public bool IsSuccessStatusCode { get; set; } - public string Message { get; set; } = ""; - } -} \ No newline at end of file