From 678b22afc27e53811f978103b7ea41609ff68606 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 13 Feb 2020 23:09:44 +0200 Subject: Implemented and deployed machine service gateway. Implemented AzureUtils => Gateway. --- .../Controllers/AzureUtilsController.cs | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs') 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 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.CreateNew(MachineServiceGatewayConfig.JWT_TOKEN_SECRET, new TokenObject() + AccessToken = WebToken.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 -- cgit v1.3.1