mirror of
https://github.com/yawaflua/Discord.Net.git
synced 2025-12-09 03:49:36 +02:00
Remove state
This commit is contained in:
@@ -21,7 +21,6 @@ public class DiscordOAuth
|
||||
private ScopesBuilder Scopes { get; set; }
|
||||
|
||||
private string? AccessToken { get; set; }
|
||||
public string State { get; }
|
||||
|
||||
public static void Configure(ulong clientId, string clientSecret, string? botToken = null)
|
||||
{
|
||||
@@ -32,22 +31,21 @@ public class DiscordOAuth
|
||||
|
||||
private readonly HttpClient _httpClient = new HttpClient();
|
||||
|
||||
public DiscordOAuth(string redirectUri, ScopesBuilder scopes, string state, bool prompt = true)
|
||||
public DiscordOAuth(string redirectUri, ScopesBuilder scopes, bool prompt = true)
|
||||
{
|
||||
RedirectUri = redirectUri;
|
||||
Scopes = scopes;
|
||||
Prompt = prompt;
|
||||
State = state;
|
||||
}
|
||||
|
||||
public string GetAuthorizationUrl()
|
||||
public string GetAuthorizationUrl(string state)
|
||||
{
|
||||
NameValueCollection query = HttpUtility.ParseQueryString(string.Empty);
|
||||
query["client_id"] = ClientId.ToString();
|
||||
query["redirect_uri"] = RedirectUri;
|
||||
query["response_type"] = "code";
|
||||
query["scope"] = Scopes.ToString();
|
||||
query["state"] = State;
|
||||
query["state"] = state;
|
||||
query["prompt"] = Prompt ? "consent" : "none";
|
||||
|
||||
var uriBuilder = new UriBuilder("https://discord.com/api/oauth2/authorize")
|
||||
@@ -96,12 +94,6 @@ public class DiscordOAuth
|
||||
return authToken;
|
||||
}
|
||||
|
||||
public bool ValidateState(HttpContext context)
|
||||
{
|
||||
var givenState = context.Request.Query["state"];
|
||||
return givenState == State;
|
||||
}
|
||||
|
||||
private async Task<T?> GetInformationAsync<T>(string accessToken, string endpoint) where T : class
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<RepositoryType>GIT</RepositoryType>
|
||||
<PackageTags>Discord-OAuth2;Discord-OAuth-2;Discord-OAuth;DiscordOAuth;Discord;OAuth;OAuth-2;OAuth2</PackageTags>
|
||||
<Deterministic>true</Deterministic>
|
||||
<Version>1.0.3</Version>
|
||||
<Version>1.0.4</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user