Skip to content

Commit

Permalink
ImplicitFlow: использовать новое апи для построения Url
Browse files Browse the repository at this point in the history
  • Loading branch information
itsokto committed May 23, 2020
1 parent e9ff5fd commit 1e687bf
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions VkNet/Infrastructure/Authorization/ImplicitFlow/ImplicitFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
using VkNet.Enums;
using VkNet.Enums.SafetyEnums;
using VkNet.Exception;
using VkNet.Infrastructure.Authorization;
using VkNet.Infrastructure.Authorization.ImplicitFlow;
using VkNet.Model;
using VkNet.Utils;

namespace VkNet.Infrastructure.Authorization.ImplicitFlow
{
Expand Down Expand Up @@ -56,10 +55,7 @@ public async Task<AuthorizationResult> AuthorizeAsync()

_logger?.LogDebug("Шаг 1. Открытие диалога авторизации");

var authorizeUrlResult = CreateAuthorizeUrl(_authorizationParameters.ApplicationId,
_authorizationParameters.Settings.ToUInt64(),
Display.Mobile,
"123435");
var authorizeUrlResult = CreateAuthorizeUrl();

var loginFormResult = await _authorizationFormsFactory.Create(ImplicitFlowPageType.LoginPassword)
.ExecuteAsync(authorizeUrlResult, _authorizationParameters)
Expand Down Expand Up @@ -95,20 +91,18 @@ public Uri CreateAuthorizeUrl()
var vkAuthParams = new VkParameters
{
{ "client_id", _authorizationParameters.ApplicationId },
{ "redirect_uri", _authorizationParameters.RedirectUri },
{ "display", _authorizationParameters.Display },
{ "scope", _authorizationParameters.Settings },
{ "redirect_uri", _authorizationParameters.RedirectUri != null ? _authorizationParameters.RedirectUri.ToString() : Constants.DefaultRedirectUri },
{ "display", Display.Mobile },
{ "scope", _authorizationParameters.Settings.ToUInt64() },
{ "response_type", ResponseType.Token },
{ "v", _versionManager.Version },
{ "state", _authorizationParameters.State },
{ "revoke", _authorizationParameters.Revoke }
};

var query = vkAuthParams.Select(x => $"{x.Key}={x.Value}");
var stringQuery = string.Join("&",query);
var result = $"{url}{stringQuery}";
var resultUrl = Url.Combine(url, Url.QueryFrom(vkAuthParams.ToArray()));

return new Uri(result);
return new Uri(resultUrl);
}

private async Task<AuthorizationResult> NextStepAsync(AuthorizationFormResult formResult)
Expand Down Expand Up @@ -198,11 +192,6 @@ private void ValidateAuthorizationParameters()
{
errorsBuilder.AppendLine($"{nameof(_authorizationParameters.Password)} обязательный параметр");
}

if (_authorizationParameters.RedirectUri == null)
{
errorsBuilder.AppendLine($"{nameof(_authorizationParameters.RedirectUri)} обязательный параметр");
}
}

var errors = errorsBuilder.ToString();
Expand Down

0 comments on commit 1e687bf

Please sign in to comment.