private async Task <AuthorizationResult> BaseAuthAsync() { try { var parameters = new VkParameters { { "grant_type", "password" }, { "client_id", "2274003" }, { "client_secret", "hHbZxrka2uZ6jB1inYsH" }, { "2fa_supported", _apiAuthParams.TwoFactorSupported ?? true }, { "force_sms", _apiAuthParams.ForceSms }, { "username", _apiAuthParams.Login }, { "password", _apiAuthParams.Password }, { "code", _apiAuthParams.Code }, { "scope", "all" }, { "device_id", RandomString.Generate(16) } }; return(await _vkApiInvoker.CallAsync <AuthorizationResult>(new Uri("https://oauth.vk.com/token"), parameters).ConfigureAwait(false)); } catch (VkAuthException exception) { switch (exception.AuthError.Error) { case "need_validation": _logger?.LogDebug("Требуется ввести код двухфакторной авторизации"); if (_apiAuthParams.TwoFactorAuthorization == null) { throw new InvalidOperationException($"Two-factor authorization required, but {nameof(_apiAuthParams.TwoFactorAuthorization)} callback is null. Set {nameof(_apiAuthParams.TwoFactorAuthorization)} callback to handle two-factor authorization."); } var result = _apiAuthParams.TwoFactorAuthorization(); _apiAuthParams.Code = result; return(await BaseAuthAsync().ConfigureAwait(false)); default: throw; } } }
public async Task <string> Register(AndroidCheckinResponse credentials) { var requestParams = GetRegisterRequestParams(RandomString.Generate(22), credentials.AndroidId.ToString()); var content = new FormUrlEncodedContent(requestParams); var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://android.clients.google.com/c2dm/register3") { Content = content }; httpRequestMessage.Headers.TryAddWithoutValidation("Authorization", $"AidLogin {credentials.AndroidId}:{credentials.SecurityToken}"); var response = await _httpClient.SendAsync(httpRequestMessage).ConfigureAwait(false); response.EnsureSuccessStatusCode(); var registerResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(registerResponse); }
public FakeSafetyNetClient([CanBeNull] ILogger <FakeSafetyNetClient> logger) { _logger = logger; _appId = RandomString.Generate(11); }