feat(auth): initial auth added part 2, refs NOISSUE
This commit is contained in:
parent
92828a90e2
commit
6b9c383697
@ -3,6 +3,9 @@ WORKDIR /App
|
||||
|
||||
# Copy everything
|
||||
COPY . ./
|
||||
|
||||
RUN apt upgrade && apt install libldap -y
|
||||
|
||||
# Restore as distinct layers
|
||||
RUN dotnet restore ./song_of_the_day/song_of_the_day.csproj
|
||||
# Build and publish a release
|
||||
|
@ -2,6 +2,9 @@
|
||||
using Scalar.AspNetCore;
|
||||
using Microsoft.AspNetCore.OpenApi;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using System.DirectoryServices.Protocols;
|
||||
|
||||
SignalIntegration.Instance = new SignalIntegration(AppConfiguration.Instance.SignalAPIEndpointUri,
|
||||
int.Parse(AppConfiguration.Instance.SignalAPIEndpointPort),
|
||||
@ -44,7 +47,7 @@ userCheckTimer.OnOccurence += async (s, ea) =>
|
||||
}
|
||||
await dci.DisposeAsync();
|
||||
};
|
||||
userCheckTimer.Start();
|
||||
//userCheckTimer.Start();
|
||||
|
||||
Console.WriteLine("Setting up user intro timer");
|
||||
var userIntroTimer = new CronTimer("*/1 * * * *", "Europe/Vienna", includingSeconds: false);
|
||||
@ -66,7 +69,7 @@ userIntroTimer.OnOccurence += async (s, ea) =>
|
||||
}
|
||||
await dci.DisposeAsync();
|
||||
};
|
||||
userIntroTimer.Start();
|
||||
//userIntroTimer.Start();
|
||||
|
||||
|
||||
Console.WriteLine("Setting up pick of the day timer");
|
||||
@ -82,7 +85,84 @@ pickOfTheDayTimer.OnOccurence += async (s, ea) =>
|
||||
SignalIntegration.Instance.SendMessageToUserAsync($"Today's (optional) suggestion helper to help you pick a song is:\n\n**{suggestion.Title}**\n\n*{suggestion.Description}*", luckyUser.SignalMemberId);
|
||||
SignalIntegration.Instance.SendMessageToUserAsync($"For now please just share your suggestion with the group - in the future I might ask you to share directly with me or via the website to help me keep track of past suggestions!", luckyUser.SignalMemberId);
|
||||
};
|
||||
pickOfTheDayTimer.Start();
|
||||
//pickOfTheDayTimer.Start();
|
||||
|
||||
var connection = new LdapConnection(AppConfiguration.Instance.LDAPConfig.LDAPserver)
|
||||
{
|
||||
Credential = new(
|
||||
AppConfiguration.Instance.LDAPConfig.Username,
|
||||
AppConfiguration.Instance.LDAPConfig.Password
|
||||
)
|
||||
};
|
||||
|
||||
var attributesToQuery = new string[]
|
||||
{
|
||||
"objectGUID",
|
||||
"sAMAccountName",
|
||||
"displayName",
|
||||
"mail",
|
||||
"whenCreated"
|
||||
};
|
||||
|
||||
SearchResponse SearchInAD(
|
||||
string ldapServer,
|
||||
int ldapPort,
|
||||
string domainForAD,
|
||||
string username,
|
||||
string password,
|
||||
string targetOU,
|
||||
string query,
|
||||
SearchScope scope,
|
||||
params string[] attributeList
|
||||
)
|
||||
{
|
||||
// on Windows the authentication type is Negotiate, so there is no need to prepend
|
||||
// AD user login with domain. On other platforms at the moment only
|
||||
// Basic authentication is supported
|
||||
var authType = AuthType.Basic;
|
||||
|
||||
//var connection = new LdapConnection(ldapServer)
|
||||
var connection = new LdapConnection(
|
||||
new LdapDirectoryIdentifier(ldapServer, ldapPort)
|
||||
)
|
||||
{
|
||||
AuthType = authType,
|
||||
Credential = new(username, password)
|
||||
};
|
||||
// the default one is v2 (at least in that version), and it is unknown if v3
|
||||
// is actually needed, but at least Synology LDAP works only with v3,
|
||||
// and since our Exchange doesn't complain, let it be v3
|
||||
connection.SessionOptions.ProtocolVersion = 3;
|
||||
|
||||
// this is for connecting via LDAPS (636 port). It should be working,
|
||||
// according to https://github.com/dotnet/runtime/issues/43890,
|
||||
// but it doesn't (at least with Synology DSM LDAP), although perhaps
|
||||
// for a different reason
|
||||
//connection.SessionOptions.SecureSocketLayer = true;
|
||||
|
||||
connection.Bind();
|
||||
|
||||
var request = new SearchRequest(targetOU, query, scope, attributeList);
|
||||
|
||||
return (SearchResponse)connection.SendRequest(request);
|
||||
}
|
||||
|
||||
var searchResults = SearchInAD(
|
||||
AppConfiguration.Instance.LDAPConfig.LDAPserver,
|
||||
AppConfiguration.Instance.LDAPConfig.Port,
|
||||
AppConfiguration.Instance.LDAPConfig.Username,
|
||||
AppConfiguration.Instance.LDAPConfig.Password,
|
||||
AppConfiguration.Instance.LDAPConfig.LDAPQueryBase,
|
||||
new StringBuilder("(&")
|
||||
.Append("(objectCategory=person)")
|
||||
.Append("(objectClass=user)")
|
||||
.Append($"(memberOf={_configurationAD.Crew})")
|
||||
.Append("(!(userAccountControl:1.2.840.113556.1.4.803:=2))")
|
||||
.Append(")")
|
||||
.ToString(),
|
||||
SearchScope.Subtree,
|
||||
attributesToQuery
|
||||
);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
|
Loading…
x
Reference in New Issue
Block a user