/// <inheritdoc /> public void Authorize(IApiAuthParams @params) { // подключение браузера через прокси if (@params.Host != null) { _logger?.Debug(message: "Настройка прокси"); Browser.Proxy = WebProxy.GetProxy(host: @params.Host, port: @params.Port, proxyLogin: @params.ProxyLogin, proxyPassword: @params.ProxyPassword); RestClient.Proxy = Browser.Proxy; } // если токен не задан - обычная авторизация if (@params.AccessToken == null) { AuthorizeWithAntiCaptcha(authParams: @params); // Сбросить после использования @params.CaptchaSid = null; @params.CaptchaKey = ""; } // если токен задан - авторизация с помощью токена полученного извне else { TokenAuth(accessToken: @params.AccessToken, userId: @params.UserId, expireTime: @params.TokenExpireTime); } _ap = @params; _logger?.Debug(message: "Авторизация прошла успешно"); }
public async Task <VkAuthorization> AuthorizeAsync(IApiAuthParams authParams) { _logger?.Debug(message: "Шаг 1. Открытие диалога авторизации"); var authorizeUrlResult = await OpenAuthDialogAsync(appId : authParams.ApplicationId, settings : authParams.Settings) .ConfigureAwait(false); if (IsAuthSuccessfull(webCallResult: authorizeUrlResult)) { return(await EndAuthorizeAsync(result : authorizeUrlResult, webProxy : Proxy).ConfigureAwait(false)); } _logger?.Debug(message: "Шаг 2. Заполнение формы логина"); var loginFormPostResult = await FilledLoginFormAsync(email : authParams.Login, password : authParams.Password, captchaSid : authParams.CaptchaSid, captchaKey : authParams.CaptchaKey, authorizeUrlResult : authorizeUrlResult) .ConfigureAwait(false); if (IsAuthSuccessfull(webCallResult: loginFormPostResult)) { return(await EndAuthorizeAsync(result : loginFormPostResult, webProxy : Proxy).ConfigureAwait(false)); } if (HasNotTwoFactor(code: authParams.TwoFactorAuthorization, loginFormPostResult: loginFormPostResult)) { return(await EndAuthorizeAsync(result : loginFormPostResult, webProxy : Proxy).ConfigureAwait(false)); } _logger?.Debug(message: "Шаг 2.5.1. Заполнить код двухфакторной авторизации"); var twoFactorFormResult = await FilledTwoFactorFormAsync(code : authParams.TwoFactorAuthorization, loginFormPostResult : loginFormPostResult); if (IsAuthSuccessfull(webCallResult: twoFactorFormResult)) { return(await EndAuthorizeAsync(result : twoFactorFormResult, webProxy : Proxy).ConfigureAwait(false)); } _logger?.Debug(message: "Шаг 2.5.2 Капча"); var captchaForm = WebForm.From(result: twoFactorFormResult); var captcha = await WebCall.PostAsync(form : captchaForm, webProxy : Proxy).ConfigureAwait(false); // todo: Нужно обработать капчу return(await EndAuthorizeAsync(result : captcha, webProxy : Proxy).ConfigureAwait(false)); }
private bool TryAuthorize(IVkApi vkApi, IApiAuthParams apiAuthParams) { try { vkApi.Authorize(apiAuthParams); //FIXME капча, будь она неладна } catch (VkAuthorizationException authException) { io.Print($"Authorization unsuccessful: {authException.Message}"); return(false); } catch (Exception e) { io.Print("Unhandled exception occured"); io.Print(e.ToString()); throw; } return(true); }
/// <inheritdoc /> public VkAuthorization Authorize(IApiAuthParams authParams) { _logger?.Debug("Шаг 1. Открытие диалога авторизации"); var authorizeUrlResult = OpenAuthDialog(authParams.ApplicationId, authParams.Settings); if (IsAuthSuccessfull(authorizeUrlResult)) { return(EndAuthorize(authorizeUrlResult, Proxy)); } _logger?.Debug("Шаг 2. Заполнение формы логина"); var loginFormPostResult = FilledLoginForm(authParams.Login, authParams.Password, authParams.CaptchaSid, authParams.CaptchaKey, authorizeUrlResult); if (IsAuthSuccessfull(loginFormPostResult)) { return(EndAuthorize(loginFormPostResult, Proxy)); } if (HasNotTwoFactor(authParams.TwoFactorAuthorization, loginFormPostResult)) { return(EndAuthorize(loginFormPostResult, Proxy)); } _logger?.Debug("Шаг 2.5.1. Заполнить код двухфакторной авторизации"); var twoFactorFormResult = FilledTwoFactorForm(authParams.TwoFactorAuthorization, loginFormPostResult); if (IsAuthSuccessfull(twoFactorFormResult)) { return(EndAuthorize(twoFactorFormResult, Proxy)); } _logger?.Debug("Шаг 2.5.2 Капча"); var captchaForm = WebForm.From(twoFactorFormResult); var captcha = WebCall.Post(captchaForm, Proxy); // todo: Нужно обработать капчу return(EndAuthorize(captcha, Proxy)); }
public void SetAuthParams(IApiAuthParams authParams) { _apiAuthParams = authParams; }
/// <inheritdoc /> public Task AuthorizeAsync(IApiAuthParams @params) { return(TypeHelper.TryInvokeMethodAsync(func: () => Authorize(@params: @params))); }
public void SetAuthorizationParams(IApiAuthParams authorizationParams) { _apiAuthParams = authorizationParams; }
/// <inheritdoc /> public async Task AuthorizeAsync(IApiAuthParams @params) { await TypeHelper.TryInvokeMethodAsync(func : () => Authorize(@params: @params)); }
public Task AuthorizeAsync(IApiAuthParams @params) { throw new NotImplementedException(); }
public void Authorize(IApiAuthParams @params) { throw new NotImplementedException(); }