Browse Source

removed unnecessary redirectUrl argument.

pull/1806/head
emorell96 4 years ago
parent
commit
93064541e4
4 changed files with 7 additions and 9 deletions
  1. +2
    -2
      samples/05_simple_blazor_discord_login/Pages/Index.razor.cs
  2. +2
    -2
      src/Discord.Net.Rest/ClientHelper.cs
  3. +1
    -3
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  4. +2
    -2
      src/Discord.Net.Rest/DiscordRestClient.cs

+ 2
- 2
samples/05_simple_blazor_discord_login/Pages/Index.razor.cs View File

@@ -39,14 +39,14 @@ namespace _05_simple_blazor_discord_login.Pages
} }
if (QueryHelpers.ParseQuery(uri.Query.TrimStart('?')).TryGetValue("code", out var code)) if (QueryHelpers.ParseQuery(uri.Query.TrimStart('?')).TryGetValue("code", out var code))
{ {
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Code, code, navigationManager.BaseUri, new List<string> { "identify" }); //this can give you an exception if the token is expired!
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Code, code, new List<string> { "identify" }); //this can give you an exception if the token is expired!
await DiscordRestClient.LoginAsync(TokenType.Bearer, RestToken.Token); await DiscordRestClient.LoginAsync(TokenType.Bearer, RestToken.Token);
User = DiscordRestClient.CurrentUser; User = DiscordRestClient.CurrentUser;
StateHasChanged(); StateHasChanged();
} }
if (QueryHelpers.ParseQuery(uri.Query.TrimStart('?')).TryGetValue("refresh_token", out var refreshToken)) if (QueryHelpers.ParseQuery(uri.Query.TrimStart('?')).TryGetValue("refresh_token", out var refreshToken))
{ {
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Refresh, refreshToken, navigationManager.BaseUri, new List<string> { "identify" }); //this can give you an exception if the token is expired!
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Refresh, refreshToken, new List<string> { "identify" }); //this can give you an exception if the token is expired!
await DiscordRestClient.LoginAsync(TokenType.Bearer, RestToken.Token); await DiscordRestClient.LoginAsync(TokenType.Bearer, RestToken.Token);
User = DiscordRestClient.CurrentUser; User = DiscordRestClient.CurrentUser;
StateHasChanged(); StateHasChanged();


+ 2
- 2
src/Discord.Net.Rest/ClientHelper.cs View File

@@ -16,9 +16,9 @@ namespace Discord.Rest
var model = await client.ApiClient.GetMyApplicationAsync(options).ConfigureAwait(false); var model = await client.ApiClient.GetMyApplicationAsync(options).ConfigureAwait(false);
return RestApplication.Create(client, model); return RestApplication.Create(client, model);
} }
public static async Task<RestToken> GetTokenAsync(BaseDiscordClient client, TokenType tokenType, string token, string redirectUrl, IEnumerable<string> scopes, RequestOptions options)
public static async Task<RestToken> GetTokenAsync(BaseDiscordClient client, TokenType tokenType, string token, IEnumerable<string> scopes, RequestOptions options)
{ {
var model = await client.ApiClient.GetTokenAsync(tokenType, token, redirectUrl, scopes, options).ConfigureAwait(false);
var model = await client.ApiClient.GetTokenAsync(tokenType, token, scopes, options).ConfigureAwait(false);
return RestToken.Create(client, model); return RestToken.Create(client, model);
} }




+ 1
- 3
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -318,7 +318,7 @@ namespace Discord.API
/// <param name="scopes">The scopes requested.</param> /// <param name="scopes">The scopes requested.</param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns>Returns <see cref="Token"/> with the information about the retrieved token.</returns> /// <returns>Returns <see cref="Token"/> with the information about the retrieved token.</returns>
public async Task<Token> GetTokenAsync(TokenType tokenType, string token, string redirectUrl, IEnumerable<string> scopes, RequestOptions options = null)
public async Task<Token> GetTokenAsync(TokenType tokenType, string token, IEnumerable<string> scopes, RequestOptions options = null)
{ {
Preconditions.NotNull(token, nameof(token)); Preconditions.NotNull(token, nameof(token));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);
@@ -335,7 +335,6 @@ namespace Discord.API
new KeyValuePair<string, string>("client_secret", ClientSecret), new KeyValuePair<string, string>("client_secret", ClientSecret),
new KeyValuePair<string, string>("grant_type", "authorization_code"), new KeyValuePair<string, string>("grant_type", "authorization_code"),
new KeyValuePair<string, string>("code", token), new KeyValuePair<string, string>("code", token),
new KeyValuePair<string, string>("redirect_uri", redirectUrl),
new KeyValuePair<string, string>("scope", string.Join(" ", scopes)) new KeyValuePair<string, string>("scope", string.Join(" ", scopes))
}; };


@@ -351,7 +350,6 @@ namespace Discord.API
new KeyValuePair<string, string>("client_secret", ClientSecret), new KeyValuePair<string, string>("client_secret", ClientSecret),
new KeyValuePair<string, string>("grant_type", "refresh_token"), new KeyValuePair<string, string>("grant_type", "refresh_token"),
new KeyValuePair<string, string>("refresh_token", token), new KeyValuePair<string, string>("refresh_token", token),
new KeyValuePair<string, string>("redirect_uri", redirectUrl),
new KeyValuePair<string, string>("scope", string.Join(" ", scopes)) new KeyValuePair<string, string>("scope", string.Join(" ", scopes))
}; };




+ 2
- 2
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -62,9 +62,9 @@ namespace Discord.Rest
{ {
return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false)); return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false));
} }
public async Task<RestToken> GetTokenAsync(TokenType tokenType, string token, string redirectUrl, IEnumerable<string> scopes, RequestOptions options = null)
public async Task<RestToken> GetTokenAsync(TokenType tokenType, string token, IEnumerable<string> scopes, RequestOptions options = null)
{ {
return await ClientHelper.GetTokenAsync(this, tokenType, token, redirectUrl, scopes, options);
return await ClientHelper.GetTokenAsync(this, tokenType, token, scopes, options);
} }


public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null) public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null)


Loading…
Cancel
Save