aboutsummaryrefslogtreecommitdiff
path: root/VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-12-15 01:41:41 -0500
committerLibravatar vman <public@vaughnnugent.com>2022-12-15 01:41:41 -0500
commita5ad943584e91bfbd953dc373a7a313367c7e0ae (patch)
tree5d5c63f6c04e3e87dec3b8fec3662d39b7b954d0 /VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs
parentf13193aa928f099c8152653570d2839b46b8f1ee (diff)
Mfa/login fixes
Diffstat (limited to 'VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs')
-rw-r--r--VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs30
1 files changed, 18 insertions, 12 deletions
diff --git a/VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs b/VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs
index 6ee7683..d8b2394 100644
--- a/VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs
+++ b/VNLib.Plugins.Essentials.SocialOauth/Endpoints/DiscordOauth.cs
@@ -39,7 +39,6 @@ using VNLib.Plugins.Essentials.Accounts;
using VNLib.Plugins.Extensions.Loading;
using VNLib.Plugins.Extensions.Loading.Users;
-#nullable enable
namespace VNLib.Plugins.Essentials.SocialOauth.Endpoints
{
@@ -50,26 +49,33 @@ namespace VNLib.Plugins.Essentials.SocialOauth.Endpoints
public DiscordOauth(PluginBase plugin, IReadOnlyDictionary<string, JsonElement> config) : base()
{
- //Get id/secret
- Task<string?> secret = plugin.TryGetSecretAsync("discord_client_secret");
- Task<string?> clientId = plugin.TryGetSecretAsync("discord_client_id");
-
- //Wait sync
- Task.WaitAll(secret, clientId);
-
Config = new("discord", config)
{
- //get gh client secret and id
- ClientID = clientId.Result ?? throw new KeyNotFoundException("Missing Discord client id from config or vault"),
- ClientSecret = secret.Result ?? throw new KeyNotFoundException("Missing the Discord client secret from config or vault"),
-
Passwords = plugin.GetPasswords(),
Users = plugin.GetUserManager(),
};
InitPathAndLog(Config.EndpointPath, plugin.Log);
+
+ //Load secrets
+ _ = plugin.DeferTask(async () =>
+ {
+ //Get id/secret
+ Task<SecretResult?> clientIdTask = plugin.TryGetSecretAsync("discord_client_id");
+ Task<SecretResult?> secretTask = plugin.TryGetSecretAsync("discord_client_secret");
+
+ await Task.WhenAll(secretTask, clientIdTask);
+
+ using SecretResult? secret = await secretTask;
+ using SecretResult? clientId = await clientIdTask;
+
+ Config.ClientID = clientId?.Result.ToString() ?? throw new KeyNotFoundException("Missing Discord client id from config or vault");
+ Config.ClientSecret = secret?.Result.ToString() ?? throw new KeyNotFoundException("Missing the Discord client secret from config or vault");
+
+ }, 100);
}
+
private static string GetUserIdFromPlatform(string userName)
{
return ManagedHash.ComputeHash($"discord|{userName}", HashAlg.SHA1, HashEncodingMode.Hexadecimal);