Skip to content

Commit

Permalink
api_token adaptation
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryImMouse committed Aug 13, 2024
1 parent f31203d commit 8bcff95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Content.Server/_Jerry/CCCVars/CCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static class CCCVars
public static readonly CVarDef<string> DiscordApiUrl =
CVarDef.Create("jerry.discord_api_url", "http://127.0.0.1:2424/api", CVar.CONFIDENTIAL | CVar.SERVERONLY);

public static readonly CVarDef<string> DiscordApiKey =
CVarDef.Create("jerry.discord_api_key", "key", CVar.CONFIDENTIAL | CVar.SERVERONLY);

/*
* Sponsors
*/
Expand Down
5 changes: 3 additions & 2 deletions Content.Server/_Jerry/Discord/DiscordAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void PostInject()
public void Initialize()
{
_configuration.OnValueChanged(CCCVars.CCCVars.DiscordApiUrl, (value) => _apiUrl = value, true);
_configuration.OnValueChanged(CCCVars.CCCVars.DiscordApiKey, (value) => _apiKey = value, true);

_sawmill = Logger.GetSawmill("discord_auth");
_net.RegisterNetMessage<MsgDiscordAuthRequired>();
Expand Down Expand Up @@ -91,7 +92,7 @@ private async void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs
{
_sawmill.Debug($"Player {userId} check Discord verification");

var requestUrl = $"{_apiUrl}/check?userid={userId}";
var requestUrl = $"{_apiUrl}/check?userid={userId}&api_token={_apiKey}";
var response = await _httpClient.GetAsync(requestUrl, cancel);
if (!response.IsSuccessStatusCode)
return null;
Expand All @@ -102,7 +103,7 @@ private async void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs
public async Task<string> GenerateLink(NetUserId userId, CancellationToken cancel = default)
{
_sawmill.Debug($"Generating link for {userId}");
var requestUrl = $"{_apiUrl}/link?userid={userId}";
var requestUrl = $"{_apiUrl}/link?userid={userId}&api_token={_apiKey}";
var response = await _httpClient.GetAsync(requestUrl, cancel);
var link = await response.Content.ReadFromJsonAsync<DiscordLinkResponse>(cancel);
return link!.Link;
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/_Jerry/Sponsors/SponsorsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public sealed class SponsorsManager
private readonly HttpClient _httpClient = new();
private string _guildId = default!;
private string _apiUrl = default!;
private string _apiKey = default!;

private Dictionary<NetUserId, SponsorData> _cachedSponsors = new();

public void Initialize()
{
_configuration.OnValueChanged(CCCVars.CCCVars.DiscordGuildID, s => _guildId = s, true);
_configuration.OnValueChanged(CCCVars.CCCVars.DiscordApiUrl, s => _apiUrl = s, true);
_configuration.OnValueChanged(CCCVars.CCCVars.DiscordApiKey, (value) => _apiKey = value, true);

_discordAuthManager.PlayerVerified += OnPlayerVerified;
_netManager.Disconnect += OnDisconnect;
Expand Down Expand Up @@ -56,7 +58,7 @@ private async void OnPlayerVerified(object? sender, ICommonSession e)

private async Task<List<string>?> GetRoles(NetUserId userId)
{
var requestUrl = $"{_apiUrl}/roles?userid={userId}&guildid={_guildId}";
var requestUrl = $"{_apiUrl}/roles?userid={userId}&guildid={_guildId}&api_token={_apiKey}";
var response = await _httpClient.GetAsync(requestUrl);

if (!response.IsSuccessStatusCode)
Expand Down

0 comments on commit 8bcff95

Please sign in to comment.