aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2018-12-28 23:39:51 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2018-12-28 23:39:51 +0200
commit68a9642a95545368ed7e9f9a7e2836f86143b439 (patch)
treed1123ea21bcb5fee99652c61054a712b5029b576 /Software/Visual_Studio/Tango.Web
parent537212b4aa3419d75ce015e5aa3a455288dc430a (diff)
downloadTango-68a9642a95545368ed7e9f9a7e2836f86143b439.tar.gz
Tango-68a9642a95545368ed7e9f9a7e2836f86143b439.zip
Implemented SQLManager with access token authentication.
Diffstat (limited to 'Software/Visual_Studio/Tango.Web')
-rw-r--r--Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs37
-rw-r--r--Software/Visual_Studio/Tango.Web/Tango.Web.csproj1
2 files changed, 38 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
new file mode 100644
index 000000000..55d18d119
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Web/SQLServer/SQLServerManager.cs
@@ -0,0 +1,37 @@
+using Microsoft.IdentityModel.Clients.ActiveDirectory;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Web.SQLServer
+{
+ public class SQLServerManager
+ {
+ private String _service_root = $"https://login.microsoftonline.com/{WebConfig.TENANT_ID}";
+
+ public String GetAccessToken()
+ {
+ var authContext = new AuthenticationContext(_service_root);
+ ClientCredential clientCredentials = new ClientCredential(WebConfig.CLIENT_ID, WebConfig.APP_SECRET);
+ AuthenticationResult authResult = authContext.AcquireToken("https://database.windows.net/", clientCredentials);
+ return authResult.AccessToken;
+ }
+
+ public SqlConnection CreateSqlConnection(String accessToken, String catalog)
+ {
+ SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
+ builder.DataSource = "twine.database.windows.net";
+ builder.InitialCatalog = catalog;
+ builder.MultipleActiveResultSets = true;
+ builder.ApplicationName = "EntityFramework";
+
+ SqlConnection sqlConnection = new SqlConnection(builder.ConnectionString);
+ sqlConnection.AccessToken = accessToken;
+
+ return sqlConnection;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
index 0f04121d1..d9a1d1dd1 100644
--- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
+++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj
@@ -247,6 +247,7 @@
<Compile Include="Authentication\TokensManager.cs" />
<Compile Include="DeploymentSlot.cs" />
<Compile Include="Logging\AzureCloudLogger.cs" />
+ <Compile Include="SQLServer\SQLServerManager.cs" />
<Compile Include="Storage\ExtensionMethods.cs" />
<Compile Include="Storage\StorageManager.cs" />
<Compile Include="TangoWebApplication.cs" />