public async Task Login() { if (IsAuthenticated()) { return; } await ProceedUtils.Proceed <bool?>(_logger, async() => { var session = this.LoadSession(); if (session != null) { AuthCookies = session; _logger.LogTrace(AuthCookies.GetLog()); return(true); } var loginGetRequest = AccountProvider.Login.LoginGet() .SetDefault(); var loginGet = await(await loginGetRequest.ExecuteUnparsedAsync()).ToLoginGet(); AuthCookies = new AuthCookies { CfdUid = loginGet.CfdUid, Session = loginGet.Session }; var loginRequest = AccountProvider.Login.Login( Credentials.Username, Credentials.Password, loginGet.GrantType, loginGet.Continue, loginGet.CsrfToken) .SetDefault() .AddCacheControlMaxAge(TimeSpan.Zero) .AddOrigin("https://account.shodan.io") .AddSecFetchSite("same-origin") .AddReferer("https://account.shodan.io/login") .AddCookies(AuthCookies); var loginResult = await loginRequest.ExecuteUnparsedAsync(); AuthCookies.Polito = loginResult.GetCookie("polito"); AuthCookies.Session = loginResult.GetCookie("session"); _logger.LogTrace(AuthCookies.GetLog()); this.SaveSession(AuthCookies); return(true); }); }
public async Task Login() { if (this.IsAuthenticated()) { return; } await ProceedUtils.Proceed <bool?>(this.Logger, async() => { AuthCookies = new AuthCookies { Username = this.UserSecrets.Username, Password = this.UserSecrets.Password, UserLang = UserLang, Ga = "GA1.2.1583055054.1567053894", Gid = "GA1.2.49410478.1567140764", Gat = "1" }; var bvbRequest = this.Lr.UserSignIn.SignInBvb(UserLang, ClientVersion) .SetAuthCookies(AuthCookies) .SetSerializer(new SignInBvbSerializer()); var bvbResponse = await bvbRequest.ExecuteAsync(); AuthCookies.Bvb = bvbResponse.Bvb; var sessionIdRequest = this.Lr.UserSignIn.SignInSessionId(UserLang, ClientVersion, "1") .SetAuthCookies(AuthCookies) .AddReferer($"https://likesrock.com/client-v2/user_signin.php?user_lang={UserLang}&client_version={ClientVersion}") .SetSerializer(new WebFormsToJsonSerializer()); var sessionId = (await sessionIdRequest.ExecuteUnparsedAsync()).GetCookie(PhpSessionId); AuthCookies.PhpSessionId = sessionId; this.Logger.LogTrace(AuthCookies.GetLog()); var session = this.LoadSession(); if (session != null) { UserSession = session; this.Logger.LogTrace(UserSession.GetLog()); return(true); } var loginRequest = this.Lr.Ajax.Login(this.UserSecrets.Username, this.UserSecrets.Password) .ClearExecInterceptors() .AddUserAgent(HttpConst.UserAgent) .AddCookies(AuthCookies) .AddConnection("keep-alive") .AddAccept("*/*") .AddOrigin("https://likesrock.com") .AddXRequestedWith("XMLHttpRequest") .AddReferer($"https://likesrock.com/client-v2/user_signin.php?user_lang={UserLang}&client_version={ClientVersion}&security=1") .AddAcceptLanguage("en-US,en;q=0.8"); var loginInfo = await loginRequest.ExecuteAsync(); if (loginInfo == null) { this.Logger.LogError("Authorization failed."); DelayUtils.LargeDelay(); return(null); } this.Logger.LogTrace(loginInfo.GetLog()); UserSession = new UserSession { UserId = loginInfo.UserId, UserName = loginInfo.UserName, UserEmail = loginInfo.UserEmail, UserAccessToken = loginInfo.UserAccessToken }; this.SaveSession(UserSession); return(true); }); }