This commit is contained in:
Frede Hundewadt 2023-09-11 12:56:55 +02:00
parent ba63e61a4e
commit f0f13754fb
10 changed files with 78 additions and 205 deletions

View file

@ -6,7 +6,7 @@
// Last Modified By : FH
// Last Modified On : 05-10-2022
// ***********************************************************************
// <copyright file="AzureAuthStore.cs" company="FCS-TECH">
// <copyright file="RpcAzureAuthStore.cs" company="FCS">
// 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; }

37
AzureConfigStore.cs Normal file
View file

@ -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}')";
}
}

View file

@ -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 file="AzureToken.cs" company="FCS-TECH">
// 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]
// </copyright>
// <summary></summary>
// ***********************************************************************
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;
}
}
}

View file

@ -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 file="AzureTokenDto.cs" company="FCS-TECH">
// 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]
// </copyright>
// <summary></summary>
// ***********************************************************************
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; }
}
}

View file

@ -25,6 +25,9 @@
// ***********************************************************************
using System.Threading.Tasks;
using FCS.Contracts;
using FCS.Lib.Common;
namespace FCS.Lib.Azure
{

View file

@ -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 file="AzureTokenHttpRequest.cs" company="FCS-TECH">
// 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]
// </copyright>
// <summary></summary>
// ***********************************************************************
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<ResponseView> RequestTokenAsync(AzureAuthStore azureAuth)
public static async Task<ResponseView> RequestTokenAsync(AzureAuthStore auth)
{
var credentials = new Dictionary<string, string>
{
{ "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
};
}
}
}
}

View file

@ -27,6 +27,7 @@
using System;
using System.Text.Json;
using FCS.Lib.Common;
using FCS.Lib.Utility;
namespace FCS.Lib.Azure

View file

@ -7,7 +7,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{63F067FE-925B-4076-86F5-F630F3E5A75B}</ProjectGuid>
<ProjectGuid>{3B0298CC-0ECE-4703-96E2-E12F7BFFAEE0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FCS.Lib.Azure</RootNamespace>
@ -36,26 +36,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="ResponseView.cs" />
<Compile Include="AzureToken.cs" />
<Compile Include="AzureTokenDto.cs" />
<Compile Include="AzureAuthStore.cs" />
<Compile Include="AzureConfigStore.cs" />
<Compile Include="AzureTokenFetcher.cs" />
<Compile Include="AzureTokenHttpRequest.cs" />
<Compile Include="AzureTokenMapper.cs" />
<Compile Include="IAzureTokenFetcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AzureAuthStore.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\fcs-utils\FCS.Lib.Utility.csproj">
<Project>{1F1FECFD-E07E-4B5C-A7F9-67FB89EE94A3}</Project>
<Name>FCS.Lib.Utility</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" />
@ -66,6 +57,20 @@
<HintPath>..\..\inno\inno.api.v2\packages\System.Text.Json.6.0.4\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\fcs-common\FCS.Lib.Common.csproj">
<Project>{3e5fa1ab-44d2-4cbc-b6d7-80b74ca9b265}</Project>
<Name>FCS.Lib.Common</Name>
</ProjectReference>
<ProjectReference Include="..\fcs-contracts\FCS.Contracts.csproj">
<Project>{8ccdfbd9-80ca-4ddf-9031-3d5d3fb972c2}</Project>
<Name>FCS.Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\fcs-utils\FCS.Lib.Utility.csproj">
<Project>{1f1fecfd-e07e-4b5c-a7f9-67fb89ee94a3}</Project>
<Name>FCS.Lib.Utility</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets" Condition="Exists('..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View file

@ -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 file="IAzureTokenFetcher.cs" company="FCS-TECH">
// 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]
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Threading.Tasks;
namespace FCS.Lib.Azure
{
public interface IAzureTokenFetcher
{
Task<AzureToken> FetchAzureToken();
}
}

View file

@ -1,37 +0,0 @@
// ***********************************************************************
// Assembly : Inno.Views
// Author : FH
// Created : 01-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-18-2022
// ***********************************************************************
// <copyright file="ResponseView.cs" company="FCS-TECH">
// 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]
// </copyright>
// <summary></summary>
// ***********************************************************************
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; } = "";
}
}