diff --git a/samples/features/security/AAD Auth/Integrated/App.config b/samples/features/security/AAD Auth/Integrated/App.config new file mode 100644 index 00000000..2d2a12d8 --- /dev/null +++ b/samples/features/security/AAD Auth/Integrated/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/features/security/AAD Auth/Integrated/Integrated.csproj b/samples/features/security/AAD Auth/Integrated/Integrated.csproj new file mode 100644 index 00000000..ee7268ff --- /dev/null +++ b/samples/features/security/AAD Auth/Integrated/Integrated.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {0CA53E48-1686-4CFF-8D23-71AFCD999694} + Exe + Properties + Integrated + Integrated + v4.6 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/features/security/AAD Auth/Integrated/Program.cs b/samples/features/security/AAD Auth/Integrated/Program.cs new file mode 100644 index 00000000..3ee6525a --- /dev/null +++ b/samples/features/security/AAD Auth/Integrated/Program.cs @@ -0,0 +1,33 @@ +using System; +using System.Data; +using System.Data.SqlClient; + +class Program +{ + static void Main() + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); + builder["Data Source"] = "aad-managed-demo.database.windows.net"; // replace with your server name + builder["Initial Catalog"] = "demo"; // replace with your database name + builder["Authentication"] = SqlAuthenticationMethod.ActiveDirectoryIntegrated; + builder["Connect Timeout"] = 30; + + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) + { + try + { + connection.Open(); + using (SqlCommand cmd = new SqlCommand(@"SELECT SUSER_SNAME()", connection)) + { + Console.WriteLine("You have successfully logged on as: " + (string)cmd.ExecuteScalar()); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + Console.WriteLine("Please press any key to stop"); + Console.ReadKey(); + } +} diff --git a/samples/features/security/AAD Auth/Integrated/Properties/AssemblyInfo.cs b/samples/features/security/AAD Auth/Integrated/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..8c2f972d --- /dev/null +++ b/samples/features/security/AAD Auth/Integrated/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +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("Integrated")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Integrated")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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("0ca53e48-1686-4cff-8d23-71afcd999694")] + +// 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 Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/features/security/AAD Auth/Password/App.config b/samples/features/security/AAD Auth/Password/App.config new file mode 100644 index 00000000..2d2a12d8 --- /dev/null +++ b/samples/features/security/AAD Auth/Password/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/features/security/AAD Auth/Password/Password.csproj b/samples/features/security/AAD Auth/Password/Password.csproj new file mode 100644 index 00000000..704d4b03 --- /dev/null +++ b/samples/features/security/AAD Auth/Password/Password.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {C48C729A-8B2F-4A13-B609-1C25B400E781} + Exe + Properties + Password + Password + v4.6 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/features/security/AAD Auth/Password/Program.cs b/samples/features/security/AAD Auth/Password/Program.cs new file mode 100644 index 00000000..7aab24aa --- /dev/null +++ b/samples/features/security/AAD Auth/Password/Program.cs @@ -0,0 +1,72 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Security; + +class Program +{ + + static SqlCredential CreateCredential(String username) + { + // Prompt the user for a password and construct SqlCredential + SecureString password = new SecureString(); + Console.WriteLine("Enter password for " + username + ": "); + + ConsoleKeyInfo nextKey = Console.ReadKey(true); + + while (nextKey.Key != ConsoleKey.Enter) + { + if (nextKey.Key == ConsoleKey.Backspace) + { + if (password.Length > 0) + { + password.RemoveAt(password.Length - 1); + // erase the last * as well + Console.Write(nextKey.KeyChar); + Console.Write(" "); + Console.Write(nextKey.KeyChar); + } + } + else + { + password.AppendChar(nextKey.KeyChar); + Console.Write("*"); + } + nextKey = Console.ReadKey(true); + } + + Console.WriteLine(); + Console.WriteLine(); + password.MakeReadOnly(); + return new SqlCredential(username, password); + } + + static void Main() + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); + builder["Data Source"] = "aad-managed-demo.database.windows.net"; // replace with your server name + builder["Initial Catalog"] = "demo"; // replace with your database name + builder["Authentication"] = SqlAuthenticationMethod.ActiveDirectoryPassword; + builder["Connect Timeout"] = 30; + string username = "bob@cqclinic.onmicrosoft.com"; // replace with your username + + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) + { + try + { + connection.Credential = CreateCredential(username); + connection.Open(); + using (SqlCommand cmd = new SqlCommand(@"SELECT SUSER_SNAME()", connection)) + { + Console.WriteLine("You have successfully logged on as: " + (string)cmd.ExecuteScalar()); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + Console.WriteLine("Please press any key to stop"); + Console.ReadKey(); + } +} diff --git a/samples/features/security/AAD Auth/Password/Properties/AssemblyInfo.cs b/samples/features/security/AAD Auth/Password/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..44685254 --- /dev/null +++ b/samples/features/security/AAD Auth/Password/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +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("Password")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Password")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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("c48c729a-8b2f-4a13-b609-1c25b400e781")] + +// 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 Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]