From 98e1674011f541f2b6cb0964aacf538d976f66df Mon Sep 17 00:00:00 2001 From: Vadim A <30937329+Implx@users.noreply.github.com> Date: Tue, 25 May 2021 18:20:58 +0300 Subject: [PATCH] Fixed VK authorization (#1166) Co-authored-by: Vadim Anosov --- .../Authorization/ImplicitFlow/ImplicitFlow.cs | 16 ++++++++++++++++ VkNet/VkNet.csproj | 16 ++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs b/VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs index 25cd81b94..c18aa7aa1 100644 --- a/VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs +++ b/VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web; using JetBrains.Annotations; using Microsoft.Extensions.Logging; using VkNet.Abstractions.Authorization; @@ -106,6 +107,12 @@ public Uri CreateAuthorizeUrl() private async Task NextStepAsync(AuthorizationFormResult formResult) { + var responseUrl = formResult.ResponseUrl; + if (responseUrl.OriginalString.StartsWith("https://oauth.vk.com/auth_redirect")) + { + responseUrl = GetRedirectUrl(responseUrl); + } + var pageType = _vkAuthorization.GetPageType(formResult.ResponseUrl); switch (pageType) @@ -164,6 +171,15 @@ private async Task NextStepAsync(AuthorizationFormResult fo return await NextStepAsync(resultForm).ConfigureAwait(false); } + private static Uri GetRedirectUrl(Uri originalUrl) + { + var originalString = originalUrl.OriginalString; + var query = HttpUtility.ParseQueryString(originalString); + var escapedUrl = query["authorize_url"]; + var unEscapedUrl = Uri.UnescapeDataString(escapedUrl); + return new Uri(unEscapedUrl); + } + /// /// Валидация параметров авторизации /// diff --git a/VkNet/VkNet.csproj b/VkNet/VkNet.csproj index 55bc61342..b3b12b142 100644 --- a/VkNet/VkNet.csproj +++ b/VkNet/VkNet.csproj @@ -55,12 +55,12 @@ - - - - - - + + + + + + @@ -89,4 +89,8 @@ + + + + \ No newline at end of file