aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService.Gateway
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-13 23:09:44 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-13 23:09:44 +0200
commit678b22afc27e53811f978103b7ea41609ff68606 (patch)
treefaaabb6468c1b22d770eb753eeac39b34ef65e4f /Software/Visual_Studio/Web/Tango.MachineService.Gateway
parent69f27fd4bfc5a46fad019b06c9c8d06159c400b9 (diff)
downloadTango-678b22afc27e53811f978103b7ea41609ff68606.tar.gz
Tango-678b22afc27e53811f978103b7ea41609ff68606.zip
Implemented and deployed machine service gateway.
Implemented AzureUtils => Gateway.
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs23
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs2
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs (renamed from Software/Visual_Studio/Web/Tango.MachineService.Gateway/MachineServiceGatewayConfig.cs)2
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs8
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginRequest.cs13
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginResponse.cs12
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml28
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj5
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config20
9 files changed, 70 insertions, 43 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
index 2daf3c7e6..ae5aa4543 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
@@ -3,10 +3,12 @@ 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.MachineService.Gateway.Messages;
using Tango.Web.Controllers;
using Tango.Web.Security;
@@ -20,43 +22,38 @@ namespace Tango.MachineService.Gateway.Controllers
}
[HttpPost]
- public LoginResponse Login(LoginRequest request)
+ public async Task<LoginResponse> Login(LoginRequest request)
{
- var azure = AzureUtils.AzureUtilsAuthenticationFactory.AuthenticateOrGetAsync().Result;
+ var azure = await AzureUtils.AzureUtilsAuthenticationFactory.AuthenticateOrGetAsync();
AzureUtils.ActiveDirectory.ActiveDirectoryManager adManager = new AzureUtils.ActiveDirectory.ActiveDirectoryManager(azure);
try
{
- adManager.Authenticate(request.Email, request.Password).GetAwaiter().GetResult();
+ await adManager.Authenticate(request.Email, request.Password);
}
catch (Exception ex)
{
throw new AuthenticationException("The specified email or password is incorrect.", ex);
}
- try
- {
- adManager.IsUserMemberOf(MachineServiceGatewayConfig.AZURE_UTILS_GROUP, request.Email);
- }
- catch
+ 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<TokenObject>.CreateNew(MachineServiceGatewayConfig.JWT_TOKEN_SECRET, new TokenObject()
+ AccessToken = WebToken<TokenObject>.CreateNew(GatewayConfig.JWT_TOKEN_SECRET, new TokenObject()
{
Email = request.Email,
}, DateTime.UtcNow.AddDays(1)).AccessToken,
};
}
- [HttpPost]
[JwtTokenFilter]
- public void DoSomethingSecret()
+ public AzureUtilsCredentials GetCredentials()
{
-
+ return AzureUtils.AzureUtilsAuthenticationFactory.GetGlobalCredentials();
}
}
} \ 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
index 4f2b26e82..841fd6baa 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Filters/JwtTokenFilter.cs
@@ -35,7 +35,7 @@ namespace Tango.MachineService.Gateway.Filters
{
try
{
- WebToken.Validate(MachineServiceGatewayConfig.JWT_TOKEN_SECRET, authorizationHeader.Parameter);
+ WebToken.Validate(GatewayConfig.JWT_TOKEN_SECRET, authorizationHeader.Parameter);
}
catch (JWT.TokenExpiredException)
{
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/MachineServiceGatewayConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs
index 3a91ef181..e7ad241ed 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/MachineServiceGatewayConfig.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/GatewayConfig.cs
@@ -7,7 +7,7 @@ using Tango.Web;
namespace Tango.MachineService.Gateway
{
- public class MachineServiceGatewayConfig
+ public class GatewayConfig
{
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();
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs
index 20df6c0bb..52b370236 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Global.asax.cs
@@ -26,6 +26,14 @@ namespace Tango.MachineService.Gateway
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
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginRequest.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginRequest.cs
deleted file mode 100644
index 40a0cd744..000000000
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginRequest.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-
-namespace Tango.MachineService.Gateway.Messages
-{
- public class LoginRequest
- {
- public String Email { get; set; }
- public String Password { get; set; }
- }
-} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginResponse.cs b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginResponse.cs
deleted file mode 100644
index da569ee99..000000000
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Messages/LoginResponse.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 LoginResponse
- {
- public String AccessToken { get; set; }
- }
-} \ No newline at end of file
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
new file mode 100644
index 000000000..8af9f7fc8
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Properties/PublishProfiles/machineservice-gateway - Web Deploy.pubxml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This file is used by the publish/package process of your Web project. You can customize the behavior of this process
+by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <WebPublishMethod>MSDeploy</WebPublishMethod>
+ <ResourceId>/subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/machineservice-gateway</ResourceId>
+ <ResourceGroup>Tango</ResourceGroup>
+ <PublishProvider>AzureWebSite</PublishProvider>
+ <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
+ <LastUsedPlatform>Any CPU</LastUsedPlatform>
+ <SiteUrlToLaunchAfterPublish>http://machineservice-gateway.azurewebsites.net</SiteUrlToLaunchAfterPublish>
+ <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
+ <ExcludeApp_Data>False</ExcludeApp_Data>
+ <MSDeployServiceURL>machineservice-gateway.scm.azurewebsites.net:443</MSDeployServiceURL>
+ <DeployIisAppPath>machineservice-gateway</DeployIisAppPath>
+ <RemoteSitePhysicalPath />
+ <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
+ <InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension>
+ <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
+ <EnableMSDeployBackup>True</EnableMSDeployBackup>
+ <UserName>$machineservice-gateway</UserName>
+ <_SavePWD>True</_SavePWD>
+ <_DestinationType>AzureWebSite</_DestinationType>
+ </PropertyGroup>
+</Project> \ 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
index c9232d7b9..c1f3b59bd 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Tango.MachineService.Gateway.csproj
@@ -248,9 +248,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
- <Compile Include="MachineServiceGatewayConfig.cs" />
- <Compile Include="Messages\LoginRequest.cs" />
- <Compile Include="Messages\LoginResponse.cs" />
+ <Compile Include="GatewayConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TangoController.cs" />
<Compile Include="WebToken.cs" />
@@ -273,6 +271,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="Properties\PublishProfiles\machineservice-gateway - Web Deploy.pubxml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Azure\Tango.AzureUtils\Tango.AzureUtils.csproj">
diff --git a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config
index 64ebb21b3..f53e9c92e 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.config
@@ -9,6 +9,26 @@
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
+
+ <add key="DB_ADDRESS" value="twine.database.windows.net" />
+ <add key="DB_USER_NAME" value="Roy" />
+ <add key="DB_PASSWORD" value="Aa123456" />
+ <add key="DB_CATALOG" value="Tango_Gateway" />
+
+ <add key="TENANT_ID" value="2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4" />
+ <add key="CLIENT_ID" value="be33437c-5052-449f-ab9d-a88d008eae24" />
+ <add key="CLIENT_SECRET" value="bf67fb6f-4d06-4893-988c-6b347aff23d6" />
+ <add key="SUBSCRIPTION_ID" value="10c8aa60-3b15-4e0d-b412-6aeef90e5e91" />
+
+ <add key="AZURE_UTILS_GROUP" value="Azure Utils" />
+
+ <add key="STORAGE_ACCOUNT" value="DefaultEndpointsProtocol=https;AccountName=tangostorage;AccountKey=S4z/D+Yg6mwMis+bs/VpcDLA9yE1iZaYq23shQlRIi2KmM9E7JY8zdZjeAPOPdG3gONHoNDEpsgH6D4cqQ/bsA==;EndpointSuffix=core.windows.net" />
+ <add key="TANGO_VERSIONS_CONTAINER" value="tango-versions-dev" />
+ <add key="MACHINE_STUDIO_VERSIONS_CONTAINER" value="machine-studio-versions-dev" />
+
+ <add key="JWT_TOKEN_SECRET" value="GQDstcKsx0NHjLOuXOYg5MbeJ1yT0u1iwDVTwine" />
+
+ <add key="CDN_ENDPOINT" value="https://tango.azureedge.net" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />