public async Task <UserInfoUnion> Login(string userName, string password, CaptchaAnswer captchaAnswer = null) { _logger.Method().Start($"{userName} | {captchaAnswer}"); Union3 <UserInfo, LoginErrorDto, Exception> userInfoUnion = await _internalAuthService.Login(userName, password, captchaAnswer); return(userInfoUnion.Match(userInfo => { ProcessUserInfo(userInfo); return new UserInfoUnion.Case1(userInfo.RetWithLog(_logger).Log()); }, error => string.IsNullOrWhiteSpace(error.CaptchaKey) || string.IsNullOrWhiteSpace(error.CaptchaUrl) ? (UserInfoUnion) new UserInfoUnion.Case2(new LoginError(error.Error, error.ErrorDescription).RetWithLog(_logger).Log()) : new UserInfoUnion.Case4(new CaptchaQuery(error.CaptchaKey, error.CaptchaUrl).RetWithLog(_logger).Log()), ex => new UserInfoUnion.Case3(ex.RetWithLog(_logger).Log()))); }
private async Task <UserInfo> UnsafeLogin(string userName, string password, CaptchaAnswer captchaAnswer) { _logger.Method().Start($"{userName} {captchaAnswer}"); var passwordtData = new Dictionary <string, string> { { "grant_type", "password" }, { "client_id", _amClientId }, { "client_secret", _amClientSecret }, { "username", userName }, { "password", password } }; if (captchaAnswer != null) { passwordtData["x_captcha_key"] = captchaAnswer.Key; passwordtData["x_captcha_answer"] = captchaAnswer.Answer; } OAuthResult resultWithXToken = await OAuthRequest(passwordtData); return((await UnsafeLoginWithXToken(resultWithXToken.AccessToken)).RetWithLog(_logger).Log()); }
private void GetException(string answer, string _uri, bool ff, CaptchaAnswer captchaResponse = null) { if (answer.Contains("Error verifying reCAPTCHA")) { //string ans = Captcha2Solver.set_captcha_bad(captchaResponse.AccessToken, captchaResponse.Id); //throw new BaseException("Bad Captcha", "Bad Captcha " + ans); throw new BaseException("Bad Captcha", "Bad Captcha"); } else if (answer.Contains("Cloudflare to restrict access")) { throw new BaseException(string.Empty, "Baned CloudFlare"); } else if (answer.Contains("Attention Required! | Cloudflare")) { throw new BaseException(string.Empty, "api.revolico ask for Captcha"); } else if (answer.Contains("Has eliminado este anuncio.")) { throw new BaseException(string.Empty, "Deteccion Anuncio Eliminado"); } else if (answer.ToLower().Contains("anuncio despublicado")) { throw new BaseException(string.Empty, "Deteccion Anuncio Despublicado"); } else if (answer.Contains("Ha ocurrido un error")) { throw new BaseException(string.Empty, "Revolico Error"); } else if (ff && ( !answer.Contains("\"status\":200") || !answer.Contains("\"errors\":null") || !answer.Contains("createAdWithoutUser"))) { throw new BaseException(string.Empty, "Non updated " + answer); } }
public Task <UserInfoUnion> Login(string userName, string password, CaptchaAnswer captchaAnswer = null) => DoWithExceptionHandling(UnsafeLogin(userName, password, captchaAnswer));
/// <summary> /// Queries Steam API with user credentials and returns a valid access token for use in API calls. /// </summary> /// <param name="username">Username of the user requesting authentication.</param> /// <param name="password">Password for the user requesting authentication.</param> /// <param name="steamGuardAnswer"></param> /// <param name="captchaAnswer"></param> /// <returns>Access token which can then be used with the UserAuthenticator.ForProtectedResource method.</returns> public static SteamAccessRequestResult GetAccessTokenForUser( string username, string password, SteamGuardAnswer steamGuardAnswer = null, CaptchaAnswer captchaAnswer = null ) { RSAValues publicKey = GetRSAKeyValues( username ); // RSA Encryption RSAHelper rsa = new RSAHelper(); rsa.ImportParameters( new RSAParameters { E = publicKey.PublicKeyExponent.HexToByteArray(), N = publicKey.PublicKeyModulus.HexToByteArray() } ); byte[] cipherPassword = rsa.Encrypt( Encoding.UTF8.GetBytes( password ) ); string encodedCipherPassword = Convert.ToBase64String( cipherPassword ); SteamClient client = new SteamClient( "https://steamcommunity.com/" ); SteamRequest request = new SteamRequest( "mobilelogin/dologin", HttpMethod.Post ); request.AddParameter( "username", username, ParameterType.QueryString ); request.AddParameter( "password", encodedCipherPassword, ParameterType.QueryString ); request.AddParameter( "rsatimestamp", publicKey.Timestamp, ParameterType.QueryString ); request.AddParameter( "oauth_client_id", "DE45CD61", ParameterType.QueryString ); request.AddParameter( "oauth_scope", "read_profile write_profile read_client write_client", ParameterType.QueryString ); if( captchaAnswer != null ) { request.AddParameter( "captchagid", captchaAnswer.GID, ParameterType.QueryString ); request.AddParameter( "captcha_text", captchaAnswer.SolutionText, ParameterType.QueryString ); } if( steamGuardAnswer != null ) { request.AddParameter( "emailsteamid", steamGuardAnswer.ID, ParameterType.QueryString ); request.AddParameter( "emailauth", steamGuardAnswer.SolutionText, ParameterType.QueryString ); } ISteamResponse response = client.Execute( request ); if( !response.IsSuccessful ) throw new SteamRequestException( "User authentication failed. Request to procure Steam access token failed (HTTP request not successful).", response ) { IsRequestIssue = true }; SteamTokenResult result; try { result = JsonConvert.DeserializeObject<SteamTokenResult>( response.Content ); } catch( Exception e ) { throw new SteamRequestException( "Unable to deserialize the token response from Steam.", e ) { IsDeserializationIssue = true }; } if( !result.IsSuccessful ){ return new SteamAccessRequestResult { IsSuccessful = false, SteamResponseMessage = result.Message, IsCaptchaNeeded = result.IsCaptchaNeeded, CaptchaURL = ( String.IsNullOrEmpty( result.CaptchaGID ) ) ? null : "https://steamcommunity.com/public/captcha.php?gid=" + result.CaptchaGID, CaptchaGID = ( String.IsNullOrEmpty( result.CaptchaGID ) ) ? null : result.CaptchaGID, IsSteamGuardNeeded = result.IsEmailAuthNeeded, SteamGuardID = ( String.IsNullOrEmpty( result.EmailSteamID ) ) ? null : result.EmailSteamID, SteamGuardEmailDomain = ( String.IsNullOrEmpty( result.EmailDomain ) ) ? null : result.EmailDomain }; } if( result.OAuthParams == null ) throw new SteamRequestException( "Login was successful did the response did not contain expected OAuth access information.", response ); OAuthParameters oauthParams = JsonConvert.DeserializeObject<OAuthParameters>( result.OAuthParams ); SteamUser user = new SteamUser { SteamID = new SteamID( oauthParams.SteamID ), OAuthAccessToken = oauthParams.OAuthToken }; return new SteamAccessRequestResult { IsSuccessful = true, IsLoginComplete = result.IsLoginComplete, User = user }; }
static void Main(string[] args) { Console.WriteLine("Hello World!"); AnuncioService anuncioService = new AnuncioService(null, null, null, null); string folder = "C:\\Users\\Rafael Fernanadez\\Documents\\Trabajos\\RT\\Recuperacion de Anuncios\\Alain"; //try //{ // using (StreamReader reader = new StreamReader("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\source.txt")) // using (StreamWriter writer = new StreamWriter("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\target.txt")) // { // string url; // int cnt = 1; // while (!reader.EndOfStream && (url = reader.ReadLine()).Length > 0) // { // Console.WriteLine(cnt); // try // { // FormInsertAnuncio formInsertAnuncio = anuncioService.Retrieve(url).GetAwaiter().GetResult(); // string jsonForm = $"{JsonConvert.SerializeObject(formInsertAnuncio)}"; // writer.WriteLine(jsonForm); // } // catch (Exception) // { // writer.WriteLine(" no " + url); // } // cnt++; // } // } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} using (StreamReader reader = new StreamReader(folder + "\\target.txt")) using (StreamWriter writer = new StreamWriter(folder + "\\links-modificar.txt")) { string line; int cnt = 1; while (!reader.EndOfStream && (line = reader.ReadLine()).Length > 0) { Console.WriteLine(cnt); try { FormInsertAnuncio formInsertAnuncio = JsonConvert.DeserializeObject <FormInsertAnuncio>(line); //Captcha string html = "DS\", \"RECAPTCHA_V2_SITE_KEY\":\"6LfyRCIUAAAAAP5zhuXfbwh63Sx4zqfPmh3Jnjy7\",\"RECAPTCHA_V3_SITE_KEY\":\"6Lfw"; CaptchaAnswer captchaAnswer = anuncioService.ResolveCaptcha("91092bd5c3c38f309e077e595d94226c", "https://www.revolico.com/insertar-anuncio.html", html).GetAwaiter().GetResult(); formInsertAnuncio.variables.captchaResponse = captchaAnswer.Answerv2; //formInsertAnuncio.variables.botScore = captchaAnswer.Answerv3; string answer = anuncioService.InsertAnuncio(formInsertAnuncio).GetAwaiter().GetResult(); InsertResult insertResult = anuncioService.ParseInsertResult(answer); writer.WriteLine("https://www.revolico.com/modificar-anuncio.html?key=" + insertResult.FullId); } catch (Exception ex) { writer.WriteLine(" no " + cnt); Console.WriteLine(ex.Message); } cnt++; } } }