Skip to content

Commit

Permalink
Fixed VK authorization (#1166)
Browse files Browse the repository at this point in the history
Co-authored-by: Vadim  Anosov <code@laserwar.com>
  • Loading branch information
Implx and Vadim Anosov authored May 25, 2021
1 parent 84ccc55 commit 98e1674
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 16 additions & 0 deletions VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,12 @@ public Uri CreateAuthorizeUrl()

private async Task<AuthorizationResult> 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)
Expand Down Expand Up @@ -164,6 +171,15 @@ private async Task<AuthorizationResult> 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);
}

/// <summary>
/// Валидация параметров авторизации
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions VkNet/VkNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="all"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.33"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" PrivateAssets="all"/>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.22.0.31243" PrivateAssets="all"/>
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="all"/>
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="all" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.33" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.22.0.31243" PrivateAssets="all" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net461'">
Expand Down Expand Up @@ -89,4 +89,8 @@
<None Include="..\tools\vknet-icon.PNG" Pack="true" PackagePath="\" />
<None Include="..\LICENCE" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Web" />
</ItemGroup>
</Project>

0 comments on commit 98e1674

Please sign in to comment.