-
Notifications
You must be signed in to change notification settings - Fork 1
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 #7 from EpicOfficer/FEATURE/Wordle
Rework discord activity token handling in API and frontend (actually works now)
- Loading branch information
Showing
19 changed files
with
120 additions
and
258 deletions.
There are no files selected for viewing
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
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,19 @@ | ||
using Blink3.API.Models; | ||
|
||
namespace Blink3.API.Interfaces; | ||
|
||
/// <summary> | ||
/// Represents the interface for handling Discord token operations. | ||
/// </summary> | ||
public interface IDiscordTokenService | ||
{ | ||
/// <summary> | ||
/// Retrieves a Discord access token asynchronously. | ||
/// </summary> | ||
/// <param name="code">The authorization code received from Discord.</param> | ||
/// <returns> | ||
/// A task that represents the asynchronous operation. The task result contains a | ||
/// <see cref="DiscordTokenResponse" /> object representing the Discord access token information. | ||
/// </returns> | ||
Task<DiscordTokenResponse> GetTokenAsync(string code); | ||
} |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Blink3.API.Models; | ||
|
||
public class DiscordTokenResponse | ||
{ | ||
[JsonPropertyName("token_type")] | ||
public string? TokenType { get; set; } | ||
|
||
[JsonPropertyName("access_token")] | ||
public string? AccessToken { get; set; } | ||
|
||
[JsonPropertyName("expires_in")] | ||
public int ExpiresIn { get; set; } | ||
|
||
[JsonPropertyName("refresh_token")] | ||
public string? RefreshToken { get; set; } | ||
|
||
[JsonPropertyName("scope")] | ||
public string? Scope { get; set; } | ||
} |
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,36 @@ | ||
using System.Net.Http.Headers; | ||
using AspNet.Security.OAuth.Discord; | ||
using Blink3.API.Interfaces; | ||
using Blink3.API.Models; | ||
using Blink3.Core.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Blink3.API.Services; | ||
|
||
public class DiscordTokenService( | ||
IHttpClientFactory httpClientFactory, | ||
IOptions<BlinkConfiguration> config) : IDiscordTokenService | ||
{ | ||
private BlinkConfiguration Config => config.Value; | ||
|
||
public async Task<DiscordTokenResponse> GetTokenAsync(string code) | ||
{ | ||
using HttpClient httpClient = httpClientFactory.CreateClient(); | ||
FormUrlEncodedContent requestBody = new(new[] | ||
{ | ||
new KeyValuePair<string, string>("client_id", Config.Discord.ClientId), | ||
new KeyValuePair<string, string>("client_secret", Config.Discord.ClientSecret), | ||
new KeyValuePair<string, string>("grant_type", "authorization_code"), | ||
new KeyValuePair<string, string>("code", code) | ||
}); | ||
|
||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
|
||
HttpResponseMessage response = | ||
await httpClient.PostAsync(DiscordAuthenticationDefaults.TokenEndpoint, requestBody); | ||
if (!response.IsSuccessStatusCode) | ||
throw new ApplicationException("Error retrieving access token from Discord."); | ||
|
||
return await response.Content.ReadFromJsonAsync<DiscordTokenResponse>() ?? new DiscordTokenResponse(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.