-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from eclipserporg/feature/add_fake_server
Restructure project, implement fake server
- Loading branch information
Showing
34 changed files
with
362 additions
and
67 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
Apis/IServerDiscordApi.cs → DiscordBot.App/Apis/IServerDiscordApi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Commands/GeneralCommands.cs → DiscordBot.App/Commands/GeneralCommands.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Commands/RestartCommands.cs → DiscordBot.App/Commands/RestartCommands.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Controllers/DiscordController.cs → ...dBot.App/Controllers/DiscordController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Controllers/FeedsController.cs → ...ordBot.App/Controllers/FeedsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Controllers/PresenceController.cs → ...Bot.App/Controllers/PresenceController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
Middlewares/BasicAuthenticationHandler.cs → ...Middlewares/BasicAuthenticationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Services/DiscordService.cs → DiscordBot.App/Services/DiscordService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Services/GuildJoinService.cs → DiscordBot.App/Services/GuildJoinService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Services/LoginService.cs → DiscordBot.App/Services/LoginService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Services/RunnerService.cs → DiscordBot.App/Services/RunnerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Settings/DiscordSettings.cs → DiscordBot.App/Settings/DiscordSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace app.Settings; | ||
namespace DiscordBot.Settings; | ||
|
||
public class Roles | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
Settings/ServerApiSettings.cs → DiscordBot.App/Settings/ServerApiSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace app.Settings; | ||
namespace DiscordBot.Settings; | ||
|
||
public class ServerApiSettings | ||
{ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace app.Models; | ||
namespace DiscordBot.Models; | ||
|
||
public class Credentials | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
Models/DiscordUserDto.cs → DiscordBot.Data/Models/DiscordUserDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace app.Models; | ||
namespace DiscordBot.Models; | ||
|
||
public class DiscordUserDto | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
Models/ResponsePairDto.cs → DiscordBot.Data/Models/ResponsePairDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace app.Models; | ||
namespace DiscordBot.Models; | ||
|
||
public class ResponsePairDto | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using DiscordBot.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace DiscordBot.FakeServer.Controllers; | ||
|
||
[ApiController] | ||
[Authorize] | ||
[Route("[action]")] | ||
public class ServerController : ControllerBase | ||
{ | ||
[HttpPost("/remove-read-only")] | ||
public bool PostRemoveReadOnly(string channel, ulong senderId, string senderName, ulong targetId, string targetName) | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpPost("/read-only")] | ||
public bool PostReadOnly(string channel, ulong senderId, string senderName, ulong targetId, string targetName, string reason) | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpGet("/apps")] | ||
public string GetApps() | ||
{ | ||
return "Currently no apps..."; | ||
} | ||
|
||
[HttpGet("/account-status")] | ||
public string GetAccountStatus(ulong id) | ||
{ | ||
return "[]"; | ||
} | ||
|
||
[HttpPost("/announce")] | ||
public void PostAnnouncement(string text) | ||
{ | ||
} | ||
|
||
[HttpPost("/save")] | ||
public bool PostSave() | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpGet("/ping")] | ||
public bool GetPing() | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpPost("/kick")] | ||
public bool PostKick(string channel, ulong senderId, string senderName, ulong targetId, string targetName, string reason) | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpPost("/ban")] | ||
public bool PostBan(string channel, ulong senderId, string senderName, ulong targetId, string targetName, string reason) | ||
{ | ||
return true; | ||
} | ||
|
||
[HttpPost("/login")] | ||
public ResponsePairDto PostLogin(string name, ulong id, string username, string discriminator, string avatarurl, string password) | ||
{ | ||
return new ResponsePairDto() | ||
{ | ||
Message = "Success", | ||
Status = true | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.13" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DiscordBot.Data\DiscordBot.Data.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
51 changes: 51 additions & 0 deletions
51
DiscordBot.FakeServer/Middlewares/BasicAuthenticationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using DiscordBot.Models; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.Extensions.Options; | ||
using System.Security.Claims; | ||
using System.Text; | ||
using System.Text.Encodings.Web; | ||
|
||
namespace DiscordBot.Middlewares; | ||
|
||
public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions> | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly Credentials _credentials; | ||
|
||
public BasicAuthenticationHandler( | ||
IOptionsMonitor<AuthenticationSchemeOptions> options, | ||
ILoggerFactory logger, | ||
UrlEncoder encoder, | ||
ISystemClock clock, | ||
IOptions<Credentials> credentials, | ||
IConfiguration configuration) : base(options, logger, encoder, clock) | ||
{ | ||
_configuration = configuration; | ||
_credentials = credentials.Value; | ||
} | ||
|
||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync() | ||
Check warning on line 27 in DiscordBot.FakeServer/Middlewares/BasicAuthenticationHandler.cs GitHub Actions / build
|
||
{ | ||
string authHeader = Request.Headers["Authorization"]; | ||
if (authHeader != null && authHeader.StartsWith("Basic", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
|
||
var authHeaderValue = authHeader.Replace("Basic ", "", StringComparison.InvariantCultureIgnoreCase); | ||
var decodedAuthHeaderValue = Encoding.UTF8.GetString(Convert.FromBase64String(authHeaderValue)); | ||
var userPassArray = decodedAuthHeaderValue.Split(":"); | ||
var extractedUsername = userPassArray[0]; | ||
var extractedPassword = userPassArray[1]; | ||
|
||
if (string.Equals(_credentials.Username, extractedUsername) && string.Equals(extractedPassword, _credentials.Password)) | ||
{ | ||
var claims = new[] { new Claim(ClaimTypes.Name, _credentials.Username) }; | ||
var identity = new ClaimsIdentity(claims, Scheme.Name); | ||
var principal = new ClaimsPrincipal(identity); | ||
var ticket = new AuthenticationTicket(principal, Scheme.Name); | ||
|
||
return AuthenticateResult.Success(ticket); | ||
} | ||
} | ||
return AuthenticateResult.Fail("Failed to authenticate"); | ||
} | ||
} |
Oops, something went wrong.