This reverts commit 93064541e4
.
pull/1806/head
@@ -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, new List<string> { "identify" }); //this can give you an exception if the token is expired! | |||||
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Code, code, navigationManager.BaseUri, 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, new List<string> { "identify" }); //this can give you an exception if the token is expired! | |||||
RestToken = await DiscordRestClient.GetTokenAsync(TokenType.Refresh, refreshToken, navigationManager.BaseUri, 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(); | ||||
@@ -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, IEnumerable<string> scopes, RequestOptions options) | |||||
public static async Task<RestToken> GetTokenAsync(BaseDiscordClient client, TokenType tokenType, string token, string redirectUrl, IEnumerable<string> scopes, RequestOptions options) | |||||
{ | { | ||||
var model = await client.ApiClient.GetTokenAsync(tokenType, token, scopes, options).ConfigureAwait(false); | |||||
var model = await client.ApiClient.GetTokenAsync(tokenType, token, redirectUrl, scopes, options).ConfigureAwait(false); | |||||
return RestToken.Create(client, model); | return RestToken.Create(client, model); | ||||
} | } | ||||
@@ -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, IEnumerable<string> scopes, RequestOptions options = null) | |||||
public async Task<Token> GetTokenAsync(TokenType tokenType, string token, string redirectUrl, 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,6 +335,7 @@ 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)) | ||||
}; | }; | ||||
@@ -350,6 +351,7 @@ 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)) | ||||
}; | }; | ||||
@@ -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, IEnumerable<string> scopes, RequestOptions options = null) | |||||
public async Task<RestToken> GetTokenAsync(TokenType tokenType, string token, string redirectUrl, IEnumerable<string> scopes, RequestOptions options = null) | |||||
{ | { | ||||
return await ClientHelper.GetTokenAsync(this, tokenType, token, scopes, options); | |||||
return await ClientHelper.GetTokenAsync(this, tokenType, token, redirectUrl, scopes, options); | |||||
} | } | ||||
public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null) | public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null) | ||||