diff --git a/example/SeqEnableAAD/Program.cs b/example/SeqEnableAAD/Program.cs new file mode 100644 index 0000000..259a6e1 --- /dev/null +++ b/example/SeqEnableAAD/Program.cs @@ -0,0 +1,91 @@ +using System; +using System.Threading.Tasks; +using DocoptNet; +using Seq.Api; +using Seq.Api.Model.Settings; + +namespace SeqEnableAAD +{ + class Program + { + const string Usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only). + +Usage: + seq-enable-aad.exe --uname= --tenantid= --clientid= --clientkey= [--authority=] + seq-enable-aad.exe (-h | --help) + +Options: + -h --help Show this screen. + --uname= Username. Azure Active Directory usernames must take the form of an email address. + --tenantid= Tenant ID. + --clientid= Client ID. + --clientkey= Client key. + --authority= Authority (optional, defaults to 'login.windows.net'). + "; + static void Main(string[] args) + { + Task.Run(async () => + { + try + { + var arguments = new Docopt().Apply(Usage, args, version: "Seq Enable AAD 0.1", exit: true); + + var server = arguments[""].ToString(); + var username = Normalize(arguments["--uname"]); + var tenantId = Normalize(arguments["--tenantid"]); + var clientId = Normalize(arguments["--clientid"]); + var clientKey = Normalize(arguments["--clientkey"]); + var authority = Normalize(arguments["--authority"]); + + await Run(server, username, tenantId, clientId, clientKey, authority); + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Red; + Console.WriteLine("seq-enable-aad: {0}", ex); + Console.ResetColor(); + Environment.Exit(-1); + } + }).Wait(); + } + + static string Normalize(ValueObject v) + { + if (v == null) return null; + var s = v.ToString(); + return string.IsNullOrWhiteSpace(s) ? null : s; + } + + static async Task Run(string server, string username, string tenantId, string clientId, string clientKey, string authority="login.windows.net") + { + var connection = new SeqConnection(server); + + var user = await connection.Users.FindCurrentAsync(); + var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider); + var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId); + var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey); + var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority); + var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId); + + user.Username = username; + provider.Value = "Azure Active Directory"; + cid.Value = clientId; + ckey.Value = clientKey; + tid.Value = tenantId; + aut.Value = authority; + + await connection.Users.UpdateAsync(user); + await connection.Settings.UpdateAsync(cid); + await connection.Settings.UpdateAsync(ckey); + await connection.Settings.UpdateAsync(tid); + await connection.Settings.UpdateAsync(aut); + + await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings + + var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled); + iae.Value = true; + await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out + } + } +} diff --git a/example/SeqEnableAAD/README.md b/example/SeqEnableAAD/README.md new file mode 100644 index 0000000..14c67af --- /dev/null +++ b/example/SeqEnableAAD/README.md @@ -0,0 +1,34 @@ +# Seq Enable AAD (Azure Active Directory) + +Be sure to read the [Seq Azure Active Directory documentation](https://docs.datalust.co/docs/azure-active-directory) to find the manual AAD setup instructions. + +## Example usage: + +``` +seq-enable-aad.exe https://seq.example.com --uname=example@microsoft.com --clientid=xxxxxx --tenantid=xxxxxx --clientkey=xxxxxx --authority=login.windows.net +``` + +### **Important note:** + +#### Windows + +Don't forget to set the "canonical URI" which Seq uses as a reply address for AAD. + +``` +seq config -k api.canonicalUri -v https://seq.example.com +seq service restart +``` + +#### Linux / Docker + +Don't forget to include the BASE_URI which Seq uses as a reply address for AAD. + +``` +docker run -d \ + --restart unless-stopped \ + --name seq \ + -p 5341:80 \ + -e ACCEPT_EULA=Y \ + -e BASE_URI=https://seq.example.com \ + datalust/seq:latest +``` \ No newline at end of file diff --git a/example/SeqEnableAAD/SeqEnableAAD.csproj b/example/SeqEnableAAD/SeqEnableAAD.csproj new file mode 100644 index 0000000..499ae03 --- /dev/null +++ b/example/SeqEnableAAD/SeqEnableAAD.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp3.1 + SeqEnableAuth + + + + + + + + + + + diff --git a/seq-api.sln b/seq-api.sln index 0c8feca..8fda661 100644 --- a/seq-api.sln +++ b/seq-api.sln @@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeqTail", "example\SeqTail\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalCopy", "example\SignalCopy\SignalCopy.csproj", "{E8CDDE17-8E29-4EB4-A4BB-38BCE346A752}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeqEnableAAD", "example\SeqEnableAAD\SeqEnableAAD.csproj", "{035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -53,6 +55,10 @@ Global {E8CDDE17-8E29-4EB4-A4BB-38BCE346A752}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8CDDE17-8E29-4EB4-A4BB-38BCE346A752}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8CDDE17-8E29-4EB4-A4BB-38BCE346A752}.Release|Any CPU.Build.0 = Release|Any CPU + {035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -63,6 +69,7 @@ Global {34BBD428-8297-484E-B771-0B72C172C264} = {1C66E116-DC21-4C8F-833E-A4C2DDF58487} {42CEBFBA-208F-40F1-AC95-13F05F6D5412} = {1C66E116-DC21-4C8F-833E-A4C2DDF58487} {E8CDDE17-8E29-4EB4-A4BB-38BCE346A752} = {1C66E116-DC21-4C8F-833E-A4C2DDF58487} + {035B62FC-CAD7-4DF9-A2A3-FAAA64DF3B55} = {1C66E116-DC21-4C8F-833E-A4C2DDF58487} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {20BAB483-FB94-4373-8E4C-0F846B6DBFFC} diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 65a1226..0de28ea 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -8,7 +8,7 @@ true seq Copyright © Datalust Pty Ltd and Contributors - https://datalust.co/images/seq-nuget.png + seq-api-icon.png https://github.com/datalust/seq-api Apache-2.0 8 @@ -16,5 +16,6 @@ + diff --git a/src/Seq.Api/seq-api-icon.png b/src/Seq.Api/seq-api-icon.png new file mode 100644 index 0000000..ed37092 Binary files /dev/null and b/src/Seq.Api/seq-api-icon.png differ