aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-02-12 18:26:56 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-02-12 18:26:56 +0200
commitd17cd66d675ec9de79c8a12b57d75079dba62eee (patch)
treee11d193c7843db8d200eae4e9bbe329723bc26fa /Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
parent18477c8dc7e7971f2cfb08d0e11ca483944f79f2 (diff)
downloadTango-d17cd66d675ec9de79c8a12b57d75079dba62eee.tar.gz
Tango-d17cd66d675ec9de79c8a12b57d75079dba62eee.zip
Gateway
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs62
1 files changed, 62 insertions, 0 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
new file mode 100644
index 000000000..2daf3c7e6
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Controllers/AzureUtilsController.cs
@@ -0,0 +1,62 @@
+using Microsoft.IdentityModel.Clients.ActiveDirectory;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Authentication;
+using System.Web;
+using System.Web.Mvc;
+using Tango.MachineService.Gateway.Filters;
+using Tango.MachineService.Gateway.Messages;
+using Tango.Web.Controllers;
+using Tango.Web.Security;
+
+namespace Tango.MachineService.Gateway.Controllers
+{
+ public class AzureUtilsController : TangoController<AzureUtilsController.TokenObject>
+ {
+ public class TokenObject
+ {
+ public String Email { get; set; }
+ }
+
+ [HttpPost]
+ public LoginResponse Login(LoginRequest request)
+ {
+ var azure = AzureUtils.AzureUtilsAuthenticationFactory.AuthenticateOrGetAsync().Result;
+ AzureUtils.ActiveDirectory.ActiveDirectoryManager adManager = new AzureUtils.ActiveDirectory.ActiveDirectoryManager(azure);
+
+ try
+ {
+ adManager.Authenticate(request.Email, request.Password).GetAwaiter().GetResult();
+ }
+ catch (Exception ex)
+ {
+ throw new AuthenticationException("The specified email or password is incorrect.", ex);
+ }
+
+ try
+ {
+ adManager.IsUserMemberOf(MachineServiceGatewayConfig.AZURE_UTILS_GROUP, request.Email);
+ }
+ catch
+ {
+ 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()
+ {
+ Email = request.Email,
+ }, DateTime.UtcNow.AddDays(1)).AccessToken,
+ };
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public void DoSomethingSecret()
+ {
+
+ }
+ }
+} \ No newline at end of file