mirror of
https://github.com/FCS-TECH/fcs-azure
synced 2024-09-16 18:10:38 +02:00
refactor for other project
This commit is contained in:
parent
fdbf97b4d1
commit
d0f097c35d
13 changed files with 566 additions and 163 deletions
|
@ -1,58 +1,94 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author : FH
|
||||
// Created : 05-10-2022
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : FH
|
||||
// Last Modified On : 05-10-2022
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <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
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
// <copyright file="AzureAuthStore.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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.
|
||||
// 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]
|
||||
// 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
|
||||
namespace FCS.Lib.Azure;
|
||||
|
||||
public class AzureAuthStore
|
||||
{
|
||||
public class AzureAuthStore
|
||||
/// <summary>
|
||||
/// Azure Auth Store Constructor
|
||||
/// </summary>
|
||||
/// <param name="azureLoginUrl"></param>
|
||||
/// <param name="azureOAuthEndpoint"></param>
|
||||
/// <param name="azureTenantId"></param>
|
||||
/// <param name="azureClientId"></param>
|
||||
/// <param name="azureGrantType"></param>
|
||||
/// <param name="azureClientSecret"></param>
|
||||
/// <param name="azureLoginScope"></param>
|
||||
public AzureAuthStore(
|
||||
string azureLoginUrl, string azureOAuthEndpoint, string azureTenantId,
|
||||
string azureClientId, string azureGrantType, string azureClientSecret,
|
||||
string azureLoginScope)
|
||||
{
|
||||
public AzureAuthStore(
|
||||
string azureLoginUrl, string azureOAuthEndpoint, string azureTenantId,
|
||||
string azureClientId, string azureGrantType, string azureSecret,
|
||||
string azureLoginScope)
|
||||
{
|
||||
AzureLoginUrl = azureLoginUrl;
|
||||
AzureOAuthEndpoint = azureOAuthEndpoint;
|
||||
AzureTenantId = azureTenantId;
|
||||
AzureClientId = azureClientId;
|
||||
AzureGrantType = azureGrantType;
|
||||
AzureSecret = azureSecret;
|
||||
AzureLoginScope = azureLoginScope;
|
||||
}
|
||||
AzureLoginUrl = azureLoginUrl;
|
||||
AzureOAuthEndpoint = azureOAuthEndpoint;
|
||||
AzureTenantId = azureTenantId;
|
||||
AzureClientId = azureClientId;
|
||||
AzureGrantType = azureGrantType;
|
||||
AzureClientSecret = azureClientSecret;
|
||||
AzureLoginScope = azureLoginScope;
|
||||
}
|
||||
|
||||
protected string AzureLoginUrl { get; set; }
|
||||
protected string AzureOAuthEndpoint { get; set; }
|
||||
protected string AzureTenantId { get; }
|
||||
public string AzureClientId { get; }
|
||||
public string AzureGrantType { get; }
|
||||
public string AzureSecret { get; }
|
||||
public string AzureLoginScope { get; }
|
||||
/// <summary>
|
||||
/// Azure Client Id
|
||||
/// </summary>
|
||||
public string AzureClientId { get; }
|
||||
|
||||
public string AzureTokenEndpoint()
|
||||
{
|
||||
return $"{AzureLoginUrl}/{AzureTenantId}/{AzureOAuthEndpoint}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Azure Client Secret
|
||||
/// </summary>
|
||||
public string AzureClientSecret { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Grant Type
|
||||
/// </summary>
|
||||
public string AzureGrantType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Login Scope
|
||||
/// </summary>
|
||||
public string AzureLoginScope { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Login Url
|
||||
/// </summary>
|
||||
protected string AzureLoginUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure OAuth Endpoint
|
||||
/// </summary>
|
||||
protected string AzureOAuthEndpoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Tenant Id
|
||||
/// </summary>
|
||||
protected string AzureTenantId { get; }
|
||||
|
||||
public string AzureTokenEndpoint()
|
||||
{
|
||||
return $"{AzureLoginUrl}/{AzureTenantId}/{AzureOAuthEndpoint}";
|
||||
}
|
||||
}
|
|
@ -1,36 +1,114 @@
|
|||
namespace FCS.Lib.Azure;
|
||||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureConfigStore.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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 AzureConfigStore
|
||||
{
|
||||
public AzureConfigStore(string baseUrl, string tenantId, string environment,
|
||||
string api, string apiGroup, string apiVersion,
|
||||
/// <summary>
|
||||
/// Azure Config Store Constructor
|
||||
/// </summary>
|
||||
/// <param name="baseUrl"></param>
|
||||
/// <param name="tenantId"></param>
|
||||
/// <param name="environment"></param>
|
||||
/// <param name="apiPublisher"></param>
|
||||
/// <param name="apiGroup"></param>
|
||||
/// <param name="apiVersion"></param>
|
||||
/// <param name="ledgerId"></param>
|
||||
/// <param name="oDataVersion"></param>
|
||||
public AzureConfigStore(
|
||||
string baseUrl, string tenantId, string environment,
|
||||
string apiPublisher, string apiGroup, string apiVersion,
|
||||
string ledgerId, string oDataVersion)
|
||||
{
|
||||
BaseUrl = baseUrl;
|
||||
TenantId = tenantId;
|
||||
Environment = environment;
|
||||
Api = api;
|
||||
ApiPublisher = apiPublisher;
|
||||
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; }
|
||||
/// <summary>
|
||||
/// Azure Api Group
|
||||
/// </summary>
|
||||
protected string ApiGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Api
|
||||
/// </summary>
|
||||
protected string ApiPublisher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Api Group
|
||||
/// </summary>
|
||||
protected string ApiVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Base Url
|
||||
/// </summary>
|
||||
protected string BaseUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Ledger Id
|
||||
/// </summary>
|
||||
protected string LedgerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure ODate Version
|
||||
/// </summary>
|
||||
protected string ODataVersion { get; set; }
|
||||
|
||||
public string InnoClientApiEndpoint()
|
||||
/// <summary>
|
||||
/// Azure Environment
|
||||
/// </summary>
|
||||
protected string Environment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Tenant Id
|
||||
/// </summary>
|
||||
protected string TenantId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Azure Client Api Endpoint
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string AzureClientApiEndpoint()
|
||||
{
|
||||
return $"{BaseUrl}/{TenantId}/{Environment}/api/{Api}/{ApiGroup}/{ApiVersion}/companies({LedgerId})";
|
||||
return
|
||||
$"{BaseUrl}/{TenantId}/{Environment}/api/{ApiPublisher}/{ApiGroup}/{ApiVersion}/companies({LedgerId})";
|
||||
}
|
||||
|
||||
public string InnoClientOAuthEndpoint()
|
||||
/// <summary>
|
||||
/// Azure OAuth Endpoint
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string AzureClientOAuthEndpoint()
|
||||
{
|
||||
return $"{BaseUrl}/{TenantId}/{Environment}/{ODataVersion}/Company('{LedgerId}')";
|
||||
}
|
||||
|
|
55
AzureToken.cs
Normal file
55
AzureToken.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureToken.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Token Type
|
||||
/// </summary>
|
||||
public string TokenType { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Access Token
|
||||
/// </summary>
|
||||
public string AccessToken { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Expires
|
||||
/// </summary>
|
||||
public long Expires { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token Has Expired
|
||||
/// </summary>
|
||||
/// <param name="timestamp"></param>
|
||||
/// <returns></returns>
|
||||
public bool HasExpired(long timestamp)
|
||||
{
|
||||
return timestamp > Expires;
|
||||
}
|
||||
}
|
56
AzureTokenDto.cs
Normal file
56
AzureTokenDto.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureTokenDto.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Token Type
|
||||
/// </summary>
|
||||
[JsonPropertyName("token_type")]
|
||||
public string TokenType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Expires In
|
||||
/// </summary>
|
||||
[JsonPropertyName("expires_in")]
|
||||
public long ExpiresIn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ext Expires In
|
||||
/// </summary>
|
||||
[JsonPropertyName("ext_expires_in")]
|
||||
public long ExtExpiresIn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Access Token
|
||||
/// </summary>
|
||||
[JsonPropertyName("access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
}
|
|
@ -1,48 +1,59 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author : FH
|
||||
// Created : 05-10-2022
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:25
|
||||
//
|
||||
// Last Modified By : FH
|
||||
// Last Modified On : 05-10-2022
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureTokenFetcher.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.
|
||||
// <copyright file="AzureTokenFetcher.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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.
|
||||
// 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]
|
||||
// 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;
|
||||
using FCS.Contracts;
|
||||
using FCS.Lib.Common;
|
||||
using FCS.Lib.Azure;
|
||||
|
||||
namespace Inno.Azure;
|
||||
|
||||
namespace FCS.Lib.Azure
|
||||
/// <summary>
|
||||
/// Implements IAzureTokenFetcher
|
||||
/// </summary>
|
||||
public class AzureTokenFetcher : IAzureTokenFetcher
|
||||
{
|
||||
public class AzureTokenFetcher : IAzureTokenFetcher
|
||||
{
|
||||
private readonly AzureAuthStore _config;
|
||||
public AzureTokenFetcher(AzureAuthStore config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
private readonly AzureAuthStore _config;
|
||||
|
||||
public async Task<AzureToken> FetchAzureToken()
|
||||
{
|
||||
var result = await AzureTokenHttpRequest.RequestTokenAsync(_config).ConfigureAwait(true);
|
||||
return !result.IsSuccessStatusCode ? new AzureToken{Expires = -1} : new AzureTokenMapper().MapAzureToken(result.Message);
|
||||
}
|
||||
/// <summary>
|
||||
/// Construct a new Azure Token Fetcher from configuration
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public AzureTokenFetcher(AzureAuthStore config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetch Azure Token
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<AzureToken> FetchAzureToken()
|
||||
{
|
||||
var result = await AzureTokenHttpRequest.RequestTokenAsync(_config).ConfigureAwait(true);
|
||||
return !result.IsSuccessStatusCode
|
||||
? new AzureToken { Expires = -1 }
|
||||
: new AzureTokenMapper().MapAzureToken(result.Message);
|
||||
}
|
||||
}
|
|
@ -1,38 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:19
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureTokenHttpRequest.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Inno.Business.Models.Common;
|
||||
using FCS.Lib.Common;
|
||||
|
||||
namespace Inno.Azure
|
||||
namespace FCS.Lib.Azure;
|
||||
|
||||
public class AzureTokenHttpRequest
|
||||
{
|
||||
public class AzureTokenHttpRequest
|
||||
public static async Task<HttpResponseView> RequestTokenAsync(AzureAuthStore auth)
|
||||
{
|
||||
public static async Task<ResponseView> RequestTokenAsync(AzureAuthStore auth)
|
||||
var credentials = new Dictionary<string, string>
|
||||
{
|
||||
var credentials = new Dictionary<string, string>
|
||||
{
|
||||
{ "grant_type", auth.AzureGrantType },
|
||||
{ "client_id", auth.AzureClientId },
|
||||
{ "client_secret", auth.AzureSecret },
|
||||
{ "scope", auth.AzureLoginScope }
|
||||
};
|
||||
{ "grant_type", auth.AzureGrantType },
|
||||
{ "client_id", auth.AzureClientId },
|
||||
{ "client_secret", auth.AzureClientSecret },
|
||||
{ "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);
|
||||
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);
|
||||
|
||||
// todo - check for network connection - mitigate server fail
|
||||
var responseMessage = await client.PostAsync(auth.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);
|
||||
var azureResponse = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(true);
|
||||
|
||||
return new ResponseView
|
||||
{
|
||||
Code = responseMessage.StatusCode,
|
||||
IsSuccessStatusCode = responseMessage.IsSuccessStatusCode,
|
||||
Message = azureResponse
|
||||
};
|
||||
}
|
||||
return new HttpResponseView
|
||||
{
|
||||
Code = responseMessage.StatusCode,
|
||||
IsSuccessStatusCode = responseMessage.IsSuccessStatusCode,
|
||||
Message = azureResponse
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,51 +1,50 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author : FH
|
||||
// Created : 05-08-2022
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : FH
|
||||
// Last Modified On : 05-10-2022
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AzureTokenMapper.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.
|
||||
// <copyright file="AzureTokenMapper.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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.
|
||||
// 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]
|
||||
// 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;
|
||||
using System.Text.Json;
|
||||
using FCS.Lib.Common;
|
||||
using FCS.Lib.Utility;
|
||||
|
||||
namespace FCS.Lib.Azure
|
||||
{
|
||||
public class AzureTokenMapper
|
||||
{
|
||||
public AzureToken MapAzureToken(string json)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(json))
|
||||
throw new ArgumentNullException(nameof(json));
|
||||
namespace FCS.Lib.Azure;
|
||||
|
||||
var token = JsonSerializer.Deserialize<AzureTokenDto>(json);
|
||||
return token == null ? null : new AzureToken
|
||||
public class AzureTokenMapper
|
||||
{
|
||||
public AzureToken MapAzureToken(string json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
throw new ArgumentNullException(nameof(json));
|
||||
|
||||
var token = JsonSerializer.Deserialize<AzureTokenDto>(json);
|
||||
return token == null
|
||||
? null
|
||||
: new AzureToken
|
||||
{
|
||||
AccessToken = token.AccessToken,
|
||||
Expires = Mogrify.CurrentDateTimeToTimeStamp() + token.ExtExpiresIn - 600,
|
||||
TokenType = token.TokenType
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
|
@ -12,7 +13,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>FCS.Lib.Azure</RootNamespace>
|
||||
<AssemblyName>FCS.Lib.Azure</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
|
@ -38,9 +39,14 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="AzureAuthStore.cs" />
|
||||
<Compile Include="AzureConfigStore.cs" />
|
||||
<Compile Include="AzureToken.cs" />
|
||||
<Compile Include="AzureTokenDto.cs" />
|
||||
<Compile Include="AzureTokenFetcher.cs" />
|
||||
<Compile Include="AzureTokenHttpRequest.cs" />
|
||||
<Compile Include="AzureTokenMapper.cs" />
|
||||
<Compile Include="IAzureConfigProvider.cs" />
|
||||
<Compile Include="IAzureTokenFetcher.cs" />
|
||||
<Compile Include="IAzureTokenProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -62,10 +68,6 @@
|
|||
<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>
|
||||
|
|
33
IAzureConfigProvider.cs
Normal file
33
IAzureConfigProvider.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="IAzureConfigProvider.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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 interface IAzureConfigProvider
|
||||
{
|
||||
AzureConfigStore GetAzureConfigStore(string country);
|
||||
AzureAuthStore GetAzureAuthStore();
|
||||
}
|
34
IAzureTokenFetcher.cs
Normal file
34
IAzureTokenFetcher.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="IAzureTokenFetcher.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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();
|
||||
}
|
48
IAzureTokenProvider.cs
Normal file
48
IAzureTokenProvider.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 02 13:17
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="IAzureTokenProvider.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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;
|
||||
|
||||
/// <summary>
|
||||
/// Interface IAzureTokenService
|
||||
/// </summary>
|
||||
public interface IAzureTokenProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Get access token
|
||||
/// </summary>
|
||||
/// <returns>Access token as async task</returns>
|
||||
Task<string> GetAccessToken();
|
||||
|
||||
/// <summary>
|
||||
/// Return if token is valid
|
||||
/// </summary>
|
||||
/// <param name="timestamp"></param>
|
||||
/// <returns>true/false</returns>
|
||||
bool TokenHasExpired(long timestamp);
|
||||
}
|
|
@ -1,4 +1,30 @@
|
|||
using System.Reflection;
|
||||
// ***********************************************************************
|
||||
// Assembly : FCS.Lib.Azure
|
||||
// Author :
|
||||
// Created : 2023 10 01 11:03
|
||||
//
|
||||
// Last Modified By : root
|
||||
// Last Modified On : 2023 10 02 15:24
|
||||
// ***********************************************************************
|
||||
// <copyright file="AssemblyInfo.cs" company="FCS">
|
||||
// Copyright (C) 2023-2023 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.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
|
16
app.config
16
app.config
|
@ -1,19 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.4" newVersion="6.0.0.4" />
|
||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.4" newVersion="6.0.0.4"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.Configuration" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
|
||||
|
|
Loading…
Reference in a new issue