From 00a491d93733d4625ad329b2ba8237f445364b3f Mon Sep 17 00:00:00 2001 From: Mirta Date: Wed, 30 Dec 2020 16:39:52 +0200 Subject: merge --- .../App_Start/BundleConfig.cs | 14 - .../App_Start/FilterConfig.cs | 13 - .../App_Start/RouteConfig.cs | 23 -- .../App_Start/WebApiConfig.cs | 23 -- .../Controllers/AzureUtilsController.cs | 59 ---- .../Controllers/GatewayController.cs | 41 --- .../Controllers/HomeController.cs | 16 - .../Controllers/ValuesController.cs | 39 --- .../Tango.MachineService.Gateway/DB/ENVIRONMENT.cs | 30 -- .../DB/GatewayDbContext.cs | 38 --- .../DTO/EnvironmentConfiguration.cs | 16 - .../Filters/JwtTokenFilter.cs | 60 ---- .../Tango.MachineService.Gateway/GatewayConfig.cs | 24 -- .../Web/Tango.MachineService.Gateway/Global.asax | 1 - .../Tango.MachineService.Gateway/Global.asax.cs | 56 ---- .../Messages/EnvironmentsRequest.cs | 12 - .../Messages/EnvironmentsResponse.cs | 17 - .../Nswag/GatewayClient.nswag | 140 --------- .../Properties/AssemblyInfo.cs | 35 --- .../machineservice-gateway - Web Deploy.pubxml | 28 -- .../Tango.MachineService.Gateway.csproj | 350 --------------------- .../TangoController.cs | 125 -------- .../Tango.MachineService.Gateway/Views/Web.config | 43 --- .../Views/_ViewStart.cshtml | 3 - .../Tango.MachineService.Gateway/Web.Debug.config | 30 -- .../Web.Release.config | 31 -- .../Web/Tango.MachineService.Gateway/Web.config | 114 ------- .../Web/Tango.MachineService.Gateway/WebToken.cs | 192 ----------- .../Tango.MachineService.Gateway/packages.config | 57 ---- 29 files changed, 1630 deletions(-) delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/BundleConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/FilterConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/RouteConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/WebApiConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/HomeController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/ValuesController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/AssemblyInfo.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/TangoController.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/Web.config delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/_ViewStart.cshtml delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Debug.config delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Release.config delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/WebToken.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway') diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/BundleConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/BundleConfig.cs deleted file mode 100644 index 68d6937d9..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/BundleConfig.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Web; -using System.Web.Optimization; - -namespace Tango.MachineService.Gateway -{ - public class BundleConfig - { - // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862 - public static void RegisterBundles(BundleCollection bundles) - { - - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/FilterConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/FilterConfig.cs deleted file mode 100644 index a915cef9e..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/FilterConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Web; -using System.Web.Mvc; - -namespace Tango.MachineService.Gateway -{ - public class FilterConfig - { - public static void RegisterGlobalFilters(GlobalFilterCollection filters) - { - filters.Add(new HandleErrorAttribute()); - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/RouteConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/RouteConfig.cs deleted file mode 100644 index 1adc877c0..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/RouteConfig.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; - -namespace Tango.MachineService.Gateway -{ - public class RouteConfig - { - public static void RegisterRoutes(RouteCollection routes) - { - routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - - routes.MapRoute( - name: "Default", - url: "{controller}/{action}/{id}", - defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } - ); - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/WebApiConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/WebApiConfig.cs deleted file mode 100644 index d3bc653da..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/App_Start/WebApiConfig.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web.Http; - -namespace Tango.MachineService.Gateway -{ - public static class WebApiConfig - { - public static void Register(HttpConfiguration config) - { - // Web API configuration and services - - // Web API routes - config.MapHttpAttributeRoutes(); - - config.Routes.MapHttpRoute( - name: "API Default", - routeTemplate: "api/{controller}/{action}/{id}", - defaults: new { id = RouteParameter.Optional }); - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs deleted file mode 100644 index ae5aa4543..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Authentication; -using System.Threading.Tasks; -using System.Web; -using System.Web.Mvc; -using Tango.AzureUtils; -using Tango.AzureUtils.Web; -using Tango.MachineService.Gateway.Filters; -using Tango.Web.Controllers; -using Tango.Web.Security; - -namespace Tango.MachineService.Gateway.Controllers -{ - public class AzureUtilsController : TangoController - { - public class TokenObject - { - public String Email { get; set; } - } - - [HttpPost] - public async Task Login(LoginRequest request) - { - var azure = await AzureUtils.AzureUtilsAuthenticationFactory.AuthenticateOrGetAsync(); - AzureUtils.ActiveDirectory.ActiveDirectoryManager adManager = new AzureUtils.ActiveDirectory.ActiveDirectoryManager(azure); - - try - { - await adManager.Authenticate(request.Email, request.Password); - } - catch (Exception ex) - { - throw new AuthenticationException("The specified email or password is incorrect.", ex); - } - - if (!adManager.IsUserMemberOf(GatewayConfig.AZURE_UTILS_GROUP, request.Email)) - { - throw new AuthenticationException("The specified user is not authorized to access the resource."); - } - - return new LoginResponse() - { - AccessToken = WebToken.CreateNew(GatewayConfig.JWT_TOKEN_SECRET, new TokenObject() - { - Email = request.Email, - }, DateTime.UtcNow.AddDays(1)).AccessToken, - }; - } - - [JwtTokenFilter] - public AzureUtilsCredentials GetCredentials() - { - return AzureUtils.AzureUtilsAuthenticationFactory.GetGlobalCredentials(); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs deleted file mode 100644 index e393c7264..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/GatewayController.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using Tango.MachineService.Gateway.DB; -using Tango.MachineService.Gateway.DTO; -using Tango.MachineService.Gateway.Messages; -using Tango.Web.Controllers; - -namespace Tango.MachineService.Gateway.Controllers -{ - public class GatewayController : TangoController - { - [HttpPost] - public EnvironmentsResponse GetEnvironments(EnvironmentsRequest request) - { - EnvironmentsResponse response = new EnvironmentsResponse(); - - using (GatewayDbContext db = GatewayDbContext.CreateDefault()) - { - var envs = db.Environments.Where(x => x.Active).ToList(); - - foreach (var env in envs) - { - response.Environments.Add(new EnvironmentConfiguration() - { - ID = env.ID.ToString(), - Name = env.Name, - Description = env.Description, - MachineServiceAddress = env.MachineServiceAddress, - DisplayIndex = env.DisplayIndex - }); - } - } - - return response; - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/HomeController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/HomeController.cs deleted file mode 100644 index f510f360c..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/HomeController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; - -namespace Tango.MachineService.Gateway.Controllers -{ - public class HomeController : Controller - { - public String Index() - { - return "Twine Gateway Service"; - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/ValuesController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/ValuesController.cs deleted file mode 100644 index 2c742706e..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/ValuesController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; - -namespace Tango.MachineService.Gateway.Controllers -{ - public class ValuesController : ApiController - { - // GET api/values - public IEnumerable Get() - { - return new string[] { "value1", "value2" }; - } - - // GET api/values/5 - public string Get(int id) - { - return "value"; - } - - // POST api/values - public void Post([FromBody]string value) - { - } - - // PUT api/values/5 - public void Put(int id, [FromBody]string value) - { - } - - // DELETE api/values/5 - public void Delete(int id) - { - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs deleted file mode 100644 index 7ab5bddbc..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/ENVIRONMENT.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Gateway.DB -{ - [Table("ENVIRONMENTS")] - public class Environment - { - [Column("ID")] - public int ID { get; set; } - - [Column("NAME")] - public String Name { get; set; } - - [Column("DESCRIPTION")] - public String Description { get; set; } - - [Column("MACHINE_SERVICE_ADDRESS")] - public String MachineServiceAddress { get; set; } - - [Column("DISPLAY_INDEX")] - public int DisplayIndex { get; set; } - - [Column("ACTIVE")] - public bool Active { get; set; } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs deleted file mode 100644 index 9f4a9f0f9..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DB/GatewayDbContext.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.Entity; -using System.Linq; -using System.Web; -using Tango.Core; - -namespace Tango.MachineService.Gateway.DB -{ - public class GatewayDbContext : DbContext - { - public GatewayDbContext(DataSource dataSource) : base(dataSource.ToConnection(), true) - { - - } - - public static GatewayDbContext CreateDefault() - { - return new GatewayDbContext(new DataSource() - { - Address = GatewayConfig.DB_ADDRESS, - IntegratedSecurity = false, - Catalog = GatewayConfig.DB_CATALOG, - Type = DataSourceType.SQLServer, - UserName = GatewayConfig.DB_USER_NAME, - Password = GatewayConfig.DB_PASSWORD - }); - } - - /// - /// Gets or sets the environments. - /// - public DbSet Environments - { - get; set; - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs deleted file mode 100644 index 25ba9ba3d..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/DTO/EnvironmentConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Gateway.DTO -{ - public class EnvironmentConfiguration - { - public String ID { get; set; } - public String Name { get; set; } - public String Description { get; set; } - public String MachineServiceAddress { get; set; } - public int DisplayIndex { get; set; } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs deleted file mode 100644 index 841fd6baa..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Authentication; -using System.Web; -using System.Web.Http; -using System.Web.Http.Controllers; -using System.Web.Http.Filters; -using Tango.Web.Security; - -namespace Tango.MachineService.Gateway.Filters -{ - public class JwtTokenFilter : ActionFilterAttribute - { - public bool AllowExpired { get; private set; } - - public JwtTokenFilter() - { - - } - - public JwtTokenFilter(bool allowExpired) - { - AllowExpired = allowExpired; - } - - public override void OnActionExecuting(HttpActionContext actionContext) - { - var authorizationHeader = actionContext.Request.Headers.Authorization; - - if (authorizationHeader != null && authorizationHeader.Parameter != null) - { - try - { - WebToken.Validate(GatewayConfig.JWT_TOKEN_SECRET, authorizationHeader.Parameter); - } - catch (JWT.TokenExpiredException) - { - if (!AllowExpired) - { - throw new AuthenticationException("Token expired."); - } - } - catch (JWT.SignatureVerificationException) - { - throw new AuthenticationException("Invalid token."); - } - } - else - { - throw new AuthenticationException("No token specified."); - } - - base.OnActionExecuting(actionContext); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs deleted file mode 100644 index dbbb10709..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Web; -using Tango.Web; - -namespace Tango.MachineService.Gateway -{ - public class GatewayConfig - { - public static String DB_ADDRESS => ConfigurationManager.AppSettings[nameof(DB_ADDRESS)].ToString(); - public static String DB_USER_NAME => ConfigurationManager.AppSettings[nameof(DB_USER_NAME)].ToString(); - public static String DB_PASSWORD => ConfigurationManager.AppSettings[nameof(DB_PASSWORD)].ToString(); - public static String DB_CATALOG => ConfigurationManager.AppSettings[nameof(DB_CATALOG)].ToString(); - - public static String JWT_TOKEN_SECRET => ConfigurationManager.AppSettings[nameof(JWT_TOKEN_SECRET)].ToString(); - public static String AZURE_UTILS_GROUP => ConfigurationManager.AppSettings[nameof(AZURE_UTILS_GROUP)].ToString(); - public static String TENANT_ID => ConfigurationManager.AppSettings[nameof(TENANT_ID)].ToString(); - public static String CLIENT_ID => ConfigurationManager.AppSettings[nameof(CLIENT_ID)].ToString(); - public static String CLIENT_SECRET => ConfigurationManager.AppSettings[nameof(CLIENT_SECRET)].ToString(); - public static String SUBSCRIPTION_ID => ConfigurationManager.AppSettings[nameof(SUBSCRIPTION_ID)].ToString(); - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax deleted file mode 100644 index badf913e2..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax +++ /dev/null @@ -1 +0,0 @@ -<%@ Application Codebehind="Global.asax.cs" Inherits="Tango.MachineService.Gateway.WebApiApplication" Language="C#" %> diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs deleted file mode 100644 index 52b370236..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Http; -using System.Web.Http.Filters; -using System.Web.Mvc; -using System.Web.Optimization; -using System.Web.Routing; -using Tango.Logging; - -namespace Tango.MachineService.Gateway -{ - public class WebApiApplication : System.Web.HttpApplication - { - protected void Application_Start() - { - LogManager.Default.Categories.Add(LogCategory.Debug); - //LogManager.Default.RegisterLogger(new AzureCloudLogger()); - GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute()); - - LogManager.Default.Log("Application Started!"); - - //AreaRegistration.RegisterAllAreas(); - GlobalConfiguration.Configure(WebApiConfig.Register); - FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); - RouteConfig.RegisterRoutes(RouteTable.Routes); - BundleConfig.RegisterBundles(BundleTable.Bundles); - - AzureUtils.AzureUtilsAuthenticationFactory.SetGlobalCredentials(new AzureUtils.AzureUtilsCredentials() - { - ClientID = GatewayConfig.CLIENT_ID, - ClientSecret = GatewayConfig.CLIENT_SECRET, - TenantID = GatewayConfig.TENANT_ID, - SubscriptionID = GatewayConfig.SUBSCRIPTION_ID - }); - } - - public class LogExceptionFilterAttribute : ExceptionFilterAttribute - { - public override void OnException(HttpActionExecutedContext context) - { - LogManager.Default.Log(context.Exception); - } - } - - protected void Application_Error(object sender, EventArgs e) - { - Exception exception = Server.GetLastError(); - if (exception != null) - { - LogManager.Default.Log(exception, "Global Exception!"); - } - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs deleted file mode 100644 index 6d2ab0f8d..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Gateway.Messages -{ - public class EnvironmentsRequest - { - public String AppSecret { get; set; } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs deleted file mode 100644 index 2063d5e59..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/EnvironmentsResponse.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Tango.MachineService.Gateway.DTO; - -namespace Tango.MachineService.Gateway.Messages -{ - public class EnvironmentsResponse - { - public List Environments { get; set; } - - public EnvironmentsResponse() - { - Environments = new List(); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag deleted file mode 100644 index d3db33524..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Nswag/GatewayClient.nswag +++ /dev/null @@ -1,140 +0,0 @@ -{ - "runtime": "Default", - "defaultVariables": "", - "documentGenerator": { - "webApiToOpenApi": { - "controllerNames": [ - "Tango.MachineService.Gateway.Controllers.GatewayController" - ], - "isAspNetCore": false, - "resolveJsonOptions": false, - "defaultUrlTemplate": "api/{controller}/{action}", - "addMissingPathParameters": false, - "includedVersions": null, - "defaultPropertyNameHandling": "Default", - "defaultReferenceTypeNullHandling": "Null", - "defaultDictionaryValueReferenceTypeNullHandling": "NotNull", - "defaultResponseReferenceTypeNullHandling": "NotNull", - "defaultEnumHandling": "Integer", - "flattenInheritanceHierarchy": false, - "generateKnownTypes": true, - "generateEnumMappingDescription": false, - "generateXmlObjects": false, - "generateAbstractProperties": false, - "generateAbstractSchemas": true, - "ignoreObsoleteProperties": false, - "allowReferencesWithProperties": false, - "excludedTypeNames": [], - "serviceHost": null, - "serviceBasePath": null, - "serviceSchemes": [], - "infoTitle": "My Title", - "infoDescription": null, - "infoVersion": "1.0.0", - "documentTemplate": null, - "documentProcessorTypes": [], - "operationProcessorTypes": [], - "typeNameGeneratorType": null, - "schemaNameGeneratorType": null, - "contractResolverType": null, - "serializerSettingsType": null, - "useDocumentProvider": true, - "documentName": "v1", - "aspNetCoreEnvironment": null, - "createWebHostBuilderMethod": null, - "startupType": null, - "allowNullableBodyParameters": true, - "output": null, - "outputType": "Swagger2", - "assemblyPaths": [ - "$(assembly)" - ], - "assemblyConfig": null, - "referencePaths": [], - "useNuGetCache": false - } - }, - "codeGenerators": { - "openApiToCSharpClient": { - "clientBaseClass": null, - "configurationClass": null, - "generateClientClasses": true, - "generateClientInterfaces": false, - "injectHttpClient": true, - "disposeHttpClient": true, - "protectedMethods": [], - "generateExceptionClasses": true, - "exceptionClass": "ApiException", - "wrapDtoExceptions": true, - "useHttpClientCreationMethod": false, - "httpClientType": "System.Net.Http.HttpClient", - "useHttpRequestMessageCreationMethod": false, - "useBaseUrl": true, - "generateBaseUrlProperty": true, - "generateSyncMethods": true, - "exposeJsonSerializerSettings": false, - "clientClassAccessModifier": "public", - "typeAccessModifier": "public", - "generateContractsOutput": false, - "contractsNamespace": null, - "contractsOutputFilePath": null, - "parameterDateTimeFormat": "s", - "parameterDateFormat": "yyyy-MM-dd", - "generateUpdateJsonSerializerSettingsMethod": true, - "useRequestAndResponseSerializationSettings": false, - "serializeTypeInformation": false, - "queryNullValue": "", - "className": "GatewayClient", - "operationGenerationMode": "MultipleClientsFromOperationId", - "additionalNamespaceUsages": [], - "additionalContractNamespaceUsages": [], - "generateOptionalParameters": false, - "generateJsonMethods": false, - "enforceFlagEnums": false, - "parameterArrayType": "System.Collections.Generic.IEnumerable", - "parameterDictionaryType": "System.Collections.Generic.IDictionary", - "responseArrayType": "System.Collections.Generic.ICollection", - "responseDictionaryType": "System.Collections.Generic.IDictionary", - "wrapResponses": false, - "wrapResponseMethods": [], - "generateResponseClasses": true, - "responseClass": "SwaggerResponse", - "namespace": "Tango.MachineService.Gateway", - "requiredPropertiesMustBeDefined": true, - "dateType": "System.DateTimeOffset", - "jsonConverters": null, - "anyType": "object", - "dateTimeType": "System.DateTimeOffset", - "timeType": "System.TimeSpan", - "timeSpanType": "System.TimeSpan", - "arrayType": "System.Collections.Generic.ICollection", - "arrayInstanceType": "System.Collections.ObjectModel.Collection", - "dictionaryType": "System.Collections.Generic.IDictionary", - "dictionaryInstanceType": "System.Collections.Generic.Dictionary", - "arrayBaseType": "System.Collections.ObjectModel.Collection", - "dictionaryBaseType": "System.Collections.Generic.Dictionary", - "classStyle": "Poco", - "generateDefaultValues": true, - "generateDataAnnotations": true, - "excludedTypeNames": [], - "excludedParameterNames": [], - "handleReferences": false, - "generateImmutableArrayProperties": false, - "generateImmutableDictionaryProperties": false, - "jsonSerializerSettingsTransformationMethod": null, - "inlineNamedArrays": false, - "inlineNamedDictionaries": false, - "inlineNamedTuples": true, - "inlineNamedAny": false, - "generateDtoTypes": true, - "generateOptionalPropertiesAsNullable": false, - "templateDirectory": null, - "typeNameGeneratorType": null, - "propertyNameGeneratorType": null, - "enumNameGeneratorType": null, - "serviceHost": null, - "serviceSchemes": null, - "output": "$(output)" - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/AssemblyInfo.cs deleted file mode 100644 index 0df63df7a..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Tango.MachineService.Gateway")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Tango.MachineService.Gateway")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("8883a0c7-a35b-4eea-97ea-34eb8101dd21")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml deleted file mode 100644 index 8af9f7fc8..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - MSDeploy - /subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice-gateway - Tango - AzureWebSite - Release - Any CPU - http://machineservice-gateway.azurewebsites.net - True - False - machineservice-gateway.scm.azurewebsites.net:443 - machineservice-gateway - - True - False - WMSVC - True - $machineservice-gateway - <_SavePWD>True - <_DestinationType>AzureWebSite - - \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj deleted file mode 100644 index f749f7f57..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - Debug - AnyCPU - - - 2.0 - {0F5F28AD-81B9-43A0-9BA7-CFB74F37202C} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Tango.MachineService.Gateway - Tango.MachineService.Gateway - v4.6.1 - false - true - - - - - - - - - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - - - true - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll - - - ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll - - - ..\..\packages\JWT.5.0.0\lib\net46\JWT.dll - True - - - ..\..\packages\Microsoft.Azure.KeyVault.3.0.1\lib\net452\Microsoft.Azure.KeyVault.dll - - - ..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll - - - ..\..\packages\Microsoft.Azure.KeyVault.WebKey.3.0.1\lib\net452\Microsoft.Azure.KeyVault.WebKey.dll - - - ..\..\packages\Microsoft.Azure.Management.AppService.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.AppService.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.BatchAI.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.BatchAI.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Cdn.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Cdn.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Compute.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Compute.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.ContainerInstance.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.ContainerInstance.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.ContainerRegistry.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.ContainerRegistry.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.ContainerService.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.ContainerService.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.CosmosDB.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.CosmosDB.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Dns.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Dns.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.EventHub.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.EventHub.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Graph.RBAC.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Graph.RBAC.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.KeyVault.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.KeyVault.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Locks.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Locks.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Monitor.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Monitor.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Msi.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Msi.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Network.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Network.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.PrivateDns.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.PrivateDns.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Redis.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Redis.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.ResourceManager.Fluent.1.31.0\lib\net461\Microsoft.Azure.Management.ResourceManager.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Search.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Search.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.ServiceBus.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.ServiceBus.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Sql.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Sql.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.Storage.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.Storage.Fluent.dll - - - ..\..\packages\Microsoft.Azure.Management.TrafficManager.Fluent.1.31.0\lib\net452\Microsoft.Azure.Management.TrafficManager.Fluent.dll - - - - ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.4.3.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - - ..\..\packages\Microsoft.IdentityModel.Logging.1.1.2\lib\net451\Microsoft.IdentityModel.Logging.dll - - - ..\..\packages\Microsoft.IdentityModel.Tokens.5.1.2\lib\net451\Microsoft.IdentityModel.Tokens.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.19\lib\net461\Microsoft.Rest.ClientRuntime.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.4.0\lib\net461\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll - - - ..\..\packages\WindowsAzure.Storage.9.3.3\lib\net45\Microsoft.WindowsAzure.Storage.dll - - - - - - - - - - - - - - - - - - - - - - - True - ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - - ..\..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll - - - - - ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.4\lib\net45\System.Net.Http.Formatting.dll - - - - - True - ..\..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.Helpers.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.4\lib\net45\System.Web.Http.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.4\lib\net45\System.Web.Http.WebHost.dll - - - True - ..\..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll - - - ..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll - - - True - ..\..\packages\Microsoft.AspNet.Razor.3.2.4\lib\net45\System.Web.Razor.dll - - - True - ..\..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.dll - - - True - ..\..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Deployment.dll - - - True - ..\..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Razor.dll - - - True - ..\..\packages\WebGrease.1.6.0\lib\WebGrease.dll - - - True - ..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll - - - - - ..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - - - - - - - - - - - - - - - - - Global.asax - - - - - - - - - - - - Designer - - - Web.config - - - Web.config - - - - - - - - - - - - Designer - - - - - - {4a6b97e5-5eba-4702-a016-6f4004f14b08} - Tango.AzureUtils - - - {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} - Tango.Core - - - {bc932dbd-7cdb-488c-99e4-f02cf441f55e} - Tango.Logging - - - - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - - - - - - - - - True - True - 53838 - / - http://localhost:2222/ - False - False - - - False - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/TangoController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/TangoController.cs deleted file mode 100644 index d44a14950..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/TangoController.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Authentication; -using System.Threading; -using System.Threading.Tasks; -using System.Web; -using System.Web.Http; -using System.Web.Http.Controllers; -using Tango.Logging; -using Tango.Web.Security; - -namespace Tango.Web.Controllers -{ - public class TangoController : ApiController - { - protected LogManager LogManager { get; private set; } - - public TangoController() - { - LogManager = LogManager.Default; - } - - public override async Task ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken) - { - string controllerName = String.Empty; - string actionName = String.Empty; - - try - { - var routeData = HttpContext.Current.Request.RequestContext.RouteData; - actionName = routeData.Values["action"].ToString(); - controllerName = routeData.Values["controller"].ToString(); - } - catch { } - - try - { - String request = String.Empty; - - try - { - request = context.Request.Content.ReadAsStringAsync().Result; - } - catch { } - - LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}"); - - OnRequestArrived(context.Request); - - var result = await base.ExecuteAsync(context, cancellationToken); - return result; - } - catch (Exception ex) - { - LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}."); - - HttpStatusCode code = HttpStatusCode.InternalServerError; - - if (ex is ArgumentException || ex is InvalidDataException) - { - code = HttpStatusCode.BadRequest; - } - else if (ex is AuthenticationException) - { - code = HttpStatusCode.Unauthorized; - } - - var httpException = new HttpResponseException(Request.CreateErrorResponse(code, ex.FlattenMessage(), ex)); - -#if DEBUG - throw httpException; -#else - //Remove Stack trace - var expandedException = httpException.Response.Content as System.Net.Http.ObjectContent; - - if (expandedException != null) - { - var expandedExceptionValues = expandedException.Value as HttpError; - - if (expandedExceptionValues != null) - { - expandedExceptionValues["StackTrace"] = "StackTrace not provided."; - } - } -#endif - - - throw httpException; - } - } - - protected virtual void OnRequestArrived(HttpRequestMessage request) - { - //Do nothing. - } - } - - public class TangoController : TangoController where T : class - { - public WebToken RequestToken { get; set; } - - protected override void OnRequestArrived(HttpRequestMessage request) - { - base.OnRequestArrived(request); - - var authorizationHeader = request.Headers.Authorization; - - if (authorizationHeader != null) - { - try - { - RequestToken = WebToken.FromToken(authorizationHeader.Parameter != null ? authorizationHeader.Parameter : authorizationHeader.ToString()); - } - catch (Exception ex) - { - throw new HttpParseException("Could not parse the provided token embedded object.", ex); - } - } - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/Web.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/Web.config deleted file mode 100644 index ecea3014b..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/Web.config +++ /dev/null @@ -1,43 +0,0 @@ - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/_ViewStart.cshtml b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/_ViewStart.cshtml deleted file mode 100644 index 2de62418c..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "~/Views/Shared/_Layout.cshtml"; -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Debug.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Debug.config deleted file mode 100644 index d7712aaf1..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Debug.config +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Release.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Release.config deleted file mode 100644 index 28a4d5fcc..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Release.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config deleted file mode 100644 index 6dd29d57d..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config +++ /dev/null @@ -1,114 +0,0 @@ - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/WebToken.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/WebToken.cs deleted file mode 100644 index 7aa4860ab..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/WebToken.cs +++ /dev/null @@ -1,192 +0,0 @@ -using JWT; -using JWT.Algorithms; -using JWT.Builder; -using JWT.Serializers; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Web.Security -{ - public class WebToken - { - public DateTime Issued { get; protected set; } - public DateTime? Expiration { get; protected set; } - public String AccessToken { get; protected set; } - public String RefreshToken { get; protected set; } - - public WebToken() - { - - } - - public static WebToken CreateNew(String secret, DateTime? expiration = null) - { - DateTime issued = DateTime.UtcNow; - - var builder = new JwtBuilder() - .WithAlgorithm(new HMACSHA256Algorithm()) - .WithSecret(secret) - .IssuedAt(issued); - - if (expiration != null) - { - builder = builder.ExpirationTime(expiration.Value); - } - - String refreshToken = Guid.NewGuid().ToString(); - - builder = builder.AddClaim("object", null); - builder = builder.AddClaim("refresh-token", refreshToken); - - return new WebToken() - { - AccessToken = builder.Build(), - RefreshToken = refreshToken, - Expiration = expiration, - Issued = issued, - }; - } - - public static void Validate(String secret, String token) - { - var json = new JwtBuilder() - .WithSecret(secret) - .MustVerifySignature() - .Decode(token); - } - - public void Validate(String secret) - { - var json = new JwtBuilder() - .WithSecret(secret) - .MustVerifySignature() - .Decode(AccessToken); - } - - public WebToken Renew(String secret) - { - var newToken = CreateNew(secret, DateTime.UtcNow.Add(Expiration.Value - Issued)); - newToken.RefreshToken = RefreshToken; - return newToken; - } - - public static WebToken FromToken(String token) - { - WebToken webToken = new WebToken(); - - var payload = new JwtBuilder() - .WithValidator(null) - .Decode>(token); - - webToken.AccessToken = token; - - if (payload.ContainsKey("exp")) - { - long exp = long.Parse(payload["exp"].ToString()); - webToken.Expiration = ConvertEpochToDateTime(exp); - } - - if (payload.ContainsKey("iat")) - { - long iat = long.Parse(payload["iat"].ToString()); - webToken.Issued = ConvertEpochToDateTime(iat); - } - - if (payload.ContainsKey("refresh-token")) - { - webToken.RefreshToken = payload["refresh-token"].ToString(); - } - - return webToken; - } - - protected static DateTime ConvertEpochToDateTime(long seconds) - { - var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - return epoch.AddSeconds(seconds); - } - } - - public class WebToken : WebToken where T : class - { - public T Object { get; protected set; } - - private WebToken() - { - - } - - public static WebToken CreateNew(String secret, T obj = null, DateTime? expiration = null) - { - DateTime issued = DateTime.UtcNow; - - var builder = new JwtBuilder() - .WithAlgorithm(new HMACSHA256Algorithm()) - .WithSecret(secret) - .IssuedAt(issued); - - if (expiration != null) - { - builder = builder.ExpirationTime(expiration.Value); - } - - String refreshToken = Guid.NewGuid().ToString(); - - builder = builder.AddClaim("object", obj); - builder = builder.AddClaim("refresh-token", refreshToken); - - return new WebToken() - { - AccessToken = builder.Build(), - RefreshToken = refreshToken, - Expiration = expiration, - Issued = issued, - Object = obj, - }; - } - - public static new WebToken FromToken(String token) - { - WebToken webToken = new WebToken(); - - var payload = new JwtBuilder() - .WithValidator(null) - .Decode>(token); - - webToken.AccessToken = token; - - if (payload.ContainsKey("exp")) - { - long exp = long.Parse(payload["exp"].ToString()); - webToken.Expiration = ConvertEpochToDateTime(exp); - } - - if (payload.ContainsKey("iat")) - { - long iat = long.Parse(payload["iat"].ToString()); - webToken.Issued = ConvertEpochToDateTime(iat); - } - - if (payload.ContainsKey("refresh-token")) - { - webToken.RefreshToken = payload["refresh-token"].ToString(); - } - - webToken.Object = JsonConvert.DeserializeObject(payload["object"].ToString()); - - return webToken; - } - - public new WebToken Renew(String secret) - { - var newToken = WebToken.CreateNew(secret, Object, DateTime.UtcNow.Add(Expiration.Value - Issued)); - newToken.RefreshToken = RefreshToken; - return newToken; - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config deleted file mode 100644 index 72f15dbf6..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/packages.config +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- cgit v1.3.1