Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions example/SeqEnableAAD/Program.cs
Original file line number Diff line number Diff line change
@@ -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 <server> --uname=<un> --tenantid=<tid> --clientid=<cid> --clientkey=<ckey> [--authority=<a>]
seq-enable-aad.exe (-h | --help)

Options:
-h --help Show this screen.
--uname=<un> Username. Azure Active Directory usernames must take the form of an email address.
--tenantid=<tid> Tenant ID.
--clientid=<cid> Client ID.
--clientkey=<ckey> Client key.
--authority=<a> 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["<server>"].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
}
}
}
34 changes: 34 additions & 0 deletions example/SeqEnableAAD/README.md
Original file line number Diff line number Diff line change
@@ -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
```
17 changes: 17 additions & 0 deletions example/SeqEnableAAD/SeqEnableAAD.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>SeqEnableAuth</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="docopt.net" Version="0.6.1.9" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Seq.Api\Seq.Api.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions seq-api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion src/Seq.Api/Seq.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>seq</PackageTags>
<Copyright>Copyright © Datalust Pty Ltd and Contributors</Copyright>
<PackageIconUrl>https://datalust.co/images/seq-nuget.png</PackageIconUrl>
<PackageIcon>seq-api-icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/datalust/seq-api</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Tavis.UriTemplates" Version="1.1.1" />
<None Include="seq-api-icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
Binary file added src/Seq.Api/seq-api-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.